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