forked from simple-statistics/simple-statistics
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmode.test.js
64 lines (54 loc) · 1.87 KB
/
mode.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/* eslint no-shadow: 0 */
const test = require("tap").test;
const ss = require("../dist/simple-statistics.js");
test("mode", function (t) {
["mode", "modeFast"].forEach(function (modeName) {
t.test(modeName, function (t) {
const modeFn = ss[modeName];
t.test(
"the mode of a single-number array is that one number",
function (t) {
t.equal(modeFn([1]), 1);
t.end();
}
);
t.test(
"the mode of a two-number array is that one number",
function (t) {
t.equal(modeFn([1, 1]), 1);
t.end();
}
);
t.test("other cases", function (t) {
t.equal(modeFn([1, 1, 2]), 1);
t.equal(modeFn([1, 1, 2, 3]), 1);
t.equal(modeFn([1, 1, 2, 3, 3]), 1);
t.equal(modeFn([1, 1, 2, 3, 3, 3]), 3);
t.equal(modeFn([1, 2, 2, 2, 1, 2, 3, 3, 3]), 2);
t.equal(modeFn([1, 2, 3, 4, 5]), 1);
t.equal(modeFn([1, 2, 3, 4, 5, 5]), 5);
t.equal(modeFn([1, 2, 2, 3, 3, 4, 1, 4, 1]), 1);
t.end();
});
t.test("the mode of an empty array is null", function (t) {
t.throws(function () {
modeFn([]);
});
t.end();
});
t.test(
"the mode of a three-number array with two same numbers is the repeated one",
function (t) {
t.equal(modeFn([1, 2, 2]), 2);
t.end();
}
);
t.end();
});
});
t.test("mode sorted", function (t) {
t.equal(ss.modeSorted([1, 2, 2]), 2);
t.end();
});
t.end();
});