Skip to content

Commit

Permalink
BUG fix for IsLastValue. Closes #39
Browse files Browse the repository at this point in the history
  • Loading branch information
LeeCampbell committed Jan 10, 2017
1 parent e5ad62c commit a08f551
Show file tree
Hide file tree
Showing 4 changed files with 155 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/HdrHistogram.UnitTests/HdrHistogram.UnitTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@
<EmbeddedResource Include="Resources\jHiccup-2.0.7S.logV2.hlog" />
<EmbeddedResource Include="Resources\ycsb.logV1.hlog" />
<EmbeddedResource Include="Resources\tagged-Log.logV2.hlog" />
<EmbeddedResource Include="Resources\IsLastValueBug.hgrm" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\HdrHistogram\HdrHistogram.csproj">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,35 @@ public void PercentileDistrubution_csv_output_is_in_correct_format(

Assert.AreEqual(expected, actual);
}

[Test] //BUG https://github.com/HdrHistogram/HdrHistogram.NET/issues/39
public void OnlySingleValueFlaggedAsLastValue()
{
var expected = GetEmbeddedFileText("IsLastValueBug.hgrm");

var histogram = new LongHistogram(highestTrackableValue: 36000000000, numberOfSignificantValueDigits:3);
histogram.RecordValueWithCount(1L, 7604459);
histogram.RecordValueWithCount(383, 2395524);
histogram.RecordValueWithCount(453, 2);
histogram.RecordValueWithCount(511, 2);
histogram.RecordValueWithCount(537, 3);
histogram.RecordValueWithCount(672, 1);
histogram.RecordValueWithCount(777, 1);
histogram.RecordValueWithCount(18143, 1);
histogram.RecordValueWithCount(208127, 1);
histogram.RecordValueWithCount(224639, 1);
histogram.RecordValueWithCount(229759, 1);
histogram.RecordValueWithCount(230271, 1);
histogram.RecordValueWithCount(258943, 1);
histogram.RecordValueWithCount(275711, 1);
histogram.RecordValueWithCount(282111, 1);

var writer = new StringWriter();
histogram.OutputPercentileDistribution(writer);
var actual = writer.ToString();

Assert.AreEqual(expected, actual);
}

