diff --git a/test/test.js b/test/test.js index e384bbe15..666c257b0 100644 --- a/test/test.js +++ b/test/test.js @@ -2161,10 +2161,10 @@ test('should work in a lazy chain sequence', 1, function() { if (!isNpm) { - var array = [1, null, 3], - actual = _(array).map(square).compact().reverse().take().value(); + var array = _.range(0, LARGE_ARRAY_SIZE).concat(null), + actual = _(array).slice(1).compact().reverse().take().value(); - deepEqual(actual, [9]); + deepEqual(actual, _.take(_.compact(_.slice(array, 1)).reverse())); } else { skipTest(); @@ -2408,11 +2408,15 @@ test('should work in a lazy chain sequence', 1, function() { if (!isNpm) { - var array = [1, 2, 1, 3], - predicate = function(value) { return value > 2; }, - actual = _(array).countBy(_.identity).map(square).filter(predicate).take().value(); + var array = _.range(LARGE_ARRAY_SIZE).concat( + _.range(Math.floor(LARGE_ARRAY_SIZE / 2), LARGE_ARRAY_SIZE), + _.range(Math.floor(LARGE_ARRAY_SIZE / 1.5), LARGE_ARRAY_SIZE) + ); - deepEqual(actual, [4]); + var predicate = function(value) { return value > 2; }, + actual = _(array).countBy().map(square).filter(predicate).take().value(); + + deepEqual(actual, _.take(_.filter(_.map(_.countBy(array), square), predicate))); } else { skipTest(); @@ -3862,25 +3866,25 @@ test('should work in a lazy chain sequence', 6, function() { if (!isNpm) { - var array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], + var array = _.range(1, LARGE_ARRAY_SIZE + 1), values = [], predicate = function(value) { values.push(value); return value > 2; }, actual = _(array).drop(2).drop().value(); - deepEqual(actual, [4, 5, 6, 7, 8, 9, 10]); + deepEqual(actual, array.slice(3)); actual = _(array).filter(predicate).drop(2).drop().value(); - deepEqual(actual, [6, 7, 8, 9, 10]); deepEqual(values, array); + deepEqual(actual, _.drop(_.drop(_.filter(array, predicate), 2))); actual = _(array).drop(2).dropRight().drop().dropRight(2).value(); - deepEqual(actual, [4, 5, 6, 7]); + deepEqual(actual, _.dropRight(_.drop(_.dropRight(_.drop(array, 2))), 2)); values = []; actual = _(array).drop().filter(predicate).drop(2).dropRight().drop().dropRight(2).value(); - deepEqual(actual, [6, 7]); deepEqual(values, array.slice(1)); + deepEqual(actual, _.dropRight(_.drop(_.dropRight(_.drop(_.filter(_.drop(array), predicate), 2))), 2)); } else { skipTest(6); @@ -3932,25 +3936,25 @@ test('should work in a lazy chain sequence', 6, function() { if (!isNpm) { - var array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], + var array = _.range(1, LARGE_ARRAY_SIZE + 1), values = [], predicate = function(value) { values.push(value); return value < 9; }, actual = _(array).dropRight(2).dropRight().value(); - deepEqual(actual, [1, 2, 3, 4, 5, 6, 7]); + deepEqual(actual, array.slice(0, -3)); actual = _(array).filter(predicate).dropRight(2).dropRight().value(); - deepEqual(actual, [1, 2, 3, 4, 5]); deepEqual(values, array); + deepEqual(actual, _.dropRight(_.dropRight(_.filter(array, predicate), 2))); actual = _(array).dropRight(2).drop().dropRight().drop(2).value(); - deepEqual(actual, [4, 5, 6, 7]); + deepEqual(actual, _.drop(_.dropRight(_.drop(_.dropRight(array, 2))), 2)); values = []; actual = _(array).dropRight().filter(predicate).dropRight(2).drop().dropRight().drop(2).value(); - deepEqual(actual, [4, 5]); deepEqual(values, array.slice(0, -1)); + deepEqual(actual, _.drop(_.dropRight(_.drop(_.dropRight(_.filter(_.dropRight(array), predicate), 2))), 2)); } else { skipTest(6); @@ -4022,46 +4026,6 @@ skipTest(2); } }); - - test('should provide the correct `predicate` arguments in a lazy chain sequence', 5, function() { - if (!isNpm) { - var args, - expected = [16, 3, [1, 4, 9 ,16]]; - - _(array).dropRightWhile(function(value, index, array) { - args = slice.call(arguments); - }).value(); - - deepEqual(args, [4, 3, array]); - - _(array).map(square).dropRightWhile(function(value, index, array) { - args = slice.call(arguments); - }).value(); - - deepEqual(args, expected); - - _(array).map(square).dropRightWhile(function(value, index) { - args = slice.call(arguments); - }).value(); - - deepEqual(args, expected); - - _(array).map(square).dropRightWhile(function(value) { - args = slice.call(arguments); - }).value(); - - deepEqual(args, expected); - - _(array).map(square).dropRightWhile(function() { - args = slice.call(arguments); - }).value(); - - deepEqual(args, expected); - } - else { - skipTest(5); - } - }); }()); /*--------------------------------------------------------------------------*/ @@ -4117,13 +4081,14 @@ test('should work in a lazy chain sequence', 3, function() { if (!isNpm) { - var wrapped = _(array).dropWhile(function(num) { - return num < 3; - }); + var array = _.range(1, LARGE_ARRAY_SIZE + 3), + predicate = function(num) { return num < 3; }, + expected = _.dropWhile(array, predicate), + wrapped = _(array).dropWhile(predicate); - deepEqual(wrapped.value(), [3, 4]); - deepEqual(wrapped.reverse().value(), [4, 3]); - strictEqual(wrapped.last(), 4); + deepEqual(wrapped.value(), expected); + deepEqual(wrapped.reverse().value(), expected.slice().reverse()); + strictEqual(wrapped.last(), _.last(expected)); } else { skipTest(3); @@ -4132,58 +4097,20 @@ test('should work in a lazy chain sequence with `drop`', 1, function() { if (!isNpm) { + var array = _.range(1, LARGE_ARRAY_SIZE + 3); + var actual = _(array) .dropWhile(function(num) { return num == 1; }) .drop() .dropWhile(function(num) { return num == 3; }) .value(); - deepEqual(actual, [4]); + deepEqual(actual, array.slice(3)); } else { skipTest(); } }); - - test('should provide the correct `predicate` arguments in a lazy chain sequence', 5, function() { - if (!isNpm) { - var args, - expected = [1, 0, [1, 4, 9, 16]]; - - _(array).dropWhile(function(value, index, array) { - args = slice.call(arguments); - }).value(); - - deepEqual(args, [1, 0, array]); - - _(array).map(square).dropWhile(function(value, index, array) { - args = slice.call(arguments); - }).value(); - - deepEqual(args, expected); - - _(array).map(square).dropWhile(function(value, index) { - args = slice.call(arguments); - }).value(); - - deepEqual(args, expected); - - _(array).map(square).dropWhile(function(index) { - args = slice.call(arguments); - }).value(); - - deepEqual(args, [1]); - - _(array).map(square).dropWhile(function() { - args = slice.call(arguments); - }).value(); - - deepEqual(args, expected); - } - else { - skipTest(5); - } - }); }()); /*--------------------------------------------------------------------------*/ @@ -4756,7 +4683,7 @@ test('should work in a lazy chain sequence', 1, function() { if (!isNpm) { - var array = [1, 2, 3, 4]; + var array = _.range(1, LARGE_ARRAY_SIZE + 1); var wrapped = _(array).filter(function(value) { return value % 2 == 0; @@ -4818,25 +4745,25 @@ test('should work in a lazy chain sequence', 6, function() { if (!isNpm) { - var array = [1, 2, 3, 4, 5, 6, 7, 8, 9 , 10], + var array = _.range(1, LARGE_ARRAY_SIZE + 1), values = [], predicate = function(value) { values.push(value); return value > 2; }, actual = _(array).take(2).take().value(); - deepEqual(actual, [1]); + deepEqual(actual, _.take(_.take(array, 2))); actual = _(array).filter(predicate).take(2).take().value(); - deepEqual(actual, [3]); - deepEqual(values, array.slice(0, 3)); + deepEqual(values, [1, 2, 3]); + deepEqual(actual, _.take(_.take(_.filter(array, predicate), 2))); actual = _(array).take(6).takeRight(4).take(2).takeRight().value(); - deepEqual(actual, [4]); + deepEqual(actual, _.takeRight(_.take(_.takeRight(_.take(array, 6), 4), 2))); values = []; actual = _(array).take(array.length - 1).filter(predicate).take(6).takeRight(4).take(2).takeRight().value(); - deepEqual(actual, [6]); - deepEqual(values, array.slice(0, -2)); + deepEqual(values, [1, 2, 3, 4, 5, 6, 7, 8]); + deepEqual(actual, _.takeRight(_.take(_.takeRight(_.take(_.filter(_.take(array, array.length - 1), predicate), 6), 4), 2))); } else { skipTest(6); @@ -4888,25 +4815,25 @@ test('should work in a lazy chain sequence', 6, function() { if (!isNpm) { - var array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], + var array = _.range(1, LARGE_ARRAY_SIZE + 1), values = [], predicate = function(value) { values.push(value); return value < 9; }, actual = _(array).takeRight(2).takeRight().value(); - deepEqual(actual, [10]); + deepEqual(actual, _.takeRight(_.takeRight(array))); actual = _(array).filter(predicate).takeRight(2).takeRight().value(); - deepEqual(actual, [8]); deepEqual(values, array); + deepEqual(actual, _.takeRight(_.takeRight(_.filter(array, predicate), 2))); actual = _(array).takeRight(6).take(4).takeRight(2).take().value(); - deepEqual(actual, [7]); + deepEqual(actual, _.take(_.takeRight(_.take(_.takeRight(array, 6), 4), 2))); values = []; actual = _(array).filter(predicate).takeRight(6).take(4).takeRight(2).take().value(); - deepEqual(actual, [5]); deepEqual(values, array); + deepEqual(actual, _.take(_.takeRight(_.take(_.takeRight(_.filter(array, predicate), 6), 4), 2))); } else { skipTest(6); @@ -4967,13 +4894,14 @@ test('should work in a lazy chain sequence', 3, function() { if (!isNpm) { - var wrapped = _(array).takeRightWhile(function(num) { - return num > 2; - }); + var array = _.range(1, LARGE_ARRAY_SIZE + 1), + predicate = function(num) { return num > 2; }, + expected = _.takeRightWhile(array, predicate), + wrapped = _(array).takeRightWhile(predicate); - deepEqual(wrapped.value(), [3, 4]); - deepEqual(wrapped.reverse().value(), [4, 3]); - strictEqual(wrapped.last(), 4); + deepEqual(wrapped.value(), expected); + deepEqual(wrapped.reverse().value(), expected.slice().reverse()); + strictEqual(wrapped.last(), _.last(expected)); } else { skipTest(3); @@ -4983,13 +4911,14 @@ test('should provide the correct `predicate` arguments in a lazy chain sequence', 5, function() { if (!isNpm) { var args, - expected = [16, 3, [1, 4, 9 , 16]]; + array = _.range(1, LARGE_ARRAY_SIZE + 1), + expected = [square(LARGE_ARRAY_SIZE), LARGE_ARRAY_SIZE - 1, _.map(array, square)]; _(array).takeRightWhile(function(value, index, array) { args = slice.call(arguments) }).value(); - deepEqual(args, [4, 3, array]); + deepEqual(args, [LARGE_ARRAY_SIZE, LARGE_ARRAY_SIZE - 1, array]); _(array).map(square).takeRightWhile(function(value, index, array) { args = slice.call(arguments) @@ -5007,7 +4936,7 @@ args = slice.call(arguments); }).value(); - deepEqual(args, [16]); + deepEqual(args, [square(LARGE_ARRAY_SIZE)]); _(array).map(square).takeRightWhile(function() { args = slice.call(arguments); @@ -5073,13 +5002,14 @@ test('should work in a lazy chain sequence', 3, function() { if (!isNpm) { - var wrapped = _(array).takeWhile(function(num) { - return num < 3; - }); + var array = _.range(1, LARGE_ARRAY_SIZE + 1), + predicate = function(num) { return num < 3; }, + expected = _.takeWhile(array, predicate), + wrapped = _(array).takeWhile(predicate); - deepEqual(wrapped.value(), [1, 2]); - deepEqual(wrapped.reverse().value(), [2, 1]); - strictEqual(wrapped.last(), 2); + deepEqual(wrapped.value(), expected); + deepEqual(wrapped.reverse().value(), expected.slice().reverse()); + strictEqual(wrapped.last(), _.last(expected)); } else { skipTest(3); @@ -5088,6 +5018,8 @@ test('should work in a lazy chain sequence with `take`', 1, function() { if (!isNpm) { + var array = _.range(1, LARGE_ARRAY_SIZE + 1); + var actual = _(array) .takeWhile(function(num) { return num < 4; }) .take(2) @@ -5104,7 +5036,8 @@ test('should provide the correct `predicate` arguments in a lazy chain sequence', 5, function() { if (!isNpm) { var args, - expected = [1, 0, [1, 4, 9, 16]]; + array = _.range(1, LARGE_ARRAY_SIZE + 1), + expected = [1, 0, _.map(array, square)]; _(array).takeWhile(function(value, index, array) { args = slice.call(arguments); @@ -6114,12 +6047,16 @@ test('should work in a lazy chain sequence', 1, function() { if (!isNpm) { - var array = [1, 2, 1, 3], - iteratee = function(value) { value.push(value[0]); return value; }, - predicate = function(value) { return value[0] > 1; }, - actual = _(array).groupBy(_.identity).map(iteratee).filter(predicate).take().value(); + var array = _.range(LARGE_ARRAY_SIZE).concat( + _.range(Math.floor(LARGE_ARRAY_SIZE / 2), LARGE_ARRAY_SIZE), + _.range(Math.floor(LARGE_ARRAY_SIZE / 1.5), LARGE_ARRAY_SIZE) + ); - deepEqual(actual, [[2, 2]]); + var iteratee = function(value) { value.push(value[0]); return value; }, + predicate = function(value) { return value[0] > 1; }, + actual = _(array).groupBy().map(iteratee).filter(predicate).take().value(); + + deepEqual(actual, _.take(_.filter(_.map(_.groupBy(array), iteratee), predicate))); } else { skipTest(); @@ -6483,11 +6420,15 @@ test('should work in a lazy chain sequence', 1, function() { if (!isNpm) { - var array = [1, 2, 1, 3], - predicate = function(value) { return value > 2; }, - actual = _(array).indexBy(_.identity).map(square).filter(predicate).take().value(); + var array = _.range(LARGE_ARRAY_SIZE).concat( + _.range(Math.floor(LARGE_ARRAY_SIZE / 2), LARGE_ARRAY_SIZE), + _.range(Math.floor(LARGE_ARRAY_SIZE / 1.5), LARGE_ARRAY_SIZE) + ); - deepEqual(actual, [4]); + var predicate = function(value) { return value > 2; }, + actual = _(array).indexBy().map(square).filter(predicate).take().value(); + + deepEqual(actual, _.take(_.filter(_.map(_.indexBy(array), square), predicate))); } else { skipTest(); @@ -6677,7 +6618,7 @@ test('should work in a lazy chain sequence', 4, function() { if (!isNpm) { - var array = [1, 2, 3], + var array = _.range(1, LARGE_ARRAY_SIZE + 1), values = []; var actual = _(array).initial().filter(function(value) { @@ -6687,7 +6628,7 @@ .value(); deepEqual(actual, []); - deepEqual(values, [1, 2]); + deepEqual(values, _.initial(array)); values = []; @@ -9205,13 +9146,11 @@ test('should work in a lazy chain sequence', 1, function() { if (!isNpm) { - var array = [1, 2, 3, 4]; + var array = _.range(1, LARGE_ARRAY_SIZE + 1), + predicate = function(value) { return value % 2; }, + wrapped = _(array).filter(predicate); - var wrapped = _(array).filter(function(value) { - return value % 2; - }); - - strictEqual(wrapped.last(), 3); + strictEqual(wrapped.last(), _.last(_.filter(array, predicate))); } else { skipTest(); @@ -9479,7 +9418,8 @@ test('should provide the correct `predicate` arguments in a lazy chain sequence', 5, function() { if (!isNpm) { var args, - expected = [1, 0, [1, 4, 9]]; + array = _.range(1, LARGE_ARRAY_SIZE + 1), + expected = [1, 0, _.map(array, square)]; _(array).map(function(value, index, array) { args || (args = slice.call(arguments)); @@ -11333,10 +11273,11 @@ if (!isNpm) { _.mixin({ 'a': _.countBy, 'b': _.filter }); - var predicate = function(value) { return value > 2; }, - actual = _([1, 2, 1, 3]).a(_.identity).map(square).b(predicate).take().value(); + var array = _.range(1, LARGE_ARRAY_SIZE + 1), + predicate = function(value) { return value > 2; }, + actual = _(array).a().map(square).b(predicate).take().value(); - deepEqual(actual, [4]); + deepEqual(actual, _.take(_.b(_.map(_.a(array), square), predicate))); delete _.a; delete _.prototype.a; @@ -12332,13 +12273,15 @@ test('should work in a lazy chain sequence', 2, function() { if (!isNpm) { - var array = [{ 'a': 1 }, null, { 'a': 3 }, { 'a': 4 }], - actual = _(array).pluck('a').value(); + var array = _.times(LARGE_ARRAY_SIZE, function(index) { + return index ? { 'a': index } : null; + }); - deepEqual(actual, [1, undefined, 3, 4]); + var actual = _(array).pluck('a').value(); + deepEqual(actual, _.pluck(array, 'a')); - actual = _(array).filter(Boolean).pluck('a').value(); - deepEqual(actual, [1, 3, 4]); + actual = _(array).filter().pluck('a').value(); + deepEqual(actual, _.pluck(_.filter(array), 'a')); } else { skipTest(2); @@ -13241,16 +13184,18 @@ test('`_.' + methodName + '` should work in a lazy chain sequence', 2, function() { if (!isNpm) { - var object = { 'a': 1, 'b': 2, 'c': 3, 'd': 4 }, - predicate = function(value) { return isFilter ? (value > 6) : (value < 6); }; - - var expected = [9, 16], + var array = _.range(1, LARGE_ARRAY_SIZE + 1), + predicate = function(value) { return isFilter ? (value > 6) : (value < 6); }, actual = _(array).map(square)[methodName](predicate).value(); - deepEqual(actual, expected); + deepEqual(actual, _[methodName](_.map(array, square), predicate)); + + var object = _.zipObject(_.times(LARGE_ARRAY_SIZE, function(index) { + return ['key' + index, index]; + })); actual = _(object).mapValues(square)[methodName](predicate).value(); - deepEqual(actual, expected); + deepEqual(actual, _[methodName](_.mapValues(object, square), predicate)); } else { skipTest(2); @@ -13260,7 +13205,8 @@ test('`_.' + methodName + '` should provide the correct `predicate` arguments in a lazy chain sequence', 5, function() { if (!isNpm) { var args, - expected = [1, 0, [1, 4, 9, 16]]; + array = _.range(1, LARGE_ARRAY_SIZE + 1), + expected = [1, 0, _.map(array, square)]; _(array)[methodName](function(value, index, array) { args || (args = slice.call(arguments)); @@ -13629,7 +13575,7 @@ test('should work in a lazy chain sequence', 4, function() { if (!isNpm) { - var array = [1, 2, 3], + var array = _.range(1, LARGE_ARRAY_SIZE + 1), values = []; var actual = _(array).rest().filter(function(value) { @@ -13639,7 +13585,7 @@ .value(); deepEqual(actual, []); - deepEqual(values, [2, 3]); + deepEqual(values, array.slice(1)); values = []; @@ -13650,7 +13596,7 @@ .rest() .value(); - deepEqual(actual, [3]); + deepEqual(actual, array.slice(2)); deepEqual(values, array); } else { @@ -13660,16 +13606,16 @@ test('should not execute subsequent iteratees on an empty array in a lazy chain sequence', 4, function() { if (!isNpm) { - var array = [1], + var array = _.range(1, LARGE_ARRAY_SIZE + 1), iteratee = function() { pass = false }, pass = true, - actual = _(array).rest().map(iteratee).value(); + actual = _(array).slice(0, 1).rest().map(iteratee).value(); ok(pass); deepEqual(actual, []); pass = true; - actual = _(array).filter(_.identity).rest().map(iteratee).value(); + actual = _(array).filter().slice(0, 1).rest().map(iteratee).value(); ok(pass); deepEqual(actual, []); @@ -14284,32 +14230,34 @@ test('should work in a lazy chain sequence', 38, function() { if (!isNpm) { - var wrapped = _(array); + var array = _.range(1, LARGE_ARRAY_SIZE + 1), + length = array.length, + wrapped = _(array); _.each(['map', 'filter'], function(methodName) { - deepEqual(wrapped[methodName]().slice(0, -1).value(), [1, 2]); - deepEqual(wrapped[methodName]().slice(1).value(), [2, 3]); - deepEqual(wrapped[methodName]().slice(1, 3).value(), [2, 3]); - deepEqual(wrapped[methodName]().slice(-1).value(), [3]); + deepEqual(wrapped[methodName]().slice(0, -1).value(), array.slice(0, -1)); + deepEqual(wrapped[methodName]().slice(1).value(), array.slice(1)); + deepEqual(wrapped[methodName]().slice(1, 3).value(), array.slice(1, 3)); + deepEqual(wrapped[methodName]().slice(-1).value(), array.slice(-1)); - deepEqual(wrapped[methodName]().slice(4).value(), []); - deepEqual(wrapped[methodName]().slice(3, 2).value(), []); - deepEqual(wrapped[methodName]().slice(0, -4).value(), []); - deepEqual(wrapped[methodName]().slice(0, null).value(), []); + deepEqual(wrapped[methodName]().slice(length).value(), array.slice(length)); + deepEqual(wrapped[methodName]().slice(3, 2).value(), array.slice(3, 2)); + deepEqual(wrapped[methodName]().slice(0, -length).value(), array.slice(0, -length)); + deepEqual(wrapped[methodName]().slice(0, null).value(), array.slice(0, null)); - deepEqual(wrapped[methodName]().slice(0, 4).value(), array); - deepEqual(wrapped[methodName]().slice(-4).value(), array); - deepEqual(wrapped[methodName]().slice(null).value(), array); + deepEqual(wrapped[methodName]().slice(0, length).value(), array.slice(0, length)); + deepEqual(wrapped[methodName]().slice(-length).value(), array.slice(-length)); + deepEqual(wrapped[methodName]().slice(null).value(), array.slice(null)); - deepEqual(wrapped[methodName]().slice(0, 1).value(), [1]); - deepEqual(wrapped[methodName]().slice(NaN, '1').value(), [1]); + deepEqual(wrapped[methodName]().slice(0, 1).value(), array.slice(0, 1)); + deepEqual(wrapped[methodName]().slice(NaN, '1').value(), array.slice(NaN, '1')); - deepEqual(wrapped[methodName]().slice(0.1, 1.1).value(), [1]); - deepEqual(wrapped[methodName]().slice('0', 1).value(), [1]); - deepEqual(wrapped[methodName]().slice(0, '1').value(), [1]); - deepEqual(wrapped[methodName]().slice('1').value(), [2, 3]); - deepEqual(wrapped[methodName]().slice(NaN, 1).value(), [1]); - deepEqual(wrapped[methodName]().slice(1, NaN).value(), []); + deepEqual(wrapped[methodName]().slice(0.1, 1.1).value(), array.slice(0.1, 1.1)); + deepEqual(wrapped[methodName]().slice('0', 1).value(), array.slice('0', 1)); + deepEqual(wrapped[methodName]().slice(0, '1').value(), array.slice(0, '1')); + deepEqual(wrapped[methodName]().slice('1').value(), array.slice('1')); + deepEqual(wrapped[methodName]().slice(NaN, 1).value(), array.slice(NaN, 1)); + deepEqual(wrapped[methodName]().slice(1, NaN).value(), array.slice(1, NaN)); }); } else { @@ -15972,11 +15920,17 @@ test('should work in a lazy chain sequence', 2, function() { if (!isNpm) { - var actual = _([1, 2]).map(String).toArray().value(); - deepEqual(actual, ['1', '2']); + var array = _.range(1, LARGE_ARRAY_SIZE + 1), + actual = _(array).map(String).toArray().value(); - actual = _({ 'a': 1, 'b': 2 }).toArray().map(String).value(); - deepEqual(actual, ['1', '2']); + deepEqual(actual, _.map(array, String)); + + var object = _.zipObject(_.times(LARGE_ARRAY_SIZE, function(index) { + return ['key' + index, index]; + })); + + actual = _(object).toArray().map(String).value(); + deepEqual(actual, _.map(_.toArray(object), String)); } else { skipTest(2); @@ -16709,14 +16663,12 @@ test('should work in a lazy chain sequence', 1, function() { if (!isNpm) { - var array = [ - { 'a': 1 }, - { 'a': 3 }, - { 'a': 1, 'b': 2 } - ]; + var array = _.times(LARGE_ARRAY_SIZE, function(index) { + return index ? { 'a': 1, 'b': index } : { 'a': 3 }; + }); var actual = _(array).where({ 'a': 1 }).value(); - deepEqual(actual, [array[0], array[2]]); + deepEqual(actual, _.where(array, { 'a': 1 })); } else { skipTest(); @@ -16888,13 +16840,14 @@ test('should work when in a lazy chain sequence before `first` or `last`', 1, function() { if (!isNpm) { - var wrapped = _([1, 2]).slice().xor([2, 3]); + var array = _.range(0, LARGE_ARRAY_SIZE), + wrapped = _(array).slice(1).xor([LARGE_ARRAY_SIZE - 1, LARGE_ARRAY_SIZE]); var actual = _.map(['first', 'last'], function(methodName) { return wrapped[methodName](); }); - deepEqual(actual, [1, 3]); + deepEqual(actual, [1, LARGE_ARRAY_SIZE]); } else { skipTest(); @@ -16952,11 +16905,14 @@ test('should work in a lazy chain sequence', 1, function() { if (!isNpm) { - var array = [['a', 1], ['b', 2]], - predicate = function(value) { return value > 2; }, + var array = _.times(LARGE_ARRAY_SIZE, function(index) { + return ['key' + index, index]; + }); + + var predicate = function(value) { return value > 2; }, actual = _(array).zipObject().map(square).filter(predicate).take().value(); - deepEqual(actual, [4]); + deepEqual(actual, _.take(_.filter(_.map(_.zipObject(array), square), predicate))); } else { skipTest(); @@ -17310,8 +17266,10 @@ test('should work in a lazy chain sequence', 1, function() { if (!isNpm) { - var actual = _([1, 2, 3, null]).map(_.identity).reverse().value(); - deepEqual(actual, [null, 3, 2, 1]); + var array = _.range(0, LARGE_ARRAY_SIZE).concat(null), + actual = _(array).slice(1).reverse().value(); + + deepEqual(actual, array.slice(1).reverse()); } else { skipTest(); @@ -17327,12 +17285,13 @@ }; try { - var wrapped = _(['a', spy]).map(String).reverse(), + var array = _.range(1, LARGE_ARRAY_SIZE).concat(spy), + wrapped = _(array).map(String).reverse(), actual = wrapped.last(); } catch(e) {} ok(wrapped instanceof _); - strictEqual(actual, 'a'); + strictEqual(actual, '1'); } else { skipTest(2);