Files
lodash/test/partition.js
Benjamin Tan d5ef31929a Add initial test files from lodash v4. (#4172)
* Install test dependencies.

* Add initial test files.

These files were created using a simplistic AST manipulator using `recast` to
preserve formatting. There's bound to be a huge chunk of errors, but this serves
as a good start. QUnit was replaced with Mocha, with ES2015 imports running via
`esm`.

As far as possible, QUnit-specific syntax has been replaced with Mocha's
`describe` and `it`, while the native Node.js `assert` module is used for
assertions. Files in the `test` directory ending in `.test.js` will be treated
as test files.

* Add initial passing files to test run.
2019-02-12 09:11:32 -08:00

49 lines
1.6 KiB
JavaScript

import assert from 'assert';
import lodashStable from 'lodash';
import { identity, stubTrue, stubFalse } from './utils.js';
import partition from '../partition.js';
describe('partition', function() {
var array = [1, 0, 1];
it('should split elements into two groups by `predicate`', function() {
assert.deepStrictEqual(partition([], identity), [[], []]);
assert.deepStrictEqual(partition(array, stubTrue), [array, []]);
assert.deepStrictEqual(partition(array, stubFalse), [[], array]);
});
it('should use `_.identity` when `predicate` is nullish', function() {
var values = [, null, undefined],
expected = lodashStable.map(values, lodashStable.constant([[1, 1], [0]]));
var actual = lodashStable.map(values, function(value, index) {
return index ? partition(array, value) : partition(array);
});
assert.deepStrictEqual(actual, expected);
});
it('should work with `_.property` shorthands', function() {
var objects = [{ 'a': 1 }, { 'a': 1 }, { 'b': 2 }],
actual = partition(objects, 'a');
assert.deepStrictEqual(actual, [objects.slice(0, 2), objects.slice(2)]);
});
it('should work with a number for `predicate`', function() {
var array = [
[1, 0],
[0, 1],
[1, 0]
];
assert.deepStrictEqual(partition(array, 0), [[array[0], array[2]], [array[1]]]);
assert.deepStrictEqual(partition(array, 1), [[array[1]], [array[0], array[2]]]);
});
it('should work with an object for `collection`', function() {
var actual = partition({ 'a': 1.1, 'b': 0.2, 'c': 1.3 }, Math.floor);
assert.deepStrictEqual(actual, [[1.1, 1.3], [0.2]]);
});
});