private Stream GetEmbeddedFileStream(string filename)
{
Expand Down
124 changes: 124 additions & 0 deletions src/HdrHistogram.UnitTests/Resources/IsLastValueBug.hgrm
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
 Value Percentile TotalCount 1/(1-Percentile)

1.000 0.000000000000 7604459 1.00
1.000 0.100000000000 7604459 1.11
1.000 0.200000000000 7604459 1.25
1.000 0.300000000000 7604459 1.43
1.000 0.400000000000 7604459 1.67
1.000 0.500000000000 7604459 2.00
1.000 0.550000000000 7604459 2.22
1.000 0.600000000000 7604459 2.50
1.000 0.650000000000 7604459 2.86
1.000 0.700000000000 7604459 3.33
1.000 0.750000000000 7604459 4.00
383.000 0.775000000000 9999983 4.44
383.000 0.800000000000 9999983 5.00
383.000 0.825000000000 9999983 5.71
383.000 0.850000000000 9999983 6.67
383.000 0.875000000000 9999983 8.00
383.000 0.887500000000 9999983 8.89
383.000 0.900000000000 9999983 10.00
383.000 0.912500000000 9999983 11.43
383.000 0.925000000000 9999983 13.33
383.000 0.937500000000 9999983 16.00
383.000 0.943750000000 9999983 17.78
383.000 0.950000000000 9999983 20.00
383.000 0.956250000000 9999983 22.86
383.000 0.962500000000 9999983 26.67
383.000 0.968750000000 9999983 32.00
383.000 0.971875000000 9999983 35.56
383.000 0.975000000000 9999983 40.00
383.000 0.978125000000 9999983 45.71
383.000 0.981250000000 9999983 53.33
383.000 0.984375000000 9999983 64.00
383.000 0.985937500000 9999983 71.11
383.000 0.987500000000 9999983 80.00
383.000 0.989062500000 9999983 91.43
383.000 0.990625000000 9999983 106.67
383.000 0.992187500000 9999983 128.00
383.000 0.992968750000 9999983 142.22
383.000 0.993750000000 9999983 160.00
383.000 0.994531250000 9999983 182.86
383.000 0.995312500000 9999983 213.33
383.000 0.996093750000 9999983 256.00
383.000 0.996484375000 9999983 284.44
383.000 0.996875000000 9999983 320.00
383.000 0.997265625000 9999983 365.71
383.000 0.997656250000 9999983 426.67
383.000 0.998046875000 9999983 512.00
383.000 0.998242187500 9999983 568.89
383.000 0.998437500000 9999983 640.00
383.000 0.998632812500 9999983 731.43
383.000 0.998828125000 9999983 853.33
383.000 0.999023437500 9999983 1024.00
383.000 0.999121093750 9999983 1137.78
383.000 0.999218750000 9999983 1280.00
383.000 0.999316406250 9999983 1462.86
383.000 0.999414062500 9999983 1706.67
383.000 0.999511718750 9999983 2048.00
383.000 0.999560546875 9999983 2275.56
383.000 0.999609375000 9999983 2560.00
383.000 0.999658203125 9999983 2925.71
383.000 0.999707031250 9999983 3413.33
383.000 0.999755859375 9999983 4096.00
383.000 0.999780273438 9999983 4551.11
383.000 0.999804687500 9999983 5120.00
383.000 0.999829101563 9999983 5851.43
383.000 0.999853515625 9999983 6826.67
383.000 0.999877929688 9999983 8192.00
383.000 0.999890136719 9999983 9102.22
383.000 0.999902343750 9999983 10240.00
383.000 0.999914550781 9999983 11702.86
383.000 0.999926757813 9999983 13653.33
383.000 0.999938964844 9999983 16384.00
383.000 0.999945068359 9999983 18204.44
383.000 0.999951171875 9999983 20480.00
383.000 0.999957275391 9999983 23405.71
383.000 0.999963378906 9999983 27306.67
383.000 0.999969482422 9999983 32768.00
383.000 0.999972534180 9999983 36408.89
383.000 0.999975585938 9999983 40960.00
383.000 0.999978637695 9999983 46811.43
383.000 0.999981689453 9999983 54613.33
383.000 0.999984741211 9999983 65536.00
383.000 0.999986267090 9999983 72817.78
383.000 0.999987792969 9999983 81920.00
383.000 0.999989318848 9999983 93622.86
383.000 0.999990844727 9999983 109226.67
383.000 0.999992370605 9999983 131072.00
383.000 0.999993133545 9999983 145635.56
383.000 0.999993896484 9999983 163840.00
383.000 0.999994659424 9999983 187245.71
383.000 0.999995422363 9999983 218453.33
383.000 0.999996185303 9999983 262144.00
383.000 0.999996566772 9999983 291271.11
383.000 0.999996948242 9999983 327680.00
383.000 0.999997329712 9999983 374491.43
383.000 0.999997711182 9999983 436906.67
383.000 0.999998092651 9999983 524288.00
383.000 0.999998283386 9999983 582542.22
453.000 0.999998474121 9999985 655360.00
511.000 0.999998664856 9999987 748982.86
537.000 0.999998855591 9999990 873813.33
672.000 0.999999046326 9999991 1048576.00
777.000 0.999999141693 9999992 1165084.44
18143.000 0.999999237061 9999993 1310720.00
208127.000 0.999999332428 9999994 1497965.71
224639.000 0.999999427795 9999995 1747626.67
229759.000 0.999999523163 9999996 2097152.00
229759.000 0.999999570847 9999996 2330168.89
230271.000 0.999999618530 9999997 2621440.00
230271.000 0.999999666214 9999997 2995931.43
258943.000 0.999999713898 9999998 3495253.33
258943.000 0.999999761581 9999998 4194304.00
258943.000 0.999999785423 9999998 4660337.78
275711.000 0.999999809265 9999999 5242880.00
275711.000 0.999999833107 9999999 5991862.86
275711.000 0.999999856949 9999999 6990506.67
275711.000 0.999999880791 9999999 8388608.00
275711.000 0.999999892712 9999999 9320675.55
282111.000 0.999999904633 10000000 10485760.00
282111.000 1.000000000000 10000000
#[Mean = 92.682, StdDeviation = 262.259]
#[Max = 282111.000, Total count = 10000000]
#[Buckets = 26, SubBuckets = 2048]
3 changes: 1 addition & 2 deletions src/HdrHistogram/Iteration/HistogramIterationValue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ public sealed class HistogramIterationValue
/// <returns>Returns <c>true</c> if it is the last value, else <c>false</c>.</returns>
public bool IsLastValue()
{
//return PercentileLevelIteratedTo == 100.0D;
return Math.Abs(PercentileLevelIteratedTo - 100.0D) < 0.0001;
return Math.Abs(PercentileLevelIteratedTo - 100.0D) < double.Epsilon;
}

// Set is all-or-nothing to avoid the potential for accidental omission of some values...
Expand Down

0 comments on commit a08f551

Please sign in to comment.