mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-03 00:27:50 +00:00
Only avoid converting -0 to 0 if comparator is provided.
This commit is contained in:
76
test/test.js
76
test/test.js
@@ -4723,16 +4723,18 @@
|
||||
});
|
||||
|
||||
QUnit.test('`_.' + methodName + '` should treat `-0` as `0`', function(assert) {
|
||||
assert.expect(1);
|
||||
assert.expect(2);
|
||||
|
||||
var values = [-0, 0],
|
||||
expected = lodashStable.map(values, alwaysEmptyArray);
|
||||
var array = [-0, 0];
|
||||
|
||||
var actual = lodashStable.map(values, function(value) {
|
||||
return func(values, [value]);
|
||||
var actual = lodashStable.map(array, function(value) {
|
||||
return func(array, [value]);
|
||||
});
|
||||
|
||||
assert.deepEqual(actual, expected);
|
||||
assert.deepEqual(actual, [[], []]);
|
||||
|
||||
actual = lodashStable.map(func([-0, 1], [1]), lodashStable.toString);
|
||||
assert.deepEqual(actual, ['0']);
|
||||
});
|
||||
|
||||
QUnit.test('`_.' + methodName + '` should match `NaN`', function(assert) {
|
||||
@@ -4757,17 +4759,20 @@
|
||||
});
|
||||
|
||||
QUnit.test('`_.' + methodName + '` should work with large arrays of `-0` as `0`', function(assert) {
|
||||
assert.expect(1);
|
||||
assert.expect(2);
|
||||
|
||||
var values = [-0, 0],
|
||||
expected = lodashStable.map(values, alwaysEmptyArray);
|
||||
var array = [-0, 0];
|
||||
|
||||
var actual = lodashStable.map(values, function(value) {
|
||||
var actual = lodashStable.map(array, function(value) {
|
||||
var largeArray = lodashStable.times(LARGE_ARRAY_SIZE, lodashStable.constant(value));
|
||||
return func(values, largeArray);
|
||||
return func(array, largeArray);
|
||||
});
|
||||
|
||||
assert.deepEqual(actual, expected);
|
||||
assert.deepEqual(actual, [[], []]);
|
||||
|
||||
var largeArray = lodashStable.times(LARGE_ARRAY_SIZE, alwaysOne);
|
||||
actual = lodashStable.map(func([-0, 1], largeArray), lodashStable.toString);
|
||||
assert.deepEqual(actual, ['0']);
|
||||
});
|
||||
|
||||
QUnit.test('`_.' + methodName + '` should work with large arrays of `NaN`', function(assert) {
|
||||
@@ -4839,6 +4844,21 @@
|
||||
|
||||
assert.deepEqual(actual, [objects[1]]);
|
||||
});
|
||||
|
||||
QUnit.test('should preserve the sign of `0`', function(assert) {
|
||||
assert.expect(1);
|
||||
|
||||
var array = [-0, 1],
|
||||
largeArray = lodashStable.times(LARGE_ARRAY_SIZE, alwaysOne),
|
||||
others = [[1], largeArray],
|
||||
expected = lodashStable.map(others, lodashStable.constant(['-0']));
|
||||
|
||||
var actual = lodashStable.map(others, function(other) {
|
||||
return lodashStable.map(_.differenceWith(array, other, lodashStable.eq), lodashStable.toString);
|
||||
});
|
||||
|
||||
assert.deepEqual(actual, expected);
|
||||
});
|
||||
}());
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
@@ -8087,6 +8107,21 @@
|
||||
|
||||
assert.deepEqual(actual, [objects[0]]);
|
||||
});
|
||||
|
||||
QUnit.test('should preserve the sign of `0`', function(assert) {
|
||||
assert.expect(1);
|
||||
|
||||
var array = [-0],
|
||||
largeArray = lodashStable.times(LARGE_ARRAY_SIZE, alwaysZero),
|
||||
others = [[0], largeArray],
|
||||
expected = lodashStable.map(others, lodashStable.constant(['-0']));
|
||||
|
||||
var actual = lodashStable.map(others, function(other) {
|
||||
return lodashStable.map(_.intersectionWith(array, other, lodashStable.eq), lodashStable.toString);
|
||||
});
|
||||
|
||||
assert.deepEqual(actual, expected);
|
||||
});
|
||||
}());
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
@@ -24078,6 +24113,23 @@
|
||||
|
||||
assert.deepEqual(actual, [objects[0], objects[1]]);
|
||||
});
|
||||
|
||||
QUnit.test('should preserve the sign of `0`', function(assert) {
|
||||
assert.expect(1);
|
||||
|
||||
var largeArray = lodashStable.times(LARGE_ARRAY_SIZE, function(index) {
|
||||
return isEven(index) ? -0 : 0;
|
||||
});
|
||||
|
||||
var arrays = [[-0, 0], largeArray],
|
||||
expected = lodashStable.map(arrays, lodashStable.constant(['-0']));
|
||||
|
||||
var actual = lodashStable.map(arrays, function(array) {
|
||||
return lodashStable.map(_.uniqWith(array, lodashStable.eq), lodashStable.toString);
|
||||
});
|
||||
|
||||
assert.deepEqual(actual, expected);
|
||||
});
|
||||
}());
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
Reference in New Issue
Block a user