-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
100 lines (78 loc) · 1.94 KB
/
test.js
File metadata and controls
100 lines (78 loc) · 1.94 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
97
98
99
100
import test from 'ava';
import randMS from './wrapper.mjs';
test('correct params', (t) => {
t.throws(() => {
randMS('a');
}, {
instanceOf: TypeError,
message: 'Expected a number or string, eg: 1 or "1s", got "a"',
});
t.throws(() => {
randMS(1, 'a');
}, {
instanceOf: TypeError,
message: 'Expected a number or string, eg: 1 or "1s", got "a"',
});
t.throws(() => {
randMS(3, 1);
}, {
instanceOf: TypeError,
message: 'Expected max "1" to be greater than min "3"',
});
});
test('ms', (t) => {
const rand = randMS();
t.true(rand < 10_001);
const randMS0 = randMS('1ms', '1ms');
t.is(randMS0, 1);
const randMS1 = randMS('1millisecond', '1milliseconds');
t.is(randMS1, 1);
});
test('s', (t) => {
const randS = randMS(1, 1);
t.is(randS, 1000);
const randS1 = randMS(1, '1s');
t.is(randS1, 1000);
const randS2 = randMS('1second', '1seconds');
t.is(randS2, 1000);
});
test('m', (t) => {
const randM = randMS('1m', '1m');
t.is(randM, 60_000);
const randM1 = randMS('1minute', '1minutes');
t.is(randM1, 60_000);
});
test('h', (t) => {
const randH = randMS('1h', '1h');
t.is(randH, 3_600_000);
const randH1 = randMS('1hour', '1hours');
t.is(randH1, 3_600_000);
});
test('d', (t) => {
const randD = randMS('1d', '1d');
t.is(randD, 86_400_000);
const randD1 = randMS('1day', '1days');
t.is(randD1, 86_400_000);
});
test('w', (t) => {
const randW = randMS('1w', '1w');
t.is(randW, 604_800_000);
const randW1 = randMS('1week', '1weeks');
t.is(randW1, 604_800_000);
});
test('M', (t) => {
const randMonths = randMS('1M', '1M');
t.is(randMonths, 2_592_000_000);
const randMonths1 = randMS('1month', '1Months');
t.is(randMonths1, 2_592_000_000);
});
test('Y', (t) => {
const randY = randMS('1y', '1y');
t.is(randY, 31_557_600_000);
const randY1 = randMS('1year', '1years');
t.is(randY1, 31_557_600_000);
});
test('span', (t) => {
const randI = randMS('1h', '1y');
t.true(randI > 3_600_000 && randI < 31_557_600_000);
});