Permalink
Browse files

Merge branch 'test'

  • Loading branch information...
2 parents ceb5f7c + a0e3e84 commit 41f769e36c1d5a93cf1b0f36a5d6a0e35ad1fc53 @mbostock mbostock committed Aug 16, 2011
View
6 d3.js
@@ -1,4 +1,4 @@
-(function(){d3 = {version: "1.29.2"}; // semver
+(function(){d3 = {version: "1.29.3"}; // semver
if (!Date.now) Date.now = function() {
return +new Date;
};
@@ -35,10 +35,10 @@ d3.rebind = function(object, method) {
};
};
d3.ascending = function(a, b) {
- return a < b ? -1 : a > b ? 1 : 0;
+ return a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;
};
d3.descending = function(a, b) {
- return b < a ? -1 : b > a ? 1 : 0;
+ return b < a ? -1 : b > a ? 1 : b >= a ? 0 : NaN;
};
d3.min = function(array, f) {
var i = -1,
View

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -1,3 +1,3 @@
d3.ascending = function(a, b) {
- return a < b ? -1 : a > b ? 1 : 0;
+ return a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;
};
View
@@ -1 +1 @@
-d3 = {version: "1.29.2"}; // semver
+d3 = {version: "1.29.3"}; // semver
View
@@ -1,3 +1,3 @@
d3.descending = function(a, b) {
- return b < a ? -1 : b > a ? 1 : 0;
+ return b < a ? -1 : b > a ? 1 : b >= a ? 0 : NaN;
};
@@ -16,6 +16,16 @@ suite.addBatch({
},
"returns zero if a == b": function() {
assert.equal(d3.ascending(0, 0), 0);
+ },
+ "returns NaN if a or b is undefined": function() {
+ assert.isNaN(d3.ascending(0, undefined));
+ assert.isNaN(d3.ascending(undefined, 0));
+ assert.isNaN(d3.ascending(undefined, undefined));
+ },
+ "returns NaN if a or b is NaN": function() {
+ assert.isNaN(d3.ascending(0, NaN));
+ assert.isNaN(d3.ascending(NaN, 0));
+ assert.isNaN(d3.ascending(NaN, NaN));
}
}
});
@@ -16,6 +16,16 @@ suite.addBatch({
},
"returns zero if a == b": function() {
assert.equal(d3.descending(0, 0), 0);
+ },
+ "returns NaN if a or b is undefined": function() {
+ assert.isNaN(d3.descending(0, undefined));
+ assert.isNaN(d3.descending(undefined, 0));
+ assert.isNaN(d3.descending(undefined, undefined));
+ },
+ "returns NaN if a or b is NaN": function() {
+ assert.isNaN(d3.descending(0, NaN));
+ assert.isNaN(d3.descending(NaN, 0));
+ assert.isNaN(d3.descending(NaN, NaN));
}
}
});
View
@@ -0,0 +1,42 @@
+require("../env");
+require("../../d3");
+
+var vows = require("vows"),
+ assert = require("assert");
+
+var suite = vows.describe("d3.first");
+
+suite.addBatch({
+ "first": {
+ topic: function() {
+ return d3.first;
+ },
+ "compares using natural order by default": function(first) {
+ assert.strictEqual(first([1, 0]), 0);
+ assert.strictEqual(first(["1", 0]), 0);
+ assert.strictEqual(first(["2", "10"]), "10");
+ assert.strictEqual(first(["2", NaN, "10"]), "10");
+ assert.strictEqual(first([2, NaN, 10]), 2);
+ },
+ "compares using optional comparator": function(first) {
+ var i = 0, aa, bb, o = new Object();
+ assert.strictEqual(first([1, o], function(a, b) { aa = a; bb = b; return ++i; }), o);
+ assert.strictEqual(aa, 1);
+ assert.strictEqual(bb, o);
+ assert.strictEqual(first([1, 0], d3.descending), 1);
+ assert.strictEqual(first(["1", 0], d3.descending), "1");
+ assert.strictEqual(first(["2", "10"], d3.descending), "2");
+ assert.strictEqual(first(["2", NaN, "10"], d3.descending), "2");
+ assert.strictEqual(first([2, NaN, 10], d3.descending), 10);
+ },
+ "returns the first of equal values": function(last) {
+ var a = new Object(), b = new Object(), c = new Object();
+ assert.strictEqual(last([a, b, c], function() { return 0; }), a);
+ },
+ "returns undefined for an empty array": function(first) {
+ assert.isUndefined(first([]));
+ }
+ }
+});
+
+suite.export(module);
View
@@ -0,0 +1,29 @@
+require("../env");
+require("../../d3");
+
+var vows = require("vows"),
+ assert = require("assert");
+
+var suite = vows.describe("d3.functor");
+
+suite.addBatch({
+ "functor": {
+ topic: function() {
+ return d3.functor;
+ },
+ "when passed a function, returns the function": function(functor) {
+ function foo() {}
+ assert.strictEqual(functor(foo), foo);
+ },
+ "when passed a non-function, returns a wrapper function": function(functor) {
+ var a = {};
+ assert.isNull(functor(null)());
+ assert.isUndefined(functor(undefined)());
+ assert.strictEqual(functor(a)(), a);
+ assert.strictEqual(functor(1)(), 1);
+ assert.deepEqual(functor([1])(), [1]);
+ }
+ }
+});
+
+suite.export(module);
View
@@ -0,0 +1,42 @@
+require("../env");
+require("../../d3");
+
+var vows = require("vows"),
+ assert = require("assert");
+
+var suite = vows.describe("d3.last");
+
+suite.addBatch({
+ "last": {
+ topic: function() {
+ return d3.last;
+ },
+ "compares using natural order by default": function(last) {
+ assert.strictEqual(last([1, 0]), 1);
+ assert.strictEqual(last(["1", 0]), "1");
+ assert.strictEqual(last(["2", "10"]), "2");
+ assert.strictEqual(last(["2", NaN, "10"]), "2");
+ assert.strictEqual(last([2, NaN, 10]), 10);
+ },
+ "compares using optional comparator": function(last) {
+ var i = 0, aa, bb, o = new Object();
+ assert.strictEqual(last([1, o], function(a, b) { aa = a; bb = b; return ++i; }), 1);
+ assert.strictEqual(aa, 1);
+ assert.strictEqual(bb, o);
+ assert.strictEqual(last([1, 0], d3.descending), 0);
+ assert.strictEqual(last(["1", 0], d3.descending), 0);
+ assert.strictEqual(last(["2", "10"], d3.descending), "10");
+ assert.strictEqual(last(["2", NaN, "10"], d3.descending), "10");
+ assert.strictEqual(last([2, NaN, 10], d3.descending), 2);
+ },
+ "returns the last of equal values": function(last) {
+ var a = new Object(), b = new Object(), c = new Object();
+ assert.strictEqual(last([a, b, c], function() { return 0; }), c);
+ },
+ "returns undefined for an empty array": function(last) {
+ assert.isUndefined(last([]));
+ }
+ }
+});
+
+suite.export(module);
View
@@ -0,0 +1,27 @@
+require("../env");
+require("../../d3");
+
+var vows = require("vows"),
+ assert = require("assert");
+
+var suite = vows.describe("d3.merge");
+
+suite.addBatch({
+ "merge": {
+ "merges an array of arrays": function() {
+ var a = {}, b = {}, c = {}, d = {}, e = {}, f = {};
+ assert.deepEqual(d3.merge([[a], [b, c], [d, e, f]]), [a, b, c, d, e, f]);
+ },
+ "returns a new array": function() {
+ var input = [[1, 2, 3], [4, 5], [6]];
+ assert.isFalse(d3.merge(input) === input);
+ },
+ "does not modify the input arrays": function() {
+ var input = [[1, 2, 3], [4, 5], [6]];
+ d3.merge(input);
+ assert.deepEqual(input, [[1, 2, 3], [4, 5], [6]]);
+ }
+ }
+});
+
+suite.export(module);
View
@@ -0,0 +1,38 @@
+require("../env");
+require("../../d3");
+
+var vows = require("vows"),
+ assert = require("assert");
+
+var suite = vows.describe("d3.rebind");
+
+suite.addBatch({
+ "rebind": {
+ topic: function() {
+ return d3.rebind;
+ },
+ "bound function uses object as context": function(rebind) {
+ var a = {}, that, f = rebind(a, function() { that = this; });
+ assert.strictEqual((f(), that), a);
+ assert.strictEqual((f.call({}), that), a);
+ },
+ "bound function receives any arguments": function(rebind) {
+ var a = [], b = {}, f = rebind(a, function() { a = Array.prototype.slice.call(arguments); });
+ assert.deepEqual((f(), a), []);
+ assert.deepEqual((f(1), a), [1]);
+ assert.deepEqual((f(null), a), [null]);
+ assert.deepEqual((f(b, b, 1), a), [b, b, 1]);
+ },
+ "bound function returns object if arguments": function(rebind) {
+ var a = {}, f = rebind(a, function() {});
+ assert.strictEqual(f(1), a);
+ assert.strictEqual(f(1, 2, 3), a);
+ },
+ "bound function returns return value if no arguments": function(rebind) {
+ var a = {}, f = rebind({}, function() { return a; });
+ assert.strictEqual(f(), a);
+ }
+ }
+});
+
+suite.export(module);
View
@@ -0,0 +1,34 @@
+require("../env");
+require("../../d3");
+
+var vows = require("vows"),
+ assert = require("assert");
+
+var suite = vows.describe("d3.split");
+
+suite.addBatch({
+ "split": {
+ topic: function() {
+ return d3.split;
+ },
+ "splits an array into arrays": function(split) {
+ var a = {}, b = {}, c = {}, d = {}, e = {}, f = {};
+ assert.deepEqual(d3.split([a, null, b, c, undefined, d, e, f]), [[a], [b, c], [d, e, f]]);
+ },
+ "splits using the specified function": function(split) {
+ assert.deepEqual(d3.split([1, 0, 2, 3, -1, 4, 5, 6], function(d) { return d <= 0; }), [[1], [2, 3], [4, 5, 6]]);
+ assert.deepEqual(d3.split([1, 0, 2, 3, -1, 4, 5, 6], function(d, i) { return i & 1; }), [[1], [2], [-1], [5]]);
+ },
+ "ignores delimiters at the start or end": function(split) {
+ var a = {}, b = {}, c = {};
+ assert.deepEqual(d3.split([null, a, b, null, c]), [[a, b], [c]]);
+ assert.deepEqual(d3.split([a, b, null, c, null]), [[a, b], [c]]);
+ assert.deepEqual(d3.split([null, a, b, null, c, null]), [[a, b], [c]]);
+ assert.deepEqual(d3.split([undefined, a, b, undefined, c]), [[a, b], [c]]);
+ assert.deepEqual(d3.split([a, b, undefined, c, undefined]), [[a, b], [c]]);
+ assert.deepEqual(d3.split([undefined, a, b, undefined, c, undefined]), [[a, b], [c]]);
+ }
+ }
+});
+
+suite.export(module);

0 comments on commit 41f769e

Please sign in to comment.