forked from dc-js/dc.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils-test.js
123 lines (113 loc) · 3.88 KB
/
utils-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
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
require("./env");
var vows = require('vows');
var assert = require('assert');
var suite = vows.describe('Utils');
suite.addBatch({
'dc.printer.filters': {
topic: function () {
return dc.printers.filters;
},
'print simple string': function (printer) {
assert.equal(printer(["a"]), "a");
},
'print range': function (printer) {
assert.equal(printer([[10, 30]]), "[10 -> 30]");
},
'print simple string and a range': function (printer) {
assert.equal(printer(["a", [10, 30]]), "a, [10 -> 30]");
}
}
});
suite.addBatch({
'dc.printer.filter': {
topic: function () {
return dc.printers.filter;
},
'print simple string': function (printer) {
assert.equal(printer("a"), "a");
},
'print date string': function (printer) {
assert.equal(printer(new Date(2012, 1, 1)), "02/01/2012");
},
'print int range': function (printer) {
assert.equal(printer([10, 30]), "[10 -> 30]");
},
'print float range': function (printer) {
assert.equal(printer([10.124244, 30.635623]), "[10 -> 31]");
},
'print date range': function (printer) {
assert.equal(printer([new Date(2012, 1, 1), new Date(2012, 1, 15)]), "[02/01/2012 -> 02/15/2012]");
},
'print single element array': function (printer) {
assert.equal(printer([new Date(2012, 1, 1)]), "02/01/2012");
},
'print null': function (printer) {
assert.equal(printer(null), "");
}
}
});
suite.addBatch({
'dc.utils.nameToId': {
topic: function () {
return dc.utils.nameToId("St. John's");
},
'id should be escaped properly': function (id) {
assert.equal(id, "st_johns");
}
}
});
suite.addBatch({
'dc.utils.add': {
topic: function () {
return dc.utils.add;
},
'should be able to add days': function (add) {
var date = add(new Date(2012, 0, 1), 10);
assert.equal(date.toString(), (new Date(2012, 0, 11)).toString());
},
'should be able to add numbers': function (add) {
var num = add(10, 10);
assert.equal(num, 20);
},
'should be able to add numbers w/ %': function (add) {
var num = add(10, "10%");
assert.equal(num, 11);
},
'should be able to add negative numbers w/ %': function (add) {
var num = add(-10, "10%");
assert.equal(num, -9);
},
'should ignore % when adding dates': function (add) {
var date = add(new Date(2012, 0, 1), "10%");
assert.equal(date.toString(), new Date(2012, 0, 11).toString());
}
}
});
suite.addBatch({
'dc.utils.subtract': {
topic: function () {
return dc.utils.subtract;
},
'should be able to subtract dates': function (subtract) {
var date = subtract(new Date(2012, 0, 11), 10);
assert.equal(date.toString(), (new Date(2012, 0, 1)).toString());
},
'should be able to subtract numbers': function (subtract) {
var num = subtract(10, 10);
assert.equal(num, 0);
},
'should be able to subtract numbers w/ %': function (subtract) {
var num = subtract(10, "10%");
assert.equal(num, 9);
},
'should be able to subtract negative numbers w/ %': function (subtract) {
var num = subtract(-10, "10%");
assert.equal(num, -11);
},
'should ignore % when subtracting dates': function (subtract) {
var date = subtract(new Date(2012, 0, 11), "10%");
assert.equal(date.toString(), new Date(2012, 0, 1).toString());
}
}
});
suite.export(module);