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