-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstats.test.js
More file actions
35 lines (34 loc) · 1018 Bytes
/
stats.test.js
File metadata and controls
35 lines (34 loc) · 1018 Bytes
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
const stats = require("./stats");
describe("stats", () => {
it("gets maximum value", () => {
expect(stats.max([1, 2, 3, 4])).toBe(4);
});
it("gets minimum value", () => {
expect(stats.min([1, 2, 3, 4])).toBe(1);
});
it("gets average value", () => {
expect(stats.avg([1, 2, 3, 4, 5, 6, 7])).toBe(4);
});
describe("median", () => {
it("sorts the array", () => {
expect(stats.sort([5, 4, 1, 3, 2])).toEqual([1, 2, 3, 4, 5]);
});
it("gets the median for odd length", () => {
expect(stats.median([1, 2, 3, 4, 5])).toBe(3);
});
it("gets the median for even length", () => {
expect(stats.median([1, 2, 3, 4, 5, 6])).toBe(3.5);
});
});
describe("mode", () => {
it("has one mode", () => {
expect(stats.mode([1, 2, 2, 2, 3])).toBe(2);
});
it("has no mode", () => {
expect(stats.mode([1, 2, 3])).toBe(null);
});
it("has multiple mode", () => {
expect(stats.mode([1, 2, 2, 3, 3, 4])).toEqual([2, 3]);
});
});
});