Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Percentile calculation : Document algorithm used #4388

Closed
asfimport opened this issue May 6, 2017 · 2 comments
Closed

Percentile calculation : Document algorithm used #4388

asfimport opened this issue May 6, 2017 · 2 comments

Comments

@asfimport
Copy link
Collaborator

Aleksei Balan (Bug 61078):
The percentile nearest rank method implemented in JMeter have an error and failing on the data from Wikipedia examples.
https://en.wikipedia.org/wiki/Percentile#The_Nearest_Rank_method

Tests implemented
https://gist.github.com/abalanonline/9b128faa67e2459b765c1ef56454684b

Created attachment TestStatCalculatorPercentile.java: TestStatCalculatorPercentile.java

TestStatCalculatorPercentile.java
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());
    }

}

OS: All

Duplicated by:

@asfimport
Copy link
Collaborator Author

@asfimport
Copy link
Collaborator Author

@pmouawad (migrated from Bugzilla):
This bug has been marked as a duplicate of #4399

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

No branches or pull requests

1 participant