-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEx2-test.js
More file actions
83 lines (71 loc) · 2.42 KB
/
Ex2-test.js
File metadata and controls
83 lines (71 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
let expect = require("chai").expect;
//Arrange
function transpose(matrix) {
let tMatrix = [];
let maxCols = matrix.map(function(row) {return row.length;}).
reduce(function(prev, current) {
return Math.max(prev, current);
});
for (let i = 0; i < maxCols; i++) {
tMatrix.push([]);
}
for (let i = 0; i < matrix.length; i++) {
for (let j = 0; j < matrix[i].length; j++) {
tMatrix[j][i] = matrix[i][j];
}
}
return tMatrix;
}
describe("Symmetric matrices:", function() {
it("should transpose a 2x2 matrix", function() {
const matrix = [[1,2],[3,4]];
const transposed = [[1,3],[2,4]];
expect(transpose(matrix)).to.deep.equal(transposed);
});
it("should transpose a 3x3 matrix", function() {
const matrix = [[1,2,3],[3, 4, 5],[6, 7, 8]];
const transposed = [[1, 3, 6],[2, 4, 7],[3, 5, 8]];
expect(transpose(matrix)).to.deep.equal(transposed);
});
it("should transpose a 3x3 matrix", function() {
const matrix = [
[1, 2, 9],
[4, 5, 45],
[7, 6, 2]
];
const transposed = [
[1, 4, 7],
[2, 5, 6],
[9, 45, 2]
];
expect(transpose(matrix)).to.deep.equal(transposed);
});
});
describe("Assymetric matrices:", function() {
it("Should return the transpose matrix:", function() {
const matrix = [
[1, 2, 3],
[4, 5]
];
const transposed = [
[1, 4],
[2, 5],
[3]
];
expect(transpose(matrix)).to.deep.equal(transposed);
});
it("should return the transpose", function() {
const matrix = [
[1,2,3],
[4,5],
[6,7,8,9]
];
const transposed = [
[1,4,6],
[2,5,7],
[3, ,8],
[ , ,9]
];
expect(transpose(matrix)).to.deep.equal(transposed);
});
});