/
years-test.js
74 lines (69 loc) · 2.26 KB
/
years-test.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
var vows = require("vows"),
load = require("../load"),
assert = require("../assert");
var suite = vows.describe("d3.time.years");
suite.addBatch({
"years": {
topic: load("time/year").expression("d3.time.years"),
"returns years": function(range) {
assert.deepEqual(range(local(2010, 0, 1), local(2013, 0, 1)), [
local(2010, 0, 1),
local(2011, 0, 1),
local(2012, 0, 1)
]);
},
"has an inclusive lower bound": function(range) {
assert.deepEqual(range(local(2010, 0, 1), local(2013, 0, 1))[0], local(2010, 0, 1));
},
"has an exclusive upper bound": function(range) {
assert.deepEqual(range(local(2010, 0, 1), local(2013, 0, 1))[2], local(2012, 0, 1));
},
"can skip years": function(range) {
assert.deepEqual(range(local(2009, 0, 1), local(2029, 0, 1), 5), [
local(2010, 0, 1),
local(2015, 0, 1),
local(2020, 0, 1),
local(2025, 0, 1)
]);
},
"UTC": {
topic: function(range) {
return range.utc;
},
"returns years": function(range) {
assert.deepEqual(range(utc(2010, 0, 1), utc(2013, 0, 1)), [
utc(2010, 0, 1),
utc(2011, 0, 1),
utc(2012, 0, 1)
]);
},
"has an inclusive lower bound": function(range) {
assert.deepEqual(range(utc(2010, 0, 1), utc(2013, 0, 1))[0], utc(2010, 0, 1));
},
"has an exclusive upper bound": function(range) {
assert.deepEqual(range(utc(2010, 0, 1), utc(2013, 0, 1))[2], utc(2012, 0, 1));
},
"can skip years": function(range) {
assert.deepEqual(range(utc(2009, 0, 1), utc(2029, 0, 1), 5), [
utc(2010, 0, 1),
utc(2015, 0, 1),
utc(2020, 0, 1),
utc(2025, 0, 1)
]);
}
}
}
});
function local(year, month, day, hours, minutes, seconds, milliseconds) {
var date = new Date();
date.setFullYear(year, month, day);
date.setHours(hours || 0, minutes || 0, seconds || 0, milliseconds || 0);
return date;
}
function utc(year, month, day, hours, minutes, seconds, milliseconds) {
var date = new Date();
date.setUTCFullYear(year, month, day);
date.setUTCHours(hours || 0, minutes || 0, seconds || 0, milliseconds || 0);
return date;
}
suite.export(module);