Skip to content

Commit cfe6490

Browse files
committed
Added tests for broadcastSizes
1 parent a804f9d commit cfe6490

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import assert from 'assert'
2+
import math from '../../../../src/defaultInstance.js'
3+
4+
describe('broadcastSizes', function () {
5+
it('should broadcast sizes', function () {
6+
assert.deepStrictEqual(math.broadcastSizes([2, 3]), [2, 3])
7+
assert.deepStrictEqual(math.broadcastSizes([3, 3], [3, 1]), [3, 3])
8+
assert.deepStrictEqual(math.broadcastSizes([2, 1], [1, 3]), [2, 3])
9+
assert.deepStrictEqual(math.broadcastSizes([5, 4, 3], [1, 4, 1]), [5, 4, 3])
10+
assert.deepStrictEqual(math.broadcastSizes([3], [2, 3]), [2, 3])
11+
assert.deepStrictEqual(math.broadcastSizes([1, 3], [2, 1]), [2, 3])
12+
})
13+
14+
it('should throw an error if sizes are not compatible', function () {
15+
assert.throws(function () { math.broadcastSizes([2, 3], [3, 2]) }, /Error: shape mismatch: /)
16+
assert.throws(function () { math.broadcastSizes([2, 3], [2, 3, 4]) }, /Error: shape mismatch: /)
17+
})
18+
19+
it('should broadcast sizes of mixed arrays and matrices', function () {
20+
assert.deepStrictEqual(math.broadcastSizes([3, 3], math.matrix([3, 1])), [3, 3])
21+
assert.deepStrictEqual(math.broadcastSizes(math.matrix([2, 1]), [1, 3]), [2, 3])
22+
assert.deepStrictEqual(math.broadcastSizes(math.matrix([5, 4, 3]), math.matrix([1, 4, 1])), [5, 4, 3])
23+
})
24+
})

0 commit comments

Comments
 (0)