-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
test.js
45 lines (36 loc) · 1.38 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/*!
* arr-union <https://github.com/jonschlinkert/arr-union>
*
* Copyright (c) 2014-2015, Jon Schlinkert.
* Licensed under the MIT License.
*/
'use strict';
/* deps:mocha */
var path = require('path');
var argv = require('minimist')(process.argv.slice(2));
var should = require('should');
var union = require('./');
if (argv._.length) {
union = require(path.resolve('benchmark/code/' + argv.code + '.js'));
}
describe('union', function() {
it('should add elements to the original array:', function() {
var arr = ['a'];
union(arr, ['b', 'c'], ['a'], ['b', 'c'], ['d', 'e', 'f']).sort()
arr.should.eql(['a', 'b', 'c', 'd', 'e', 'f'].sort());
});
it('should union all elements in the given arrays:', function() {
union(['a'], ['b', 'c'], ['d', 'e', 'f']).sort().should.eql(['a', 'b', 'c', 'd', 'e', 'f'].sort());
});
it('should ignore falsey values', function() {
union(['a'], undefined, ['d', 'e', 'f']).sort().should.eql(['a', 'd', 'e', 'f'].sort());
});
it('should arrayify non-array values', function() {
union(['a'], 'cde', ['d', 'e', 'f']).sort().should.eql(['a', 'cde', 'd', 'e', 'f'].sort());
});
it('should uniquify elements from additional arrays:', function() {
var arr = ['a', 'b', 'c'];
var res = union(arr, ['b', 'c'], ['a'], ['b', 'c'], ['d', 'e', 'f']).sort()
res.should.eql(['a', 'b', 'c', 'd', 'e', 'f'].sort());
});
});