Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abalanonline/9b128faa67e2459b765c1ef56454684b to your computer and use it in GitHub Desktop.
Save abalanonline/9b128faa67e2459b765c1ef56454684b to your computer and use it in GitHub Desktop.
JMeter Percentile test
package org.apache.jorphan.math;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class TestStatCalculatorPercentile {
private StatCalculatorLong calc;
@Before
public void setUp() {
calc = new StatCalculatorLong();
}
// https://en.wikipedia.org/wiki/Percentile#The_Nearest_Rank_method
@Test
public void testPercentileExample1() {
calc.addValue(15);
calc.addValue(20);
calc.addValue(35);
calc.addValue(40);
calc.addValue(50);
assertEquals(15, calc.getPercentPoint(0.05).intValue());
assertEquals(20, calc.getPercentPoint(0.30).intValue());
assertEquals(20, calc.getPercentPoint(0.40).intValue());
assertEquals(35, calc.getPercentPoint(0.50).intValue());
assertEquals(50, calc.getPercentPoint(1.00).intValue());
}
@Test
public void testPercentileExample2() {
calc.addValue(3);
calc.addValue(6);
calc.addValue(7);
calc.addValue(8);
calc.addValue(8);
calc.addValue(10);
calc.addValue(13);
calc.addValue(15);
calc.addValue(16);
calc.addValue(20);
assertEquals(7, calc.getPercentPoint(0.25).intValue());
assertEquals(8, calc.getPercentPoint(0.50).intValue());
assertEquals(15, calc.getPercentPoint(0.75).intValue());
assertEquals(20, calc.getPercentPoint(1.00).intValue());
}
@Test
public void testPercentileExample3() {
calc.addValue(3);
calc.addValue(6);
calc.addValue(7);
calc.addValue(8);
calc.addValue(8);
calc.addValue(9);
calc.addValue(10);
calc.addValue(13);
calc.addValue(15);
calc.addValue(16);
calc.addValue(20);
assertEquals(7, calc.getPercentPoint(0.25).intValue());
assertEquals(9, calc.getPercentPoint(0.50).intValue());
assertEquals(15, calc.getPercentPoint(0.75).intValue());
assertEquals(20, calc.getPercentPoint(1.00).intValue());
}
}
@abalanonline
Copy link
Author

Failing on line 63
Expected :15, Actual :13

@pmouawad
Copy link

pmouawad commented May 6, 2017

Hello,
Thanks for this Pr.
I think a better fix is to introduce HdrHistogram from Gil Tene instead of having our own algorithm.

if you'd like to contribute a Pr for that , I'll be happy to merge it.

@abalanonline
Copy link
Author

Believe it or not, HdrHistogram have the same bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment