forked from d3/d3
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththreshold-test.js
More file actions
64 lines (61 loc) · 2.25 KB
/
Copy paththreshold-test.js
File metadata and controls
64 lines (61 loc) · 2.25 KB
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
var vows = require("vows"),
load = require("../load"),
assert = require("../assert");
var suite = vows.describe("d3.scale.threshold");
suite.addBatch({
"threshold": {
topic: load("scale/threshold").expression("d3.scale.threshold"),
"has the default domain [.5]": function(threshold) {
var x = threshold();
assert.deepEqual(x.domain(), [.5]);
assert.equal(x(.49), 0);
},
"has the default range [0, 1]": function(threshold) {
var x = threshold();
assert.deepEqual(x.range(), [0, 1]);
assert.equal(x(.50), 1);
},
"maps a number to a discrete value in the range": function(threshold) {
var x = threshold().domain([1/3, 2/3]).range(["a", "b", "c"]);
assert.equal(x(0), "a");
assert.equal(x(.2), "a");
assert.equal(x(.4), "b");
assert.equal(x(.6), "b");
assert.equal(x(.8), "c");
assert.equal(x(1), "c");
},
"returns undefined if the specified value is not orderable": function(threshold) {
var x = threshold().domain([1/3, 2/3]).range(["a", "b", "c"]);
assert.isUndefined(x());
assert.isUndefined(x(undefined));
assert.isUndefined(x(NaN));
assert.equal(x(null), "a"); // null < 1/3
},
"domain values are arbitrary": function(threshold) {
var x = threshold().domain(["10", "2"]).range([0, 1, 2]);
assert.strictEqual(x.domain()[0], "10");
assert.strictEqual(x.domain()[1], "2");
assert.equal(x("0"), 0);
assert.equal(x("12"), 1);
assert.equal(x("3"), 2);
},
"range values are arbitrary": function(threshold) {
var a = {}, b = {}, c = {}, x = threshold().domain([1/3, 2/3]).range([a, b, c]);
assert.equal(x(0), a);
assert.equal(x(.2), a);
assert.equal(x(.4), b);
assert.equal(x(.6), b);
assert.equal(x(.8), c);
assert.equal(x(1), c);
},
"invertExtent": {
"returns the domain extent for the specified range value": function(threshold) {
var a = {}, b = {}, c = {}, x = threshold().domain([1/3, 2/3]).range([a, b, c]);
assert.deepEqual(x.invertExtent(a), [undefined, 1/3]);
assert.deepEqual(x.invertExtent(b), [1/3, 2/3]);
assert.deepEqual(x.invertExtent(c), [2/3, undefined]);
}
}
}
});
suite.export(module);