mirror of
https://github.com/josdejong/mathjs.git
synced 2026-01-18 14:59:29 +00:00
27 lines
1.0 KiB
JavaScript
27 lines
1.0 KiB
JavaScript
// test setPowerset
|
|
const assert = require('assert')
|
|
const math = require('../../../src/main')
|
|
|
|
describe('setPowerset', function () {
|
|
it('should return the powerset of a set', function () {
|
|
assert.deepEqual(math.setPowerset([1, 2]), [[], [1], [2], [1, 2]])
|
|
assert.deepEqual(math.setPowerset([1, math.complex(2, 2)]),
|
|
[[], [math.complex(2, 2)], [1], [math.complex(2, 2), 1]])
|
|
assert.deepEqual(math.setPowerset([]), [])
|
|
})
|
|
|
|
it('should return the powerset of a multiset', function () {
|
|
assert.deepEqual(math.setPowerset([1, 1]), [[], [1], [1], [1, 1]])
|
|
})
|
|
|
|
it('should always return an array', function () {
|
|
assert.equal(math.typeof(math.setPowerset([1, 2, 3])), 'Array')
|
|
assert.equal(math.typeof(math.setPowerset(math.matrix([1, 2, 3]))), 'Array')
|
|
})
|
|
|
|
it('should throw an error in case of invalid number of arguments', function () {
|
|
assert.throws(function () { math.setPowerset() }, /TypeError: Too few arguments/)
|
|
assert.throws(function () { math.setPowerset([], []) }, /TypeError: Too many arguments/)
|
|
})
|
|
})
|