From 4238e84ec48104c7d625ea9503eea9c54cf8ffef Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Sat, 9 Aug 2014 09:39:29 -0700 Subject: [PATCH] Add tests for matching `NaN`. --- test/test.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/test/test.js b/test/test.js index b83802996..d0c81a4a2 100644 --- a/test/test.js +++ b/test/test.js @@ -1902,6 +1902,10 @@ strictEqual(_.contains([3, 2, 1], 3, true), true); }); + test('should match `NaN`', 1, function() { + strictEqual(_.contains([1, NaN, 3], NaN), true); + }); + test('should be aliased', 1, function() { strictEqual(_.include, _.contains); }); @@ -2857,6 +2861,10 @@ deepEqual(actual, [1, 3]); }); + test('should match `NaN`', 1, function() { + deepEqual(_.difference([1, NaN, 3], [NaN, 5, NaN]), [1, 3]); + }); + test('should work with large arrays', 1, function() { var array1 = _.range(LARGE_ARRAY_SIZE + 1), array2 = _.range(LARGE_ARRAY_SIZE), @@ -4793,6 +4801,10 @@ deepEqual(_.intersection(array), [1, 3, 2]); }); + test('should match `NaN`', 1, function() { + deepEqual(_.intersection([1, NaN, 3], [NaN, 5, NaN]), [NaN]); + }); + test('should work with large arrays of objects', 1, function() { var object = {}, largeArray = _.times(LARGE_ARRAY_SIZE, _.constant(object)); @@ -6722,6 +6734,10 @@ strictEqual(func(empty, undefined), -1); strictEqual(func(empty, undefined, true), -1); }); + + test('`_.' + methodName + '` should match `NaN`', 1, function() { + strictEqual(func([1, NaN, 3], NaN), 1); + }); }); /*--------------------------------------------------------------------------*/ @@ -8489,6 +8505,13 @@ _.pull(array, undefined); deepEqual(array, [1, 3]); }); + + test('should match `NaN`', 1, function() { + var array = [1, NaN, 3, NaN]; + + _.pull(array, NaN); + deepEqual(array, [1, 3]); + }); }()); /*--------------------------------------------------------------------------*/ @@ -11024,6 +11047,10 @@ deepEqual(_.uniq(objects), objects); }); + test('should not treat `NaN` as uniq', 1, function() { + deepEqual(_.uniq([1, NaN, 3, NaN]), [1, NaN, 3]); + }); + test('should work with `isSorted`', 3, function() { var expected = [1, 2, 3]; deepEqual(_.uniq([1, 2, 3], true), expected);