-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
127 lines (118 loc) · 2.64 KB
/
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
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/* eslint-disable no-undef */
import {
isEmpty,
minBy,
isEqual,
isValidDate,
getDateObject,
} from "./dist/main.js";
const logTestResult = (description, result) => {
if (result) {
console.log(`✅ \x1b[32m${description}: PASSED\x1b[0m`);
} else {
console.log(`❌ \x1b[31m${description}: FAILED\x1b[0m`);
}
};
console.log("------ START OF TESTS ------\n");
console.log("\n------ TEST: isEmpty ------");
try {
let a = [];
const result = isEmpty(a);
logTestResult("isEmpty([])", result);
} catch (e) {
logTestResult("isEmpty([])", false);
}
console.log("\n");
console.log("------ TEST: minBy ------");
try {
const intervals = [
{ daily: 1000 },
{ monthly: 200 },
{ weekly: 300 },
{ yearly: 40 },
];
const min = minBy(intervals, (x) => x[Object.keys(x)[0]]);
logTestResult("minBy(intervals)", min.yearly === 40);
} catch (e) {
logTestResult("minBy(intervals)", false);
}
console.log("\n");
console.log("------ TEST: isEqual ------");
try {
const a = {
a: 1,
b: { c: 1, d: { e: 1, f: { g: 1, h: { i: 1, j: { j: [1, 2, 3] } } } } },
};
const b = {
a: 1,
b: { c: 1, d: { e: 1, f: { g: 1, h: { i: 1, j: { j: [1, 2, 4] } } } } },
};
const result1 = isEqual(a, b);
logTestResult("isEqual(Object a, b)", !result1);
const x = [
1,
2,
{
a: 1,
b: 2,
c: {
a: 2,
b: {
m: [
1,
2,
{
m: [1, 2, 4],
},
],
},
},
},
];
const y = [
1,
2,
{
a: 1,
b: 2,
c: {
a: 2,
b: {
m: [
1,
2,
{
m: [1, 2],
},
],
},
},
},
];
const result2 = isEqual(x, y);
logTestResult("isEqual(Array x, y)", !result2);
} catch (e) {
logTestResult("isEqual(Object or Array)", false);
}
console.log("\n");
console.log("------ TEST: isValidDate ------");
try {
logTestResult('isValidDate("01-01-2000")', isValidDate("01-01-2000"));
logTestResult('isValidDate("29-02-2000")', isValidDate("29-02-2000"));
logTestResult('isValidDate("29-02-2001")', !isValidDate("29-02-2001"));
logTestResult('isValidDate("2001-02-29")', !isValidDate("2001-02-29"));
} catch (e) {
logTestResult("isValidDate", false);
}
console.log("\n");
console.log("------ TEST: getDateObject ------");
try {
logTestResult(
'getDateObject("01-01-2000")',
JSON.stringify(getDateObject("01-01-2000")) ===
JSON.stringify({ year: "2000", month: "1", day: "1" })
);
} catch (e) {
logTestResult("getDateObject", false);
}
console.log("\n------ END OF TESTS ------\n");