1
|
|
|
import tape from 'tape'; |
2
|
|
|
import { test_dates, custom_seed, test_list1, test_list2_using_default_seed, test_list2_using_custom_seed, |
3
|
|
|
test_list3_using_default_seed, test_list3_using_custom_seed, test_list4_using_default_seed, |
4
|
|
|
test_list4_using_custom_seed, test_list5_using_default_seed, test_list5_using_custom_seed, |
5
|
|
|
test_num8_using_default_seed, test_num8_using_custom_seed |
6
|
|
|
} from './helper_data'; |
7
|
|
|
import { list1, list2, list3, list4, list5, num8, indexers } from '../src/data'; |
8
|
|
|
import { DEFAULT_SEED } from '../src/constants'; |
9
|
|
|
|
10
|
|
|
function simple_date(date) { |
11
|
|
|
return date.toLocaleDateString('en-GB', {day: '2-digit', month: '2-digit', year: 'numeric'}); |
12
|
|
|
} |
13
|
|
|
|
14
|
|
|
|
15
|
|
|
tape('Should generate the correct "list1" for the given dates', function(assert) { |
16
|
|
|
test_dates.forEach(function (date) { |
17
|
|
|
date = new Date(date); |
18
|
|
|
let l1 = list1(date); |
19
|
|
|
let timestamp = date.getTime(); |
20
|
|
|
|
21
|
|
|
assert.test('list1 for: ' + simple_date(date) + ' (timestamp: ' + timestamp + ')', function (test) { |
22
|
|
|
test.deepEqual(l1, test_list1[timestamp], 'list1 should be correct.'); |
23
|
|
|
test.end(); |
24
|
|
|
}); |
25
|
|
|
}); |
26
|
|
|
|
27
|
|
|
assert.end(); |
28
|
|
|
}); |
29
|
|
|
|
30
|
|
|
|
31
|
|
|
tape('Should generate the correct "list2"', function(assert) { |
32
|
|
|
assert.test('list2 using default seed (' + DEFAULT_SEED + ')', function (test) { |
33
|
|
|
let l2 = list2(DEFAULT_SEED); |
34
|
|
|
test.deepEqual(l2, test_list2_using_default_seed, 'list2 should be correct.'); |
35
|
|
|
test.end(); |
36
|
|
|
}); |
37
|
|
|
|
38
|
|
|
assert.test('list2 using custom seed (' + custom_seed + ')', function (test) { |
39
|
|
|
let l2 = list2(custom_seed); |
40
|
|
|
test.deepEqual(l2, test_list2_using_custom_seed, 'list2 should be correct.'); |
41
|
|
|
test.end(); |
42
|
|
|
}); |
43
|
|
|
|
44
|
|
|
assert.end(); |
45
|
|
|
}); |
46
|
|
|
|
47
|
|
|
|
48
|
|
|
tape('Should generate the correct "list3"', function(assert) { |
49
|
|
|
test_dates.forEach(function (date) { |
50
|
|
|
date = new Date(date); |
51
|
|
|
let l1 = list1(date); |
52
|
|
|
let timestamp = date.getTime(); |
53
|
|
|
|
54
|
|
|
assert.test('list3 using default seed for: ' + simple_date(date) + ' (timestamp: ' + timestamp + ')', function (test) { |
55
|
|
|
let l2 = list2(DEFAULT_SEED); |
56
|
|
|
let l3 = list3(l1, l2); |
57
|
|
|
test.deepEqual(l3, test_list3_using_default_seed[timestamp], 'list3 should be correct.'); |
58
|
|
|
test.end(); |
59
|
|
|
}); |
60
|
|
|
|
61
|
|
|
assert.test('list3 using custom seed for: ' + simple_date(date) + ' (timestamp: ' + timestamp + ')', function (test) { |
62
|
|
|
let l2 = list2(custom_seed); |
63
|
|
|
let l3 = list3(l1, l2); |
64
|
|
|
test.deepEqual(l3, test_list3_using_custom_seed[timestamp], 'list3 should be correct.'); |
65
|
|
|
test.end(); |
66
|
|
|
}); |
67
|
|
|
}); |
68
|
|
|
|
69
|
|
|
assert.end(); |
70
|
|
|
}); |
71
|
|
|
|
72
|
|
|
|
73
|
|
|
tape('Should generate the correct "list4"', function(assert) { |
74
|
|
|
test_dates.forEach(function (date) { |
75
|
|
|
date = new Date(date); |
76
|
|
|
let l1 = list1(date); |
77
|
|
|
let timestamp = date.getTime(); |
78
|
|
|
|
79
|
|
|
assert.test('list4 using default seed for: ' + simple_date(date) + ' (timestamp: ' + timestamp + ')', function (test) { |
80
|
|
|
let l2 = list2(DEFAULT_SEED); |
81
|
|
|
let l3 = list3(l1, l2); |
82
|
|
|
let l4 = list4(l3); |
83
|
|
|
test.deepEqual(l4, test_list4_using_default_seed[timestamp], 'list4 should be correct.'); |
84
|
|
|
test.end(); |
85
|
|
|
}); |
86
|
|
|
|
87
|
|
|
assert.test('list4 using custom seed for: ' + simple_date(date) + ' (timestamp: ' + timestamp + ')', function (test) { |
88
|
|
|
let l2 = list2(custom_seed); |
89
|
|
|
let l3 = list3(l1, l2); |
90
|
|
|
let l4 = list4(l3); |
91
|
|
|
test.deepEqual(l4, test_list4_using_custom_seed[timestamp], 'list4 should be correct.'); |
92
|
|
|
test.end(); |
93
|
|
|
}); |
94
|
|
|
}); |
95
|
|
|
|
96
|
|
|
assert.end(); |
97
|
|
|
}); |
98
|
|
|
|
99
|
|
|
|
100
|
|
|
tape('Should generate the correct "list5"', function(assert) { |
101
|
|
|
test_dates.forEach(function (date) { |
102
|
|
|
date = new Date(date); |
103
|
|
|
let l1 = list1(date); |
104
|
|
|
let timestamp = date.getTime(); |
105
|
|
|
|
106
|
|
|
assert.test('list5 using default seed for: ' + simple_date(date) + ' (timestamp: ' + timestamp + ')', function (test) { |
107
|
|
|
let l2 = list2(DEFAULT_SEED); |
108
|
|
|
let l3 = list3(l1, l2); |
109
|
|
|
let l4 = list4(l3); |
110
|
|
|
let l5 = list5(DEFAULT_SEED, l4); |
111
|
|
|
test.deepEqual(l5, test_list5_using_default_seed[timestamp], 'list5 should be correct.'); |
112
|
|
|
test.end(); |
113
|
|
|
}); |
114
|
|
|
|
115
|
|
|
assert.test('list5 using custom seed for: ' + simple_date(date) + ' (timestamp: ' + timestamp + ')', function (test) { |
116
|
|
|
let l2 = list2(custom_seed); |
117
|
|
|
let l3 = list3(l1, l2); |
118
|
|
|
let l4 = list4(l3); |
119
|
|
|
let l5 = list5(custom_seed, l4); |
120
|
|
|
test.deepEqual(l5, test_list5_using_custom_seed[timestamp], 'list5 should be correct.'); |
121
|
|
|
test.end(); |
122
|
|
|
}); |
123
|
|
|
}); |
124
|
|
|
|
125
|
|
|
assert.end(); |
126
|
|
|
}); |
127
|
|
|
|
128
|
|
|
|
129
|
|
|
tape('Should generate the correct "num8"', function(assert) { |
130
|
|
|
test_dates.forEach(function (date) { |
131
|
|
|
date = new Date(date); |
132
|
|
|
let l1 = list1(date); |
133
|
|
|
let timestamp = date.getTime(); |
134
|
|
|
|
135
|
|
|
assert.test('num8 using default seed for: ' + simple_date(date) + ' (timestamp: ' + timestamp + ')', function (test) { |
136
|
|
|
let l2 = list2(DEFAULT_SEED); |
137
|
|
|
let l3 = list3(l1, l2); |
138
|
|
|
let n8 = num8(l3); |
139
|
|
|
test.equal(n8, test_num8_using_default_seed[timestamp], 'num8 should be correct.'); |
140
|
|
|
test.end(); |
141
|
|
|
}); |
142
|
|
|
|
143
|
|
|
assert.test('num8 using custom seed for: ' + simple_date(date) + ' (timestamp: ' + timestamp + ')', function (test) { |
144
|
|
|
let l2 = list2(custom_seed); |
145
|
|
|
let l3 = list3(l1, l2); |
146
|
|
|
let n8 = num8(l3); |
147
|
|
|
test.equal(n8, test_num8_using_custom_seed[timestamp], 'num8 should be correct.'); |
148
|
|
|
test.end(); |
149
|
|
|
}); |
150
|
|
|
}); |
151
|
|
|
|
152
|
|
|
assert.end(); |
153
|
|
|
}); |
154
|
|
|
|
155
|
|
|
|
156
|
|
|
tape('Should generate the correct "indexers"', function(assert) { |
157
|
|
|
test_dates.forEach(function (date) { |
158
|
|
|
date = new Date(date); |
159
|
|
|
let timestamp = date.getTime(); |
160
|
|
|
|
161
|
|
|
assert.test('indexers using default seed for: ' + simple_date(date) + ' (timestamp: ' + timestamp + ')', function (test) { |
162
|
|
|
let idx = indexers(date, DEFAULT_SEED); |
163
|
|
|
test.deepEqual(idx, test_list5_using_default_seed[timestamp], 'indexers should be correct.'); |
164
|
|
|
test.end(); |
165
|
|
|
}); |
166
|
|
|
|
167
|
|
|
assert.test('indexers using custom seed for: ' + simple_date(date) + ' (timestamp: ' + timestamp + ')', function (test) { |
168
|
|
|
let idx = indexers(date, custom_seed); |
169
|
|
|
test.deepEqual(idx, test_list5_using_custom_seed[timestamp], 'indexers should be correct.'); |
170
|
|
|
test.end(); |
171
|
|
|
}); |
172
|
|
|
}); |
173
|
|
|
|
174
|
|
|
assert.end(); |
175
|
|
|
}); |
176
|
|
|
|