Skip to content

Commit 02c2c18

Browse files
committed
Add tests for legacySubset
1 parent 251c8ad commit 02c2c18

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

test/unit-tests/core/config.test.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,27 @@ describe('config', function () {
5252
// Check if console.warn was called
5353
assert.strictEqual(warnStub.callCount, 1)
5454

55+
// Test legacy syntax for getting a subset of a matrix
56+
const A = math2.matrix([[1, 2, 3], [4, 5, 6]])
57+
const index = math2.index
58+
assert.deepStrictEqual(math2.subset(A, index(1, 2)), 6)
59+
assert.deepStrictEqual(math2.subset(A, index([1], 2)), 6)
60+
assert.deepStrictEqual(math2.subset(A, index(1, [2])), 6)
61+
assert.deepStrictEqual(math2.subset(A, index([1], [2])), 6)
62+
assert.deepStrictEqual(math2.subset(A, index(1, [1, 2])).toArray(), [[5, 6]])
63+
assert.deepStrictEqual(math2.subset(A, index([0, 1], 1)).toArray(), [[2], [5]])
64+
65+
// Test without legacy syntax
66+
math2.config({ legacySubset: false })
67+
assert.deepStrictEqual(math2.subset(A, index(1, 2)), 6)
68+
assert.deepStrictEqual(math2.subset(A, index([1], 2)).toArray(), [6])
69+
assert.deepStrictEqual(math2.subset(A, index(1, [2])).toArray(), [6])
70+
assert.deepStrictEqual(math2.subset(A, index([1], [2])).toArray(), [[6]])
71+
assert.deepStrictEqual(math2.subset(A, index(1, [1, 2])).toArray(), [5, 6])
72+
assert.deepStrictEqual(math2.subset(A, index([1], [1, 2])).toArray(), [[5, 6]])
73+
assert.deepStrictEqual(math2.subset(A, index([0, 1], 1)).toArray(), [2, 5])
74+
assert.deepStrictEqual(math2.subset(A, index([0, 1], [1])).toArray(), [[2], [5]])
75+
5576
// Restore console.warn
5677
warnStub.restore()
5778
})

0 commit comments

Comments
 (0)