mathjs/test/function/set/setDistinct.test.js
Nekomajin42 fc9018457f setops v4
- using sort() again
- update the tests with unsorted input
2017-06-06 11:50:50 +02:00

27 lines
1001 B
JavaScript

// test setDistinct
var assert = require('assert');
var math = require('../../../index');
describe('setDistinct', function () {
it('should return the elements of a set', function () {
assert.deepEqual(math.setDistinct([1, 2]), [1, 2]);
assert.deepEqual(math.setDistinct([]), []);
});
it('should return the distinct elements of a multiset', function () {
assert.deepEqual(math.setDistinct([1, 1, 2, 2]), [1, 2]);
assert.deepEqual(math.setDistinct([1, 2, 1, 2]), [1, 2]);
});
it('should return the same type of output as the inputs', function() {
assert.equal(math.typeof(math.setDistinct([1, 2, 3])), 'Array');
assert.equal(math.typeof(math.setDistinct(math.matrix([1, 2, 3]))), 'Matrix');
});
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/);
});
});