Add test for pointRadius function type coercion.

This commit is contained in:
Jason Davies 2012-12-13 21:55:00 +00:00
Родитель c7d4fabb9d
Коммит 01a7e187ea
1 изменённых файлов: 28 добавлений и 17 удалений

Просмотреть файл

@ -22,7 +22,7 @@ suite.addBatch({
}); });
assert.deepEqual(testContext.buffer(), [ assert.deepEqual(testContext.buffer(), [
{type: "moveTo", x: 165, y: 160}, {type: "moveTo", x: 165, y: 160},
{type: "arc", x: 165, y: 160} {type: "arc", x: 165, y: 160, r: 4.5}
]); ]);
}, },
@ -32,9 +32,9 @@ suite.addBatch({
coordinates: [[-63, 18], [-62, 18], [-62, 17]] coordinates: [[-63, 18], [-62, 18], [-62, 17]]
}); });
assert.deepEqual(testContext.buffer(), [ assert.deepEqual(testContext.buffer(), [
{type: "moveTo", x: 165, y: 160}, {type: "arc", x: 165, y: 160}, {type: "moveTo", x: 165, y: 160}, {type: "arc", x: 165, y: 160, r: 4.5},
{type: "moveTo", x: 170, y: 160}, {type: "arc", x: 170, y: 160}, {type: "moveTo", x: 170, y: 160}, {type: "arc", x: 170, y: 160, r: 4.5},
{type: "moveTo", x: 170, y: 165}, {type: "arc", x: 170, y: 165} {type: "moveTo", x: 170, y: 165}, {type: "arc", x: 170, y: 165, r: 4.5}
]); ]);
}, },
@ -75,7 +75,7 @@ suite.addBatch({
geometries: [{type: "Point", coordinates: [0, 0]}] geometries: [{type: "Point", coordinates: [0, 0]}]
}); });
assert.deepEqual(testContext.buffer(), [ assert.deepEqual(testContext.buffer(), [
{type: "moveTo", x: 480, y: 250}, {type: "arc", x: 480, y: 250} {type: "moveTo", x: 480, y: 250}, {type: "arc", x: 480, y: 250, r: 4.5}
]); ]);
}, },
@ -85,7 +85,7 @@ suite.addBatch({
features: [{type: "Feature", geometry: {type: "Point", coordinates: [0, 0]}}] features: [{type: "Feature", geometry: {type: "Point", coordinates: [0, 0]}}]
}); });
assert.deepEqual(testContext.buffer(), [ assert.deepEqual(testContext.buffer(), [
{type: "moveTo", x: 480, y: 250}, {type: "arc", x: 480, y: 250} {type: "moveTo", x: 480, y: 250}, {type: "arc", x: 480, y: 250, r: 4.5}
]); ]);
}, },
@ -123,9 +123,20 @@ suite.addBatch({
assert.strictEqual(path.pointRadius(), 4.5); assert.strictEqual(path.pointRadius(), 4.5);
assert.strictEqual(path.pointRadius(radius).pointRadius(), radius); assert.strictEqual(path.pointRadius(radius).pointRadius(), radius);
}, },
"coerces a constant point radius to a number": function() { "coerces point radius to a number": {
"constant": function() {
var path = d3.geo.path(); var path = d3.geo.path();
assert.strictEqual(path.pointRadius("5").pointRadius(), 5); assert.strictEqual(path.pointRadius("6").pointRadius(), 6);
},
"function": function(path) {
var radius = path.pointRadius();
try {
path.pointRadius(function() { return "6"; })({type: "Point", coordinates: [0, 0]});
assert.strictEqual(testContext.buffer().filter(function(d) { return d.type === "arc"; })[0].r, 6);
} finally {
path.pointRadius(radius);
}
}
} }
}, },
@ -295,7 +306,7 @@ suite.addBatch({
coordinates: [-63, 18] coordinates: [-63, 18]
}); });
assert.deepEqual(testContext.buffer(), [ assert.deepEqual(testContext.buffer(), [
{type: "moveTo", x: 165, y: 160}, {type: "arc", x: 165, y: 160} {type: "moveTo", x: 165, y: 160}, {type: "arc", x: 165, y: 160, r: 4.5}
]); ]);
}, },
"MultiPoint": function(path) { "MultiPoint": function(path) {
@ -304,9 +315,9 @@ suite.addBatch({
coordinates: [[-63, 18], [-62, 18], [-62, 17]] coordinates: [[-63, 18], [-62, 18], [-62, 17]]
}); });
assert.deepEqual(testContext.buffer(), [ assert.deepEqual(testContext.buffer(), [
{type: "moveTo", x: 165, y: 160}, {type: "arc", x: 165, y: 160}, {type: "moveTo", x: 165, y: 160}, {type: "arc", x: 165, y: 160, r: 4.5},
{type: "moveTo", x: 170, y: 160}, {type: "arc", x: 170, y: 160}, {type: "moveTo", x: 170, y: 160}, {type: "arc", x: 170, y: 160, r: 4.5},
{type: "moveTo", x: 170, y: 165}, {type: "arc", x: 170, y: 165} {type: "moveTo", x: 170, y: 165}, {type: "arc", x: 170, y: 165, r: 4.5}
]); ]);
}, },
"Polygon": { "Polygon": {
@ -369,7 +380,7 @@ suite.addBatch({
"Point": { "Point": {
"visible": function(path) { "visible": function(path) {
path({type: "Point", coordinates: [0, 0]}); path({type: "Point", coordinates: [0, 0]});
assert.deepEqual(testContext.buffer(), [{type: "moveTo", x: 859, y: 187}, {type: "arc", x: 859, y: 187}]); assert.deepEqual(testContext.buffer(), [{type: "moveTo", x: 859, y: 187}, {type: "arc", x: 859, y: 187, r: 4.5}]);
}, },
"invisible": function(path) { "invisible": function(path) {
path({type: "Point", coordinates: [-180, 0]}); path({type: "Point", coordinates: [-180, 0]});
@ -378,7 +389,7 @@ suite.addBatch({
}, },
"MultiPoint": function(path) { "MultiPoint": function(path) {
path({type: "MultiPoint", coordinates: [[0, 0], [-180, 0]]}); path({type: "MultiPoint", coordinates: [[0, 0], [-180, 0]]});
assert.deepEqual(testContext.buffer(), [{type: "moveTo", x: 859, y: 187}, {type: "arc", x: 859, y: 187}]); assert.deepEqual(testContext.buffer(), [{type: "moveTo", x: 859, y: 187}, {type: "arc", x: 859, y: 187, r: 4.5}]);
} }
}, },
"rotate(-24, -175.5])": { "rotate(-24, -175.5])": {
@ -635,7 +646,7 @@ suite.addBatch({
"rotate([0, 0, 0])": { "rotate([0, 0, 0])": {
"longitudes wrap at ±180°": function(path) { "longitudes wrap at ±180°": function(path) {
path({type: "Point", coordinates: [180 + 1e-6, 0]}); path({type: "Point", coordinates: [180 + 1e-6, 0]});
assert.deepEqual(testContext.buffer(), [{type: "moveTo", x: -420, y: 250}, {type: "arc", x: -420, y: 250}]); assert.deepEqual(testContext.buffer(), [{type: "moveTo", x: -420, y: 250}, {type: "arc", x: -420, y: 250, r: 4.5}]);
} }
} }
} }
@ -644,7 +655,7 @@ suite.addBatch({
var testBuffer = []; var testBuffer = [];
var testContext = { var testContext = {
arc: function(x, y, r, ra, rb) { testBuffer.push({type: "arc", x: Math.round(x), y: Math.round(y)}); }, arc: function(x, y, r, a0, a1) { testBuffer.push({type: "arc", x: Math.round(x), y: Math.round(y), r: r}); },
moveTo: function(x, y) { testBuffer.push({type: "moveTo", x: Math.round(x), y: Math.round(y)}); }, moveTo: function(x, y) { testBuffer.push({type: "moveTo", x: Math.round(x), y: Math.round(y)}); },
lineTo: function(x, y) { testBuffer.push({type: "lineTo", x: Math.round(x), y: Math.round(y)}); }, lineTo: function(x, y) { testBuffer.push({type: "lineTo", x: Math.round(x), y: Math.round(y)}); },
closePath: function() { testBuffer.push({type: "closePath"}); }, closePath: function() { testBuffer.push({type: "closePath"}); },