forked from TheAlgorithms/TypeScript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLowestCommonMultiple.test.ts
58 lines (50 loc) · 1.68 KB
/
LowestCommonMultiple.test.ts
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
import { binaryLCM, lowestCommonMultiple, naiveLCM } from "../LowestCommonMultiple";
describe("naiveLCM", () => {
test.each([[[3, 4], 12], [[8, 6], 24], [[5, 8, 3], 120], [[0.8, 0.4], 0.8]])(
"of given two numbers is correct",
(nums, expected) => {
expect(naiveLCM(nums)).toBe(expected);
},
);
test("only positive numbers should be accepted", () => {
expect(() => naiveLCM([-2, -3])).toThrowError(
"numbers must be positive to determine lowest common multiple",
);
});
test("at least one number must be passed in", () => {
expect(() => naiveLCM([])).toThrowError(
"at least one number must be passed in",
);
});
});
describe("binaryLCM", () => {
test.each([[3, 4, 12], [8, 6, 24], [8, 16, 16]])(
"of given two numbers is correct",
(numa, numb, expected) => {
expect(binaryLCM(numa, numb)).toBe(expected);
},
);
test("only whole numbers should be accepted", () => {
expect(() => binaryLCM(-2, -3)).toThrowError(
"numbers must be positive to determine lowest common multiple",
);
});
});
describe("lowestCommonMultiple", () => {
test.each([[[3, 4], 12], [[8, 6], 24], [[5, 8, 3], 120], [[8, 16], 16]])(
"of given two numbers is correct",
(nums, expected) => {
expect(lowestCommonMultiple(nums)).toBe(expected);
},
);
test("only positive numbers should be accepted", () => {
expect(() => lowestCommonMultiple([-2, -3])).toThrowError(
"numbers must be positive to determine lowest common multiple",
);
});
test("at least one number must be passed in", () => {
expect(() => lowestCommonMultiple([])).toThrowError(
"at least one number must be passed in",
);
});
});