Debian Codegraph @

tests/moment-timezone/create-links.js

raw symbols ◀ ▶ SCIP
1 Debian patch touch this file
1 "use strict";
2
•3 delete require.cache[require.resolve("../../moment-timezone-utils")];
4 delete require.cache[require.resolve("../../moment-timezone")];
5 delete require.cache[require.resolve("../../")];
6 var tz = require("../../moment-timezone-utils").tz;
7
8 // A == B
9 // C == D == E
10
11 var ZONE_A = {
12 name : "Zone/A",
13 abbrs : ["ABC", "DEF", "GHI"],
14 offsets : [10, 20, 30],
15 untils : [-1000, 100, 200]
16 };
17
18 var ZONE_B = {
19 name : "Zone/B",
20 abbrs : ["ABC", "DEF", "GHI"],
21 offsets : [10, 20, 30],
22 untils : [-1000, 100, 200]
23 };
24
25 var ZONE_C = {
26 name : "Zone/C",
27 abbrs : ["ZYX", "WVU"],
28 offsets : [20, 30],
29 untils : [-3000, 900]
30 };
31
32 var ZONE_D = {
33 name : "Zone/D",
34 abbrs : ["ZYX", "WVU"],
35 offsets : [20, 30],
36 untils : [-3000, 900]
37 };
38
39 var ZONE_E = {
40 name : "Zone/E",
41 abbrs : ["ZYX", "WVU"],
42 offsets : [20, 30],
43 untils : [-3000, 900]
44 };
45
46 var ZONES_ABC = {
47 zones : [ZONE_A, ZONE_B, ZONE_C],
48 links : [],
49 version : '2014abc'
50 };
51
52 var ZONES_ACD = {
53 zones : [ZONE_A, ZONE_C, ZONE_D],
54 links : [],
55 version : '2014acd'
56 };
57
58 var ZONES_ADCB = {
59 zones : [ZONE_A, ZONE_D, ZONE_C, ZONE_B],
60 links : [],
61 version : '2014adcb'
62 };
63
64 var ZONES_ABCD = {
65 zones : [ZONE_A, ZONE_B, ZONE_C, ZONE_D],
66 links : [],
67 version : '2014abcd'
68 };
69
70 var ZONES_ABCDE = {
71 zones : [ZONE_A, ZONE_B, ZONE_C, ZONE_D, ZONE_E],
72 links : [],
73 version : '2014abcde'
74 };
75
76
77 exports['create-links'] = {
78 abc : function (test) {
79 var actual = tz.createLinks(ZONES_ABC),
80 expected = {
81 zones : [ZONE_A, ZONE_C],
82 links : ['Zone/A|Zone/B'],
83 version : '2014abc'
84 };
85
86 test.deepEqual(actual, expected, "Should be able to create a link between two identical zones.");
87 test.done();
88 },
89
90 acd : function (test) {
91 var actual = tz.createLinks(ZONES_ACD),
92 expected = {
93 zones : [ZONE_A, ZONE_C],
94 links : ['Zone/C|Zone/D'],
95 version : '2014acd'
96 };
97
98 test.deepEqual(actual, expected, "Should be able to create a link between two identical zones.");
99 test.done();
100 },
101
102 adcb : function (test) {
103 var actual = tz.createLinks(ZONES_ADCB),
104 expected = {
105 zones : [ZONE_A, ZONE_D],
106 links : ['Zone/A|Zone/B', 'Zone/D|Zone/C'],
107 version : '2014adcb'
108 };
109
110 test.deepEqual(actual, expected, "Should be able to create a link between two identical zones.");
111 test.done();
112 },
113
114 abcd : function (test) {
115 var actual = tz.createLinks(ZONES_ABCD),
116 expected = {
117 zones : [ZONE_A, ZONE_C],
118 links : ['Zone/A|Zone/B', 'Zone/C|Zone/D'],
119 version : '2014abcd'
120 };
121
122 test.deepEqual(actual, expected, "Should be able to create a link between two identical zones.");
123 test.done();
124 },
125
126 abcde : function (test) {
127 var actual = tz.createLinks(ZONES_ABCDE),
128 expected = {
129 zones : [ZONE_A, ZONE_C],
130 links : ['Zone/A|Zone/B', 'Zone/C|Zone/D', 'Zone/C|Zone/E'],
131 version : '2014abcde'
132 };
133
134 test.deepEqual(actual, expected, "Should be able to create a link between two identical zones.");
135 test.done();
136 },
137
138 'differing offsets' : function (test) {
139 var A = {
140 name : "Zone/A",
141 abbrs : ["ABC", "DEF", "GHI"],
142 offsets : [10, 20, 30],
143 untils : [-1000, 100, 200]
144 },
145 B = {
146 name : "Zone/B",
147 abbrs : ["ABC", "DEF", "GHI"],
148 offsets : [10, 20, 40],
149 untils : [-1000, 100, 200]
150 },
151 AB = {
152 zones : [A, B],
153 links : [],
154 version : '2014ab'
155 };
156
157 var actual = tz.createLinks(AB),
158 expected = {
159 zones : [A, B],
160 links : [],
161 version : '2014ab'
162 };
163
164 test.deepEqual(actual, expected, "Should not create a link if the offsets are different.");
165 test.done();
166 },
167
168 'differing untils' : function (test) {
169 var A = {
170 name : "Zone/A",
171 abbrs : ["ABC", "DEF", "GHI"],
172 offsets : [10, 20, 30],
173 untils : [-1000, 100, 200]
174 },
175 B = {
176 name : "Zone/B",
177 abbrs : ["ABC", "DEF", "GHI"],
178 offsets : [10, 20, 30],
179 untils : [-1000, 100, 300]
180 },
181 AB = {
182 zones : [A, B],
183 links : [],
184 version : '2014ab'
185 };
186
187 var actual = tz.createLinks(AB),
188 expected = {
189 zones : [A, B],
190 links : [],
191 version : '2014ab'
192 };
193
194 test.deepEqual(actual, expected, "Should not create a link if the untils are different.");
195 test.done();
196 },
197
198 'differing abbrs' : function (test) {
199 var A = {
200 name : "Zone/A",
201 abbrs : ["ABC", "DEF", "GHI"],
202 offsets : [10, 20, 30],
203 untils : [-1000, 100, 200]
204 },
205 B = {
206 name : "Zone/B",
207 abbrs : ["ABC", "DEF", "XYZ"],
208 offsets : [10, 20, 30],
209 untils : [-1000, 100, 200]
210 },
211 AB = {
212 zones : [A, B],
213 links : [],
214 version : '2014ab'
215 };
216
217 var actual = tz.createLinks(AB),
218 expected = {
219 zones : [A, B],
220 links : [],
221 version : '2014ab'
222 };
223
224 test.deepEqual(actual, expected, "Should not create a link if the abbrs are different.");
225 test.done();
226 },
227
228 'differing lengths' : function (test) {
229 var A = {
230 name : "Zone/A",
231 abbrs : ["ABC", "DEF", "GHI"],
232 offsets : [10, 20, 30],
233 untils : [-1000, 100, 200]
234 },
235 B = {
236 name : "Zone/B",
237 abbrs : ["ABC", "DEF", "GHI", "JKL"],
238 offsets : [10, 20, 30, 40],
239 untils : [-1000, 100, 200, 300]
240 },
241 AB = {
242 zones : [A, B],
243 links : [],
244 version : '2014ab'
245 };
246
247 var actual = tz.createLinks(AB),
248 expected = {
249 zones : [A, B],
250 links : [],
251 version : '2014ab'
252 };
253
254 test.deepEqual(actual, expected, "Should not create a link if the lengths of any of the arrays are different.");
255 test.done();
256 },
257
258 'retain existing links' : function (test) {
259 var actual = tz.createLinks({
260 zones : [ZONE_A, ZONE_B, ZONE_C],
261 links : ["Test/A|Test/B", "Test/A|Test/C"],
262 version : '2014abcretain'
263 }),
264 expected = {
265 zones : [ZONE_A, ZONE_C],
266 links : ["Test/A|Test/B", "Test/A|Test/C", "Zone/A|Zone/B"],
267 version : '2014abcretain'
268 };
269
270 test.deepEqual(actual, expected, "Should retain existing links passed in.");
271 test.done();
272 },
273
274 'make the zone with the smaller population a link' : function (test) {
275 var large = {
276 name : "Zone/Large",
277 abbrs : ["ABC", "DEF", "GHI"],
278 offsets : [10, 20, 30],
279 untils : [-1000, 100, 200],
280 population : 100
281 },
282 small = {
283 name : "Zone/Small",
284 abbrs : ["ABC", "DEF", "GHI"],
285 offsets : [10, 20, 30],
286 untils : [-1000, 100, 200],
287 population : 20
288 },
289 largeFirst = {
290 zones : [large, small],
291 links : [],
292 version : '2014populations'
293 },
294 smallFirst = {
295 zones : [small, large],
296 links : [],
297 version : '2014populations'
298 },
299 expected = {
300 zones : [large],
301 links : ["Zone/Large|Zone/Small"],
302 version : '2014populations'
303 };
304
305 test.deepEqual(tz.createLinks(largeFirst), expected, "Make smaller population a link.");
306 test.deepEqual(tz.createLinks(smallFirst), expected, "Make smaller population a link.");
307
308 test.done();
309 }
310 };