mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-08 02:17:48 +00:00
Add more large array tests for sortedIndex methods.
This commit is contained in:
@@ -968,7 +968,8 @@
|
|||||||
|
|
||||||
/** Used as references for the max length and index of an array. */
|
/** Used as references for the max length and index of an array. */
|
||||||
var MAX_ARRAY_LENGTH = Math.pow(2, 32) - 1,
|
var MAX_ARRAY_LENGTH = Math.pow(2, 32) - 1,
|
||||||
MAX_ARRAY_INDEX = MAX_ARRAY_LENGTH - 1;
|
MAX_ARRAY_INDEX = MAX_ARRAY_LENGTH - 1,
|
||||||
|
HALF_MAX_ARRAY_LENGTH = MAX_ARRAY_LENGTH >>> 1;
|
||||||
|
|
||||||
/** Used as the size, in bytes, of each Float64Array element. */
|
/** Used as the size, in bytes, of each Float64Array element. */
|
||||||
var FLOAT64_BYTES_PER_ELEMENT = Float64Array ? Float64Array.BYTES_PER_ELEMENT : 0;
|
var FLOAT64_BYTES_PER_ELEMENT = Float64Array ? Float64Array.BYTES_PER_ELEMENT : 0;
|
||||||
@@ -2753,7 +2754,7 @@
|
|||||||
high = array ? array.length : low;
|
high = array ? array.length : low;
|
||||||
|
|
||||||
value = iteratee(value);
|
value = iteratee(value);
|
||||||
if (value !== value || typeof value == 'undefined' || high > (MAX_ARRAY_LENGTH / 2)) {
|
if (value !== value || typeof value == 'undefined' || high > HALF_MAX_ARRAY_LENGTH) {
|
||||||
return baseBinaryIndex(array, value, iteratee, retHighest);
|
return baseBinaryIndex(array, value, iteratee, retHighest);
|
||||||
}
|
}
|
||||||
while (low < high) {
|
while (low < high) {
|
||||||
|
|||||||
29
test/test.js
29
test/test.js
@@ -11151,22 +11151,23 @@
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
test('`_.' + methodName + '` should support arrays larger than `Math.pow(2, 31) - 1`', 2, function() {
|
test('`_.' + methodName + '` should support arrays larger than `MAX_ARRAY_LENGTH / 2`', 4, function() {
|
||||||
var array = [0],
|
_.each([Math.ceil(MAX_ARRAY_LENGTH / 2), MAX_ARRAY_LENGTH], function(length, index) {
|
||||||
length = MAX_ARRAY_LENGTH,
|
var array = [],
|
||||||
steps = 0;
|
steps = 0;
|
||||||
|
|
||||||
array.length = length;
|
array.length = length;
|
||||||
|
|
||||||
// Avoid false fails in older Firefox.
|
// Avoid false fails in older Firefox.
|
||||||
if (array.length == length) {
|
if (array.length == length) {
|
||||||
var actual = func(array, undefined, function() { steps++; });
|
var actual = func(array, undefined, function() { steps++; });
|
||||||
strictEqual(steps, 33);
|
strictEqual(steps, isSortedIndex ? 33 : (32 + index));
|
||||||
strictEqual(actual, isSortedIndex ? 0 : MAX_ARRAY_INDEX);
|
strictEqual(actual, isSortedIndex ? 0 : Math.min(length, MAX_ARRAY_INDEX));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
skipTest(2);
|
skipTest(2);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user