From 518a79045cc3edd1f15d07bc4f73eb1849f7fc37 Mon Sep 17 00:00:00 2001 From: Volker Breuer Date: Thu, 19 Nov 2015 11:44:44 +0100 Subject: [PATCH] bugfix: adding data equal to the lower bound of a histogram threw an exception while lower values were fitted appropriately --- src/Numerics/Statistics/Histogram.cs | 2 +- src/UnitTests/StatisticsTests/HistogramTests.cs | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/Numerics/Statistics/Histogram.cs b/src/Numerics/Statistics/Histogram.cs index 06142da9..b86b44b2 100644 --- a/src/Numerics/Statistics/Histogram.cs +++ b/src/Numerics/Statistics/Histogram.cs @@ -344,7 +344,7 @@ namespace MathNet.Numerics.Statistics // Sort if needed. LazySort(); - if (d < LowerBound) + if (d <= LowerBound) { // Make the lower bound just slightly smaller than the datapoint so it is contained in this bucket. _buckets[0].LowerBound = d.Decrement(); diff --git a/src/UnitTests/StatisticsTests/HistogramTests.cs b/src/UnitTests/StatisticsTests/HistogramTests.cs index c5f79e5b..79bbaf29 100644 --- a/src/UnitTests/StatisticsTests/HistogramTests.cs +++ b/src/UnitTests/StatisticsTests/HistogramTests.cs @@ -348,6 +348,18 @@ namespace MathNet.Numerics.UnitTests.StatisticsTests Assert.AreEqual(3, h[0].Count); } + /// + /// Add data equal to the lower bound of a histogram. + /// + [Test] + public void AddDataEqualToLowerBound() + { + var h = new Histogram(new[] { 1.0, 5.0, 10.0 }, 3, 0.0, 10.0); + Assert.DoesNotThrow(() => h.AddData(0.0)); + + Assert.AreEqual(2, h[0].Count); + } + /// /// Small dataset histogram without bounds. ///