-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.mjs
More file actions
40 lines (35 loc) · 782 Bytes
/
Copy pathtest.mjs
File metadata and controls
40 lines (35 loc) · 782 Bytes
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
import assert from 'node:assert/strict'
import test from 'node:test'
import addon from './index.cjs'
test('multiplies two matrices', () => {
const a = [
[1, 2],
[3, 4],
]
const b = [
[5, 6],
[7, 8],
]
assert.deepEqual(addon.multiply(a, b), [
[19, 22],
[43, 50],
])
})
test('identity leaves a matrix alone', () => {
const a = [
[1, 2, 3],
[4, 5, 6],
]
const identity = [
[1, 0, 0],
[0, 1, 0],
[0, 0, 1],
]
assert.deepEqual(addon.multiply(a, identity), a)
})
test('a C++ exception arrives as a JS error', () => {
assert.throws(() => addon.multiply([[1, 2]], [[1, 2]]), /shapes do not line up/)
})
test('bad input is rejected with a TypeError', () => {
assert.throws(() => addon.multiply(42, 7), TypeError)
})