mirror of
https://github.com/josdejong/mathjs.git
synced 2026-01-18 14:59:29 +00:00
* fix: #3597 added nullish type definitions (#3601) * chore: update HISTORY.md and AUTHORS * docs: describe that `setDistinct` sorts the elements (see #3602) * [Issue-3602] - fixing setDistinct order * Reverting formatting * fixing formatting * fixing test cases and logic --------- Co-authored-by: Ayomide Bamigbade <iamtryve@gmail.com> Co-authored-by: Jos de Jong <wjosdejong@gmail.com>
35 lines
1.4 KiB
JavaScript
35 lines
1.4 KiB
JavaScript
// test setDistinct
|
|
import assert from 'assert'
|
|
|
|
import math from '../../../../src/defaultInstance.js'
|
|
|
|
describe('setDistinct', function () {
|
|
it('should return the elements of a set', function () {
|
|
assert.deepStrictEqual(math.setDistinct([1, 2]), [1, 2])
|
|
assert.deepStrictEqual(math.setDistinct([]), [])
|
|
})
|
|
|
|
it('should return the elements of a set in insertion order', function () {
|
|
assert.deepStrictEqual(math.setDistinct([3, 1, 2, 1, 2]), [3, 1, 2])
|
|
assert.deepStrictEqual(math.setDistinct(['h', 'e', 'l', 'l', 'o']), ['h', 'e', 'l', 'o'])
|
|
})
|
|
|
|
it('should return the distinct elements of a multiset', function () {
|
|
assert.deepStrictEqual(math.setDistinct([1, 1, 2, 2]), [1, 2])
|
|
assert.deepStrictEqual(math.setDistinct([1, 2, 1, 2]), [1, 2])
|
|
assert.deepStrictEqual(math.setDistinct([1, 2, math.complex(3, 3), 2, math.complex(3, 3)]), [1, 2, math.complex(3, 3)])
|
|
})
|
|
|
|
it('should return the same type of output as the inputs', function () {
|
|
assert.strictEqual(math.typeOf(math.setDistinct([1, 2, 3])), 'Array')
|
|
assert.strictEqual(
|
|
math.typeOf(math.setDistinct(math.matrix([1, 2, 3]))),
|
|
'DenseMatrix')
|
|
})
|
|
|
|
it('should throw an error in case of invalid number of arguments', function () {
|
|
assert.throws(function () { math.setDistinct() }, /TypeError: Too few arguments/)
|
|
assert.throws(function () { math.setDistinct([], []) }, /TypeError: Too many arguments/)
|
|
})
|
|
})
|