-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompare.test.ts
More file actions
96 lines (82 loc) · 3.17 KB
/
compare.test.ts
File metadata and controls
96 lines (82 loc) · 3.17 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
94
95
96
import compare, { isEqual, isGreaterThan, isLessThan, min, max } from "../src/compare";
describe("compare", () => {
test("should compare positive integers correctly", () => {
expect(compare("123", "456")).toBe(-1);
expect(compare("456", "123")).toBe(1);
expect(compare("123", "123")).toBe(0);
});
test("should compare negative integers correctly", () => {
expect(compare("-123", "-456")).toBe(1);
expect(compare("-456", "-123")).toBe(-1);
expect(compare("-123", "-123")).toBe(0);
});
test("should compare positive and negative numbers correctly", () => {
expect(compare("123", "-456")).toBe(1);
expect(compare("-123", "456")).toBe(-1);
expect(compare("0", "-0")).toBe(0);
});
test("should compare decimal numbers correctly", () => {
expect(compare("123.456", "123.789")).toBe(-1);
expect(compare("123.789", "123.456")).toBe(1);
expect(compare("123.456", "123.456")).toBe(0);
});
test("should compare very large numbers correctly", () => {
expect(compare("999999999999999999999999", "1000000000000000000000000")).toBe(-1);
expect(compare("1000000000000000000000000", "999999999999999999999999")).toBe(1);
});
test("should compare very small decimal numbers correctly", () => {
expect(compare("0.000000000000000001", "0.000000000000000002")).toBe(-1);
expect(compare("0.000000000000000002", "0.000000000000000001")).toBe(1);
});
test("should handle zero correctly", () => {
expect(compare("0", "0")).toBe(0);
expect(compare("0", "-0")).toBe(0);
expect(compare("0.0", "0")).toBe(0);
expect(compare("0", "1")).toBe(-1);
expect(compare("1", "0")).toBe(1);
});
});
describe("isEqual", () => {
test("should check equality correctly", () => {
expect(isEqual("123", "123")).toBe(true);
expect(isEqual("123", "456")).toBe(false);
expect(isEqual("123.456", "123.456")).toBe(true);
expect(isEqual("0", "-0")).toBe(true);
});
});
describe("isGreaterThan", () => {
test("should check greater than correctly", () => {
expect(isGreaterThan("456", "123")).toBe(true);
expect(isGreaterThan("123", "456")).toBe(false);
expect(isGreaterThan("123", "123")).toBe(false);
});
});
describe("isLessThan", () => {
test("should check less than correctly", () => {
expect(isLessThan("123", "456")).toBe(true);
expect(isLessThan("456", "123")).toBe(false);
expect(isLessThan("123", "123")).toBe(false);
});
});
describe("min", () => {
test("should find minimum of two numbers", () => {
expect(min("123", "456")).toBe("123");
expect(min("456", "123")).toBe("123");
expect(min("-123", "-456")).toBe("-456");
});
test("should find minimum of multiple numbers", () => {
expect(min("123", "456", "789", "12")).toBe("12");
expect(min("-10", "-20", "-5", "-30")).toBe("-30");
});
});
describe("max", () => {
test("should find maximum of two numbers", () => {
expect(max("123", "456")).toBe("456");
expect(max("456", "123")).toBe("456");
expect(max("-123", "-456")).toBe("-123");
});
test("should find maximum of multiple numbers", () => {
expect(max("123", "456", "789", "12")).toBe("789");
expect(max("-10", "-20", "-5", "-30")).toBe("-5");
});
});