From 62300406df09839d3abba75bf13f3edbd28d1eeb Mon Sep 17 00:00:00 2001 From: Justin Needham Date: Wed, 6 May 2015 14:08:42 -0400 Subject: [PATCH] Added Unit tests that fail current bucket sorting algorithm --- .../StatisticsTests/HistogramTests.cs | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/src/UnitTests/StatisticsTests/HistogramTests.cs b/src/UnitTests/StatisticsTests/HistogramTests.cs index 3420d3ee..8d1e353f 100644 --- a/src/UnitTests/StatisticsTests/HistogramTests.cs +++ b/src/UnitTests/StatisticsTests/HistogramTests.cs @@ -28,6 +28,8 @@ // OTHER DEALINGS IN THE SOFTWARE. // +using System.Linq; + namespace MathNet.Numerics.UnitTests.StatisticsTests { using System; @@ -46,6 +48,16 @@ namespace MathNet.Numerics.UnitTests.StatisticsTests /// readonly double[] _smallDataset = {0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5}; + /// + /// Datatset array with small absolute values + /// + /// + /// These values are chosen to precisely match the upper bounds of 9 buckets, + /// from 0.5e-22 to 9.5E-22 + /// + readonly double[] _smallValueDataset = { 0.5e-22, 1.5E-22, 2.5E-22, 3.4999999999999996E-22, 4.4999999999999989E-22, + 5.4999999999999983E-22, 6.4999999999999986E-22, 7.4999999999999988E-22, + 8.4999999999999982E-22, 9.5E-22}; /// /// Can create empty bucket. /// @@ -371,5 +383,60 @@ namespace MathNet.Numerics.UnitTests.StatisticsTests Assert.AreEqual(0.0, hist.LowerBound); Assert.AreEqual(10.0, hist.UpperBound); } + + + + /// + /// Dataset of small values histogram without bounds. + /// + [Test] + public void SmallValuesHistogramWithoutBounds() + { + var hist = new Histogram(_smallValueDataset, 9); + + Assert.AreEqual(9, hist.BucketCount); + + for (var i = 1; i < 9; i++) + { + Assert.AreEqual(1.0, hist[i].Count); + } + + Assert.AreEqual(2.0, hist[0].Count); + + Assert.AreEqual(0.5e-22.Decrement(), hist.LowerBound); + Assert.AreEqual(9.5e-22, hist.UpperBound); + } + + /// + /// Dataset of small values histogram with bounds. + /// + [Test] + public void SmallValuesHistogramWithBounds() + { + var hist = new Histogram(_smallValueDataset, 10, 0.0, 10e-22); + + Assert.AreEqual(10, hist.BucketCount); + + for (var i = 0; i < 10; i++) + { + Assert.AreEqual(1.0, hist[i].Count); + } + + Assert.AreEqual(0.0, hist.LowerBound); + Assert.AreEqual(10.0e-22, hist.UpperBound); + } + + /// + /// Attempt to construct a dataset with small valued buckets + /// + [Test] + public void SmallValuesManyBucketsHistogramWithBounds() + { + var hist = new Histogram(_smallValueDataset, 100, 0.0, 10e-22); + + Assert.AreEqual(100, hist.BucketCount); + Assert.AreEqual(0.0, hist.LowerBound); + Assert.AreEqual(10.0e-22, hist.UpperBound); + } } }