-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Expand file tree
/
Copy pathMatrixMultiplication.test.js
More file actions
71 lines (66 loc) · 1.34 KB
/
MatrixMultiplication.test.js
File metadata and controls
71 lines (66 loc) · 1.34 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
import { matrixMultiplication } from '../MatrixMultiplication'
test('matrixMultiplication([[1,2,3],[4,5,6]], [[7,8],[9,10],[11,12]]) => [[58,64],[139,154]]', () => {
const A = [
[1, 2, 3],
[4, 5, 6]
]
const B = [
[7, 8],
[9, 10],
[11, 12]
]
const res = matrixMultiplication(A, B)
expect(res).toEqual([
[58, 64],
[139, 154]
])
})
test('matrixMultiplication([[2,4],[3,4]], [[1,2],[1,3]]) => [[6,16],[7,18]]', () => {
const A = [
[2, 4],
[3, 4]
]
const B = [
[1, 2],
[1, 3]
]
const res = matrixMultiplication(A, B)
expect(res).toEqual([
[6, 16],
[7, 18]
])
})
test('matrixMultiplication([[1,2],[3,4]], [[5,6],[7,8]]) => [[19,22],[43,50]]', () => {
const A = [
[1, 2],
[3, 4]
]
const B = [
[5, 6],
[7, 8]
]
const res = matrixMultiplication(A, B)
expect(res).toEqual([
[19, 22],
[43, 50]
])
})
test('matrixMultiplication([[1]], [[2]]) => [[2]]', () => {
const A = [[1]]
const B = [[2]]
const res = matrixMultiplication(A, B)
expect(res).toEqual([[2]])
})
test('throws error when matrices cannot be multiplied', () => {
const A = [
[1, 2, 3],
[4, 5, 6]
]
const B = [
[1, 2],
[3, 4]
]
expect(() => matrixMultiplication(A, B)).toThrow(
'Matrix multiplication not possible: columns of A must equal rows of B'
)
})