mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-08 02:17:48 +00:00
Add small array lazy chain tests for _.first and _.last.
This commit is contained in:
committed by
John-David Dalton
parent
82f693a2bc
commit
a5e2caf40b
42
test/test.js
42
test/test.js
@@ -4768,7 +4768,7 @@
|
|||||||
QUnit.module('lodash.first');
|
QUnit.module('lodash.first');
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
var array = [1, 2, 3];
|
var array = [1, 2, 3, 4];
|
||||||
|
|
||||||
test('should return the first element', 1, function() {
|
test('should return the first element', 1, function() {
|
||||||
strictEqual(_.first(array), 1);
|
strictEqual(_.first(array), 1);
|
||||||
@@ -4816,18 +4816,21 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should work in a lazy chain sequence', 1, function() {
|
test('should work in a lazy chain sequence', 2, function() {
|
||||||
if (!isNpm) {
|
if (!isNpm) {
|
||||||
var array = _.range(1, LARGE_ARRAY_SIZE + 1);
|
var largeArray = _.range(1, LARGE_ARRAY_SIZE + 1),
|
||||||
|
smallArray = array;
|
||||||
|
|
||||||
var wrapped = _(array).filter(function(value) {
|
_.times(2, function(index) {
|
||||||
return value % 2 == 0;
|
var array = index ? largeArray : smallArray,
|
||||||
|
predicate = function(value) { return value % 2; },
|
||||||
|
wrapped = _(array).filter(predicate);
|
||||||
|
|
||||||
|
strictEqual(wrapped.first(), _.first(_.filter(array, predicate)));
|
||||||
});
|
});
|
||||||
|
|
||||||
strictEqual(wrapped.first(), 2);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
skipTest();
|
skipTest(2);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -9243,10 +9246,10 @@
|
|||||||
QUnit.module('lodash.last');
|
QUnit.module('lodash.last');
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
var array = [1, 2, 3];
|
var array = [1, 2, 3, 4];
|
||||||
|
|
||||||
test('should return the last element', 1, function() {
|
test('should return the last element', 1, function() {
|
||||||
strictEqual(_.last(array), 3);
|
strictEqual(_.last(array), 4);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should return `undefined` when querying empty arrays', 1, function() {
|
test('should return `undefined` when querying empty arrays', 1, function() {
|
||||||
@@ -9265,7 +9268,7 @@
|
|||||||
|
|
||||||
test('should return an unwrapped value when implicitly chaining', 1, function() {
|
test('should return an unwrapped value when implicitly chaining', 1, function() {
|
||||||
if (!isNpm) {
|
if (!isNpm) {
|
||||||
strictEqual(_(array).last(), 3);
|
strictEqual(_(array).last(), 4);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
skipTest();
|
skipTest();
|
||||||
@@ -9291,16 +9294,21 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should work in a lazy chain sequence', 1, function() {
|
test('should work in a lazy chain sequence', 2, function() {
|
||||||
if (!isNpm) {
|
if (!isNpm) {
|
||||||
var array = _.range(1, LARGE_ARRAY_SIZE + 1),
|
var largeArray = _.range(1, LARGE_ARRAY_SIZE + 1),
|
||||||
predicate = function(value) { return value % 2; },
|
smallArray = array;
|
||||||
wrapped = _(array).filter(predicate);
|
|
||||||
|
|
||||||
strictEqual(wrapped.last(), _.last(_.filter(array, predicate)));
|
_.times(2, function(index) {
|
||||||
|
var array = index ? largeArray : smallArray,
|
||||||
|
predicate = function(value) { return value % 2; },
|
||||||
|
wrapped = _(array).filter(predicate);
|
||||||
|
|
||||||
|
strictEqual(wrapped.last(), _.last(_.filter(array, predicate)));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
skipTest();
|
skipTest(2);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}());
|
}());
|
||||||
|
|||||||
Reference in New Issue
Block a user