From 7573ac775110f333a344d41f3d6a485c90207261 Mon Sep 17 00:00:00 2001 From: Jeremy Ashkenas Date: Wed, 13 Jul 2011 12:36:27 -0400 Subject: [PATCH] Unit tests for sparse arrays. --- test/collections.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/collections.js b/test/collections.js index 9a4d49ec4..a0ac266ac 100644 --- a/test/collections.js +++ b/test/collections.js @@ -77,6 +77,15 @@ $(document).ready(function() { ok(ifnull instanceof TypeError, 'handles a null (without inital value) properly'); ok(_.reduce(null, function(){}, 138) === 138, 'handles a null (with initial value) properly'); + + // Sparse arrays: + equals(_.reduce([], function(){}, undefined), undefined, 'undefined can be passed as a special case'); + + var sparseArray = []; + sparseArray[100] = 10; + sparseArray[200] = 20; + + equals(_.reduce(sparseArray, function(a, b){ return a + b }), 30, 'initially-sparse arrays with no memo'); }); test('collections: reduceRight', function() {