d3/test/scale/threshold-test.js

50 строки
1.6 KiB
JavaScript
Исходник Обычный вид История

2012-08-09 07:33:23 +04:00
var vows = require("vows"),
2013-03-14 10:21:23 +04:00
load = require("../load"),
2013-03-14 23:59:54 +04:00
assert = require("../assert");
2012-08-09 07:33:23 +04:00
var suite = vows.describe("d3.scale.threshold");
suite.addBatch({
"threshold": {
2013-03-14 21:52:01 +04:00
topic: load("scale/threshold").expression("d3.scale.threshold"),
"has the default domain [.5]": function(threshold) {
var x = threshold();
2012-08-09 07:33:23 +04:00
assert.deepEqual(x.domain(), [.5]);
assert.equal(x(.49), 0);
},
2013-03-14 21:52:01 +04:00
"has the default range [0, 1]": function(threshold) {
var x = threshold();
2012-08-09 07:33:23 +04:00
assert.deepEqual(x.range(), [0, 1]);
assert.equal(x(.50), 1);
},
2013-03-14 21:52:01 +04:00
"maps a number to a discrete value in the range": function(threshold) {
var x = threshold().domain([1/3, 2/3]).range(["a", "b", "c"]);
2012-08-09 07:33:23 +04:00
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");
},
2013-03-14 21:52:01 +04:00
"domain values are arbitrary": function(threshold) {
var x = threshold().domain(["10", "2"]).range([0, 1, 2]);
2012-08-09 07:33:23 +04:00
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);
},
2013-03-14 21:52:01 +04:00
"range values are arbitrary": function(threshold) {
var a = {}, b = {}, c = {}, x = threshold().domain([1/3, 2/3]).range([a, b, c]);
2012-08-09 07:33:23 +04:00
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);
}
}
});
suite.export(module);