Skip to content

Commit

Permalink
add assert.xyzEqual()
Browse files Browse the repository at this point in the history
  • Loading branch information
justincormack committed Mar 2, 2012
1 parent 9bf1caf commit 475bc16
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 22 deletions.
3 changes: 1 addition & 2 deletions d3.v2.js
Expand Up @@ -1480,8 +1480,7 @@ d3_Hsl.prototype.rgb = function() {
};

d3_Hsl.prototype.xyz = function() {
var rgb = this.rgb()
return d3_rgb_xyz(rgb.r, rgb.g, rgb.b);
return this.rgb().xyz();
};

d3_Hsl.prototype.toString = function() {
Expand Down
6 changes: 3 additions & 3 deletions d3.v2.min.js

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions src/core/hsl.js
Expand Up @@ -30,8 +30,7 @@ d3_Hsl.prototype.rgb = function() {
};

d3_Hsl.prototype.xyz = function() {
var rgb = this.rgb()
return d3_rgb_xyz(rgb.r, rgb.g, rgb.b);
return this.rgb().xyz();
};

d3_Hsl.prototype.toString = function() {
Expand Down
20 changes: 5 additions & 15 deletions test/core/xyz-test.js
Expand Up @@ -12,33 +12,23 @@ suite.addBatch({
},
"exposes x, y and z properties": function(xyz) {
var color = xyz("#abc");
assert.equal(color.x, 45.246971009995335);
assert.equal(color.y, 48.44632879252148);
assert.equal(color.z, 64.09304697440157);
assert.xyzEqual(color, 45.246971009995335, 48.44632879252148, 64.09304697440157);
},
"can convert from XYZ": function(xyz) {
var color = xyz(d3.xyz(40, 50, 60));
assert.equal(color.x, 40);
assert.equal(color.y, 50);
assert.equal(color.z, 60);
assert.xyzEqual(color, 40, 50, 60);
},
"can convert from RGB": function(xyz) {
var color = d3.rgb("#abc").xyz();
assert.equal(color.x, 45.246971009995335);
assert.equal(color.y, 48.44632879252148);
assert.equal(color.z, 64.09304697440157);
assert.xyzEqual(color, 45.246971009995335, 48.44632879252148, 64.09304697440157);
},
"can convert from HSL": function(xyz) {
var color = d3.hsl("#abc").xyz();
assert.equal(color.x, 45.246971009995335);
assert.equal(color.y, 48.44632879252148);
assert.equal(color.z, 64.09304697440157);
assert.xyzEqual(color, 45.246971009995335, 48.44632879252148, 64.09304697440157);
},
"can initialize with RGB": function(xyz) {
var color = xyz(d3.rgb(30, 40, 50));
assert.equal(color.x, 1.8699354618049604);
assert.equal(color.y, 2.0238922484735156);
assert.equal(color.z, 3.309705799692103);
assert.xyzEqual(color, 1.8699354618049604, 2.0238922484735156, 3.309705799692103);
},
"can convert to RGB": function(xyz) {
assert.rgbEqual(xyz(d3.rgb(30, 40, 50)).rgb(), 30, 40, 50);
Expand Down
6 changes: 6 additions & 0 deletions test/env-assert.js
Expand Up @@ -30,6 +30,12 @@ assert.hslEqual = function(actual, h, s, l, message) {
}
};

assert.xyzEqual = function(actual, x, y, z, message) {
if (Math.abs(actual.x - x) > 1e-6 || Math.abs(actual.y - y) > 1e-6 || Math.abs(actual.z - z) > 1e-6) {
assert.fail("xyz(" + actual.x + "," + actual.y + "," + actual.z + ")", "xyz(" + x + "," + y + "," + z + ")", message || "expected {expected}, got {actual}", null, assert.xyzEqual);
}
};

assert.pathEqual = function(actual, expected, message) {
if (!pathEqual(actual, expected)) {
assert.fail(formatPath(actual), formatPath(expected), message || "expected {expected}, got {actual}", null, assert.pathEqual);
Expand Down

0 comments on commit 475bc16

Please sign in to comment.