|
| 1 | +require("../env"); |
| 2 | + |
| 3 | +var vows = require("vows"), |
| 4 | + assert = require("assert"); |
| 5 | + |
| 6 | +var suite = vows.describe("d3.scale.threshold"); |
| 7 | + |
| 8 | +suite.addBatch({ |
| 9 | + "threshold": { |
| 10 | + topic: function() { |
| 11 | + return d3.scale.threshold; |
| 12 | + }, |
| 13 | + "has the default domain [.5]": function(threshold) { |
| 14 | + var x = threshold(); |
| 15 | + assert.deepEqual(x.domain(), [.5]); |
| 16 | + assert.equal(x(.49), 0); |
| 17 | + }, |
| 18 | + "has the default range [0, 1]": function(threshold) { |
| 19 | + var x = threshold(); |
| 20 | + assert.deepEqual(x.range(), [0, 1]); |
| 21 | + assert.equal(x(.50), 1); |
| 22 | + }, |
| 23 | + "maps a number to a discrete value in the range": function(threshold) { |
| 24 | + var x = threshold().domain([1/3, 2/3]).range(["a", "b", "c"]); |
| 25 | + assert.equal(x(0), "a"); |
| 26 | + assert.equal(x(.2), "a"); |
| 27 | + assert.equal(x(.4), "b"); |
| 28 | + assert.equal(x(.6), "b"); |
| 29 | + assert.equal(x(.8), "c"); |
| 30 | + assert.equal(x(1), "c"); |
| 31 | + }, |
| 32 | + "domain values are arbitrary": function(threshold) { |
| 33 | + var x = threshold().domain(["10", "2"]).range([0, 1, 2]); |
| 34 | + assert.strictEqual(x.domain()[0], "10"); |
| 35 | + assert.strictEqual(x.domain()[1], "2"); |
| 36 | + assert.equal(x("0"), 0); |
| 37 | + assert.equal(x("12"), 1); |
| 38 | + assert.equal(x("3"), 2); |
| 39 | + }, |
| 40 | + "range values are arbitrary": function(threshold) { |
| 41 | + var a = {}, b = {}, c = {}, x = threshold().domain([1/3, 2/3]).range([a, b, c]); |
| 42 | + assert.equal(x(0), a); |
| 43 | + assert.equal(x(.2), a); |
| 44 | + assert.equal(x(.4), b); |
| 45 | + assert.equal(x(.6), b); |
| 46 | + assert.equal(x(.8), c); |
| 47 | + assert.equal(x(1), c); |
| 48 | + } |
| 49 | + } |
| 50 | +}); |
| 51 | + |
| 52 | +suite.export(module); |
0 commit comments