-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
41 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
d3.transpose = function(matrix) { | ||
return d3.zip.apply(d3, matrix); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
require("../env"); | ||
require("../../d3"); | ||
|
||
var vows = require("vows"), | ||
assert = require("assert"); | ||
|
||
var suite = vows.describe("d3.transpose"); | ||
|
||
suite.addBatch({ | ||
"transpose": { | ||
topic: function() { | ||
return d3.transpose; | ||
}, | ||
"transposes a square matrix": function(transpose) { | ||
assert.deepEqual(d3.transpose([[1, 2], [3, 4]]), [[1, 3], [2, 4]]); | ||
}, | ||
"transposes a non-square matrix": function(transpose) { | ||
assert.deepEqual(d3.transpose([[1, 2, 3, 4, 5], [2, 4, 6, 8, 10]]), [[1, 2], [2, 4], [3, 6], [4, 8], [5, 10]]); | ||
}, | ||
"transposes a single-row matrix": function(transpose) { | ||
assert.deepEqual(d3.transpose([[1, 2, 3, 4, 5]]), [[1], [2], [3], [4], [5]]); | ||
}, | ||
"transposes an empty matrix": function(transpose) { | ||
assert.deepEqual(d3.transpose([]), []); | ||
}, | ||
"ignores extra elements given an irregular matrix": function(transpose) { | ||
assert.deepEqual(d3.transpose([[1, 2], [3, 4], [5, 6, 7]]), [[1, 3, 5], [2, 4, 6]]); | ||
} | ||
} | ||
}); | ||
|
||
suite.export(module); |