diff --git a/src/UnitTests/StatisticsTests/StatisticsSerializationTests.cs b/src/UnitTests/StatisticsTests/StatisticsSerializationTests.cs new file mode 100644 index 00000000..908401de --- /dev/null +++ b/src/UnitTests/StatisticsTests/StatisticsSerializationTests.cs @@ -0,0 +1,81 @@ +using System.IO; +using System.Runtime.Serialization; +using MathNet.Numerics.Statistics; +using NUnit.Framework; + +namespace MathNet.Numerics.UnitTests.StatisticsTests +{ + [TestFixture] + public class StatisticsSerializationTests + { + [Test] + public void RunningStatisticsDataContractSerializationTest() + { + var expected = new RunningStatistics(new[] { 1.0, 2.0, 3.0 }); + + var serializer = new DataContractSerializer(typeof(RunningStatistics)); + var stream = new MemoryStream(); + serializer.WriteObject(stream, expected); + + stream.Position = 0; + var actual = (RunningStatistics)serializer.ReadObject(stream); + + Assert.That(actual.Count, Is.EqualTo(expected.Count)); + Assert.That(actual.Maximum, Is.EqualTo(expected.Maximum)); + Assert.That(actual.Mean, Is.EqualTo(expected.Mean)); + } + + [Test] + public void RunningStatisticsWithInfinityNaNDataContractSerializationTest() + { + var expected = new RunningStatistics(new[] { 1.0, 2.0, 3.0, double.PositiveInfinity, double.NaN }); + + var serializer = new DataContractSerializer(typeof(RunningStatistics)); + var stream = new MemoryStream(); + serializer.WriteObject(stream, expected); + + stream.Position = 0; + var actual = (RunningStatistics)serializer.ReadObject(stream); + + Assert.That(actual.Count, Is.EqualTo(expected.Count)); + Assert.That(actual.Maximum, Is.EqualTo(expected.Maximum)); + Assert.That(actual.Mean, Is.EqualTo(expected.Mean)); + } + + [Test] + public void DescriptiveStatisticsDataContractSerializationTest() + { + var expected = new DescriptiveStatistics(new[] { 1.0, 2.0, 3.0 }); + + var serializer = new DataContractSerializer(typeof(DescriptiveStatistics)); + var stream = new MemoryStream(); + serializer.WriteObject(stream, expected); + + stream.Position = 0; + var actual = (DescriptiveStatistics)serializer.ReadObject(stream); + + Assert.That(actual.Count, Is.EqualTo(expected.Count)); + Assert.That(actual.Maximum, Is.EqualTo(expected.Maximum)); + Assert.That(actual.Mean, Is.EqualTo(expected.Mean)); + } + + [Test] + public void HistogramDataContractSerializationTest() + { + var expected = new Histogram(new[] { 1.0, 2.0, 3.0, 4.0 }, 2); + + var serializer = new DataContractSerializer(typeof(Histogram)); + var stream = new MemoryStream(); + serializer.WriteObject(stream, expected); + + stream.Position = 0; + var actual = (Histogram)serializer.ReadObject(stream); + + Assert.That(actual.BucketCount, Is.EqualTo(expected.BucketCount)); + Assert.That(actual.DataCount, Is.EqualTo(expected.DataCount)); + Assert.That(actual.LowerBound, Is.EqualTo(expected.LowerBound)); + Assert.That(actual[0].Width, Is.EqualTo(expected[0].Width)); + Assert.That(actual[0].UpperBound, Is.EqualTo(expected[0].UpperBound)); + } + } +} diff --git a/src/UnitTests/UnitTests-Net35.csproj b/src/UnitTests/UnitTests-Net35.csproj index fbb5e800..d65607e1 100644 --- a/src/UnitTests/UnitTests-Net35.csproj +++ b/src/UnitTests/UnitTests-Net35.csproj @@ -59,6 +59,8 @@ + + diff --git a/src/UnitTests/UnitTests-Portable259.csproj b/src/UnitTests/UnitTests-Portable259.csproj index 0858525a..63417c71 100644 --- a/src/UnitTests/UnitTests-Portable259.csproj +++ b/src/UnitTests/UnitTests-Portable259.csproj @@ -44,6 +44,8 @@ + + diff --git a/src/UnitTests/UnitTests-Portable328.csproj b/src/UnitTests/UnitTests-Portable328.csproj index 55d26134..62762c12 100644 --- a/src/UnitTests/UnitTests-Portable328.csproj +++ b/src/UnitTests/UnitTests-Portable328.csproj @@ -44,6 +44,8 @@ + + diff --git a/src/UnitTests/UnitTests-Portable47.csproj b/src/UnitTests/UnitTests-Portable47.csproj index 23f4369d..d8a896eb 100644 --- a/src/UnitTests/UnitTests-Portable47.csproj +++ b/src/UnitTests/UnitTests-Portable47.csproj @@ -52,6 +52,8 @@ {49205185-621E-FFB9-2104-887C9F1BBD13} Numerics-Portable47 + + diff --git a/src/UnitTests/UnitTests-Portable7.csproj b/src/UnitTests/UnitTests-Portable7.csproj index 1e091034..9d801adc 100644 --- a/src/UnitTests/UnitTests-Portable7.csproj +++ b/src/UnitTests/UnitTests-Portable7.csproj @@ -52,6 +52,8 @@ {25E6E93B-56A2-4F14-8458-03665F122B3F} Numerics-Portable7 + + diff --git a/src/UnitTests/UnitTests-Portable78.csproj b/src/UnitTests/UnitTests-Portable78.csproj index 5fb33db7..8393adcc 100644 --- a/src/UnitTests/UnitTests-Portable78.csproj +++ b/src/UnitTests/UnitTests-Portable78.csproj @@ -52,6 +52,8 @@ {2EBD6F22-9BD6-4AF2-A21B-7198C9C5571F} Numerics-Portable78 + + diff --git a/src/UnitTests/UnitTests.csproj b/src/UnitTests/UnitTests.csproj index 91b8405d..b64c0ed7 100644 --- a/src/UnitTests/UnitTests.csproj +++ b/src/UnitTests/UnitTests.csproj @@ -75,6 +75,8 @@ {B7CAE5F4-A23F-4438-B5BE-41226618B695} Numerics + + @@ -398,6 +400,7 @@ +