Permalink
Browse files

fix wrong median returned when breaking tie with no larger value

  • Loading branch information...
ssadedin committed Oct 9, 2018
1 parent c7a59a8 commit f97d5860a2f79381da8aa94b08ff7ea93515d866
Showing with 11 additions and 1 deletion.
  1. +2 −0 src/main/java/graxxia/IntegerStats.java
  2. +9 −1 src/test/groovy/IntegerStatsTest.groovy
@@ -178,6 +178,8 @@ public int getPercentile(int percentile) {
return (lowerValue + k) / 2;
}
}
// Now larger value to average - just return what we had
return lowerValue;
}
else
return i;
@@ -40,5 +40,13 @@ class IntegerStatsTest {
values.each { c.addValue(it); d.addValue(it) }
assert c.getPercentile(50) == d.getPercentile(50).toInteger()
}
@Test
void testBreakTieNoLarger() {
def values = [30]*10
def c = new IntegerStats(100)
def d = new DescriptiveStatistics()
values.each { c.addValue(it); d.addValue(it) }
assert c.getPercentile(50) == 30
}
}

0 comments on commit f97d586

Please sign in to comment.