Skip to content

Commit 4315651

Browse files
committed
Added test for broadcastTo
1 parent b212e6f commit 4315651

File tree

2 files changed

+36
-11
lines changed

2 files changed

+36
-11
lines changed

test/unit-tests/function/matrix/broadcastSizes.test.js

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,26 @@ import assert from 'assert'
22
import math from '../../../../src/defaultInstance.js'
33

44
describe('broadcastSizes', function () {
5+
const broadcastSizes = math.broadcastSizes
6+
const matrix = math.matrix
7+
58
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])
9+
assert.deepStrictEqual(broadcastSizes([2, 3]), [2, 3])
10+
assert.deepStrictEqual(broadcastSizes([3, 3], [3, 1]), [3, 3])
11+
assert.deepStrictEqual(broadcastSizes([2, 1], [1, 3]), [2, 3])
12+
assert.deepStrictEqual(broadcastSizes([5, 4, 3], [1, 4, 1]), [5, 4, 3])
13+
assert.deepStrictEqual(broadcastSizes([3], [2, 3]), [2, 3])
14+
assert.deepStrictEqual(broadcastSizes([1, 3], [2, 1]), [2, 3])
1215
})
1316

1417
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: /)
18+
assert.throws(function () { broadcastSizes([2, 3], [3, 2]) }, /Error: shape mismatch: /)
19+
assert.throws(function () { broadcastSizes([2, 3], [2, 3, 4]) }, /Error: shape mismatch: /)
1720
})
1821

1922
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+
assert.deepStrictEqual(broadcastSizes([3, 3], matrix([3, 1])), [3, 3])
24+
assert.deepStrictEqual(broadcastSizes(matrix([2, 1]), [1, 3]), [2, 3])
25+
assert.deepStrictEqual(broadcastSizes(matrix([5, 4, 3]), matrix([1, 4, 1])), [5, 4, 3])
2326
})
2427
})
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import assert from 'assert'
2+
import math from '../../../../src/defaultInstance.js'
3+
4+
describe('broadcastTo', function () {
5+
const broadcastTo = math.broadcastTo
6+
const matrix = math.matrix
7+
8+
it('should broadcast arrays to a given size', function () {
9+
assert.deepStrictEqual(broadcastTo([1, 2, 3], [2, 3]), [[1, 2, 3], [1, 2, 3]])
10+
assert.deepStrictEqual(broadcastTo([2, 3], [2, 2]), [[2, 3], [2, 3]])
11+
})
12+
13+
it('should broadcast matrices to a given size', function () {
14+
assert.deepStrictEqual(broadcastTo(matrix([1, 2, 3]), [2, 3]), matrix([[1, 2, 3], [1, 2, 3]]))
15+
assert.deepStrictEqual(broadcastTo(matrix([2, 3]), [2, 2]), matrix([[2, 3], [2, 3]]))
16+
})
17+
18+
it('should throw an error if sizes are not compatible', function () {
19+
assert.throws(function () { broadcastTo([1, 2], [2, 3]) }, /Error: shape mismatch: /)
20+
assert.throws(function () { broadcastTo(matrix([1, 2]), [2, 3]) }, /Error: shape mismatch: /)
21+
})
22+
})

0 commit comments

Comments
 (0)