Skip to content

Commit

Permalink
ava
Browse files Browse the repository at this point in the history
  • Loading branch information
msn0 committed May 19, 2017
1 parent 4b2f21a commit b86f300
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 42 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Calculate Nth percentile of a list of values",
"main": "dist/index.js",
"scripts": {
"test": "mocha --compilers js:babel-register",
"test": "ava --verbose && eslint .",
"prepublish": "rollup -c"
},
"repository": {
Expand All @@ -24,12 +24,12 @@
},
"homepage": "https://github.com/msn0/stats-percentile",
"devDependencies": {
"ava": "^0.19.1",
"babel-cli": "^6.24.1",
"babel-plugin-external-helpers": "^6.22.0",
"babel-preset-es2015": "^6.24.1",
"babelrc-rollup": "^3.0.0",
"eslint-config-helmut": "^1.2.0",
"mocha": "^3.4.1",
"rollup": "^0.41.6",
"rollup-plugin-babel": "^2.7.1",
"rollup-plugin-uglify": "^1.0.2"
Expand Down
78 changes: 38 additions & 40 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,53 +1,51 @@
import assert from 'assert';
import test from 'ava';
import percentile from './dist/';

describe('Percentile calculation', () => {
it('should return expected values', () => {
test('should return expected values', t => {

const data1 = [35, 20, 15, 50, 40];
const data2 = [3, 6, 7, 8, 8, 10, 13, 15, 16, 20];
const data3 = [3, 6, 7, 8, 8, 9, 10, 13, 15, 16, 20];
const data4 = [
10, 13, 15, 16, 20, 3, 6, 7, 7, 15, 19, 23, 33, 8, 19, 35, 22, 17, 19, 29,
13, 13, 15, 16, 22, 3, 8, 7, 1, 14, 19, 23, 33, 8, 19, 35, 21, 17, 19, 29,
17, 13, 19, 16, 20, 3, 9, 7, 25, 15, 18, 13, 23, 7, 11, 35, 22, 1, 9, 9,
13, 12, 15, 14, 21, 5, 6, 5, 7, 16, 16, 23, 47, 8, 19, 35, 29, 17, 19, 29,
15, 13, 15, 8, 20, 3, 6, 7, 7, 17, 19, 23, 43, 8, 19, 35, 22, 17, 19, 9,
10, 19, 14, 16, 26, 9, 5, 7, 17, 18, 12, 25, 63, 8, 19, 35, 22, 17, 15, 16
10, 13, 15, 16, 20, 3, 6, 7, 7, 15, 19, 23, 33, 8, 19, 35, 22, 17, 19, 29,
13, 13, 15, 16, 22, 3, 8, 7, 1, 14, 19, 23, 33, 8, 19, 35, 21, 17, 19, 29,
17, 13, 19, 16, 20, 3, 9, 7, 25, 15, 18, 13, 23, 7, 11, 35, 22, 1, 9, 9,
13, 12, 15, 14, 21, 5, 6, 5, 7, 16, 16, 23, 47, 8, 19, 35, 29, 17, 19, 29,
15, 13, 15, 8, 20, 3, 6, 7, 7, 17, 19, 23, 43, 8, 19, 35, 22, 17, 19, 9,
10, 19, 14, 16, 26, 9, 5, 7, 17, 18, 12, 25, 63, 8, 19, 35, 22, 17, 15, 16
];
const data5 = [3];
const data6 = [
10, 13, 15, 16, 20, 3, 6, 7, 7, 15, 19, 13,
13, 8, 19, 35, 22, 17, 19, 19, 12, 21, 9, 9, 12
10, 13, 15, 16, 20, 3, 6, 7, 7, 15, 19, 13,
13, 8, 19, 35, 22, 17, 19, 19, 12, 21, 9, 9, 12
];

assert.equal(percentile(data1, 30), 20);
assert.equal(percentile(data1, 40), 20);
assert.equal(percentile(data1, 50), 35);
assert.equal(percentile(data1, 100), 50);

assert.equal(percentile(data2, 25), 7);
assert.equal(percentile(data2, 50), 8);
assert.equal(percentile(data2, 75), 15);
assert.equal(percentile(data2, 100), 20);

assert.equal(percentile(data3, 25), 7);
assert.equal(percentile(data3, 50), 9);
assert.equal(percentile(data3, 75), 15);
assert.equal(percentile(data3, 100), 20);

assert.equal(percentile(data4, 10), 6);
assert.equal(percentile(data4, 30), 11);
assert.equal(percentile(data4, 40), 14);
assert.equal(percentile(data4, 95), 35);
assert.equal(percentile(data4, 99), 47);
assert.equal(percentile(data4, 100), 63);

assert.equal(percentile(data5, 25), 3);
assert.equal(percentile(data5, 50), 3);
assert.equal(percentile(data5, 75), 3);
assert.equal(percentile(data5, 100), 3);

assert.equal(percentile(data6, 95), 22);
});
t.is(percentile(data1, 30), 20);
t.is(percentile(data1, 40), 20);
t.is(percentile(data1, 50), 35);
t.is(percentile(data1, 100), 50);

t.is(percentile(data2, 25), 7);
t.is(percentile(data2, 50), 8);
t.is(percentile(data2, 75), 15);
t.is(percentile(data2, 100), 20);

t.is(percentile(data3, 25), 7);
t.is(percentile(data3, 50), 9);
t.is(percentile(data3, 75), 15);
t.is(percentile(data3, 100), 20);

t.is(percentile(data4, 10), 6);
t.is(percentile(data4, 30), 11);
t.is(percentile(data4, 40), 14);
t.is(percentile(data4, 95), 35);
t.is(percentile(data4, 99), 47);
t.is(percentile(data4, 100), 63);

t.is(percentile(data5, 25), 3);
t.is(percentile(data5, 50), 3);
t.is(percentile(data5, 75), 3);
t.is(percentile(data5, 100), 3);

t.is(percentile(data6, 95), 22);
});

0 comments on commit b86f300

Please sign in to comment.