Commit 994235b3 authored by Mike Bostock's avatar Mike Bostock
Browse files

Test for interpolate to null.

I’m not entirely sure this is the most useful behavior, but since typeof null is
"object" and +null is 0, interpolating to null is equivalent to interpolating to
the number zero.
parent d3bbf394
......@@ -95,11 +95,11 @@ suite.addBatch({
"interpolates each property in b": function(d3) {
assert.deepEqual(d3.interpolate({foo: 2, bar: 4}, {foo: 12, bar: 24})(.4), {foo: 6, bar: 12});
},
"interpolates numbers if b is coercible to a number (not NaN)": function(d3) {
var two = new Number(2), twelve = new Number(12);
assert.strictEqual(d3.interpolate(two, twelve)(.4), 6);
var start = new Date(2012, 0, 1), end = new Date(2013, 0, 1);
assert.strictEqual(d3.interpolate(start, end)(.5), +new Date(2012, 6, 2, 1));
"interpolates numbers if b is coercible to a number (!isNaN(+b))": function(d3) {
assert.strictEqual(d3.interpolate(new Number(2), new Number(12))(.4), 6);
assert.strictEqual(d3.interpolate(new Date(2012, 0, 1), new Date(2013, 0, 1))(.5), +new Date(2012, 6, 2, 1));
assert.strictEqual(d3.interpolate(1, null)(.4), .6); // +null = 0
assert.isNaN(d3.interpolate("blue", null)(.4));
},
"reuses the returned object during interpolation": function(d3) {
var i = d3.interpolate({foo: 2, bar: 4}, {foo: 12, bar: 24});
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment