Skip to content
Browse files

add assert.xyzEqual()

  • Loading branch information...
1 parent 9bf1caf commit 475bc16021b4e528caf1898896e4889ad00f9cc4 @justincormack committed
Showing with 16 additions and 22 deletions.
  1. +1 −2 d3.v2.js
  2. +3 −3 d3.v2.min.js
  3. +1 −2 src/core/hsl.js
  4. +5 −15 test/core/xyz-test.js
  5. +6 −0 test/env-assert.js
View
3 d3.v2.js
@@ -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() {
View
6 d3.v2.min.js
3 additions, 3 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
View
3 src/core/hsl.js
@@ -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() {
View
20 test/core/xyz-test.js
@@ -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);
View
6 test/env-assert.js
@@ -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);

0 comments on commit 475bc16

Please sign in to comment.
Something went wrong with that request. Please try again.