-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdivide.test.ts
More file actions
93 lines (83 loc) · 1.98 KB
/
divide.test.ts
File metadata and controls
93 lines (83 loc) · 1.98 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import divide from "../src/divide";
const TIME_OUT = 10;
describe("divide function test", () => {
test(
"Dividing positive numbers",
async () => {
expect(divide("10", "2")).toBe("5");
expect(divide("100", "25")).toBe("4");
expect(divide("7", "2")).toBe("3.5");
},
TIME_OUT
);
test(
"Dividing negative numbers",
async () => {
expect(divide("-10", "2")).toBe("-5");
expect(divide("10", "-2")).toBe("-5");
expect(divide("-10", "-2")).toBe("5");
},
TIME_OUT
);
test(
"Dividing decimals",
async () => {
expect(divide("3.14", "2")).toBe("1.57");
expect(divide("1", "3")).toBe("0.33333333333333333333");
expect(divide("0.1", "0.3")).toBe("0.33333333333333333333");
},
TIME_OUT
);
test(
"Dividing by zero",
async () => {
expect(() => divide("10", "0")).toThrow();
expect(() => divide("-5", "0")).toThrow();
expect(() => divide("0", "0")).toThrow();
},
TIME_OUT
);
test(
"Dividing zero",
async () => {
expect(divide("0", "5")).toBe("0");
expect(divide("0", "-3")).toBe("0");
expect(divide("0", "0.1")).toBe("0");
},
TIME_OUT
);
test(
"Dividing large numbers",
async () => {
expect(divide("1000000000000000", "1000000")).toBe("1000000000");
expect(divide("9999999999", "3")).toBe("3333333333");
},
TIME_OUT
);
test(
"Dividing small numbers",
async () => {
expect(divide("0.0000001", "0.0001")).toBe("0.001");
expect(divide("0.000000001", "0.000000003")).toBe(
"0.33333333333333333333"
);
},
TIME_OUT
);
test(
"Precision test",
async () => {
expect(divide("1", "3", 5)).toBe("0.33333");
expect(divide("2", "3", 10)).toBe("0.6666666667");
},
TIME_OUT
);
test(
"Rounding test",
async () => {
expect(divide("10", "3", 2)).toBe("3.33");
expect(divide("1", "6", 3)).toBe("0.167");
},
TIME_OUT
);
});