Commit | Line | Data |
---|---|---|
4884b8d3 JB |
1 | import { expect } from 'expect'; |
2 | ||
3 | import { median, nthPercentile, stdDeviation } from '../../src/utils/StatisticUtils'; | |
4 | ||
5 | describe('StatisticUtils test suite', () => { | |
6 | it('Verify median()', () => { | |
7 | expect(median([])).toBe(0); | |
8 | expect(median([0.08])).toBe(0.08); | |
9 | expect(median([0.25, 4.75, 3.05, 6.04, 1.01, 2.02, 5.03])).toBe(3.05); | |
10 | expect(median([0.25, 4.75, 3.05, 6.04, 1.01, 2.02])).toBe(2.535); | |
11 | }); | |
12 | ||
13 | it('Verify nthPercentile()', () => { | |
14 | expect(nthPercentile([], 25)).toBe(0); | |
15 | expect(nthPercentile([0.08], 50)).toBe(0.08); | |
16 | const array0 = [0.25, 4.75, 3.05, 6.04, 1.01, 2.02, 5.03]; | |
17 | expect(nthPercentile(array0, 0)).toBe(0.25); | |
18 | expect(nthPercentile(array0, 50)).toBe(3.05); | |
19 | expect(nthPercentile(array0, 80)).toBe(4.974); | |
20 | expect(nthPercentile(array0, 85)).toBe(5.131); | |
21 | expect(nthPercentile(array0, 90)).toBe(5.434); | |
22 | expect(nthPercentile(array0, 95)).toBe(5.736999999999999); | |
23 | expect(nthPercentile(array0, 100)).toBe(6.04); | |
24 | }); | |
25 | ||
26 | it('Verify stdDeviation()', () => { | |
27 | expect(stdDeviation([0.25, 4.75, 3.05, 6.04, 1.01, 2.02, 5.03])).toBe(2.0256064851429216); | |
28 | }); | |
29 | }); |