forked from simple-statistics/simple-statistics
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmedian.test.js
43 lines (36 loc) · 1.09 KB
/
median.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/* eslint no-shadow: 0 */
const test = require("tap").test;
const ss = require("../dist/simple-statistics.js");
test("median", function (t) {
t.test("can get the median of three numbers", function (t) {
t.equal(ss.median([1, 2, 3]), 2);
t.end();
});
t.test("can get the median of two numbers", function (t) {
t.equal(ss.median([1, 2]), 1.5);
t.equal(ss.medianSorted([1, 2]), 1.5);
t.end();
});
t.test("can get the median of four numbers", function (t) {
t.equal(ss.median([1, 2, 3, 4]), 2.5);
t.end();
});
t.test("cannot calculate the median of an empty list", function (t) {
t.throws(function () {
ss.median([]);
});
t.end();
});
t.test("sorts numbers numerically", function (t) {
t.equal(ss.median([8, 9, 10]), 9);
t.end();
});
t.test("does not change the sorting order of its input", function (t) {
const x = [1, 0];
t.equal(ss.median(x), 0.5);
t.equal(x[0], 1);
t.equal(x[1], 0);
t.end();
});
t.end();
});