/
minmax.test.js
54 lines (48 loc) · 1.42 KB
/
minmax.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
/* eslint no-shadow: 0 */
const test = require("tap").test;
const ss = require("../dist/simple-statistics.js");
test("min", function (t) {
t.throws(function () {
ss.min([]);
}, "zero length array throws");
t.test("can get the minimum of one number", function (t) {
t.equal(ss.min([1]), 1);
t.end();
});
t.test("can get the minimum of three numbers", function (t) {
t.equal(ss.min([1, 7, -1000]), -1000);
t.end();
});
t.end();
});
test("max", function (t) {
t.throws(function () {
ss.max([]);
}, "zero length array throws");
t.test("can get the maximum of three numbers", function (t) {
t.equal(ss.max([1, 7, -1000]), 7);
t.end();
});
t.end();
});
test("extent", function (t) {
t.throws(function () {
ss.extent([]);
}, "zero length array throws");
t.test("can get the extent of one number", function (t) {
t.same(ss.extent([1]), [1, 1]);
t.equal(ss.extent([1])[0], ss.extent([1])[1]);
t.end();
});
t.test("can get the extent of three numbers", function (t) {
t.same(ss.extent([1, 7, -1000]), [-1000, 7]);
t.end();
});
t.end();
});
test("sorted", function (t) {
t.equal(ss.maxSorted([1, 7, 1000]), 1000, "maxSorted");
t.equal(ss.minSorted([1, 7, 1000]), 1, "minSorted");
t.same(ss.extentSorted([1, 7, 1000]), [1, 1000], "extentSorted");
t.end();
});