Created
May 6, 2017 15:04
-
-
Save abalanonline/9b128faa67e2459b765c1ef56454684b to your computer and use it in GitHub Desktop.
JMeter Percentile test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | |
} | |
} |
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.
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
Failing on line 63
Expected :15, Actual :13