-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
index.tests.js
82 lines (75 loc) · 2.76 KB
/
index.tests.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
import * as assert from "assert";
import { toMeridiem, toMilitary } from "midday";
const testMeridiem = () => {
assert.strictEqual(toMeridiem("00:00"), "12:00 AM");
assert.strictEqual(toMeridiem("00:01"), "12:01 AM");
assert.strictEqual(toMeridiem("01:15"), "1:15 AM");
assert.strictEqual(toMeridiem("02:30"), "2:30 AM");
assert.strictEqual(toMeridiem("03:45"), "3:45 AM");
assert.strictEqual(toMeridiem("11:59"), "11:59 AM");
assert.strictEqual(toMeridiem("12:00"), "12:00 PM");
assert.strictEqual(toMeridiem("13:15"), "1:15 PM");
assert.strictEqual(toMeridiem("14:30"), "2:30 PM");
assert.strictEqual(toMeridiem("15:45"), "3:45 PM");
assert.strictEqual(toMeridiem("20:15"), "8:15 PM");
assert.strictEqual(toMeridiem("21:30"), "9:30 PM");
assert.strictEqual(toMeridiem("22:45"), "10:45 PM");
assert.strictEqual(toMeridiem("23:59"), "11:59 PM");
assert.strictEqual(toMeridiem("0000"), "12:00 AM");
assert.strictEqual(toMeridiem("0030"), "12:30 AM");
assert.strictEqual(toMeridiem("1315"), "1:15 PM");
assert.strictEqual(toMeridiem("2315"), "11:15 PM");
assert.strictEqual(toMeridiem("030"), "12:30 AM");
assert.strictEqual(toMeridiem("730"), "7:30 AM");
assert.throws(
() => toMeridiem("24:00"),
Error,
"Should throw an error if the time string is invalid."
);
assert.throws(
() => toMeridiem("29:00"),
Error,
"Should throw an error if the time string is invalid."
);
assert.throws(
() => toMeridiem("10:95"),
Error,
"Should throw an error if the time string is invalid."
);
};
const testMilitary = () => {
assert.strictEqual(toMilitary("12:00 AM"), "00:00");
assert.strictEqual(toMilitary("12:01 AM"), "00:01");
assert.strictEqual(toMilitary("1:15 AM"), "01:15");
assert.strictEqual(toMilitary("2:30 AM"), "02:30");
assert.strictEqual(toMilitary("3:45 AM"), "03:45");
assert.strictEqual(toMilitary("11:59 AM"), "11:59");
assert.strictEqual(toMilitary("12:00 PM"), "12:00");
assert.strictEqual(toMilitary("1:15 PM"), "13:15");
assert.strictEqual(toMilitary("2:30 PM"), "14:30");
assert.strictEqual(toMilitary("3:45 PM"), "15:45");
assert.strictEqual(toMilitary("8:15 PM"), "20:15");
assert.strictEqual(toMilitary("9:30 PM"), "21:30");
assert.strictEqual(toMilitary("10:45 PM"), "22:45");
assert.strictEqual(toMilitary("11:59 PM"), "23:59");
assert.throws(
() => toMilitary("14:15 PM"),
Error,
"Should throw an error if the time string is invalid."
);
assert.throws(
() => toMilitary("41:15 PM"),
Error,
"Should throw an error if the time string is invalid."
);
assert.throws(
() => toMilitary("1:99 PM"),
Error,
"Should throw an error if the time string is invalid."
);
};
const runTests = () => {
testMeridiem();
testMilitary();
};
runTests();