From ee8567ab387351b5e752d9b2b6a6e19e4815f2d1 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Mon, 28 Dec 2015 20:33:39 -0600 Subject: [PATCH] Cleanup `MapCache` tests. --- test/test.js | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/test/test.js b/test/test.js index e8f1bd128..462e8e559 100644 --- a/test/test.js +++ b/test/test.js @@ -12703,23 +12703,22 @@ QUnit.test('should implement a `Map` interface on the cache object', function(assert) { assert.expect(164); - function getValue(key) { - var lastIndex = cacheKeys.length - 1; - return cacheKeys[lastIndex - lodashStable.indexOf(cacheKeys, key)]; - } - var symbol = Symbol ? Symbol() : undefined, - cacheKeys = [true, false, 1, -Infinity, NaN, { 'a': 1 }, null, 'a', symbol, undefined]; + keys = [true, false, 1, -Infinity, NaN, { 'a': 1 }, null, 'a', symbol, undefined]; + + var pairs = lodashStable.map(keys, function(key, index) { + var lastIndex = keys.length - 1; + return [key, keys[lastIndex - index]]; + }); lodashStable.times(2, function(index) { - var func = (index ? (lodashBizarro || {}) : _).memoize, - memoized = func ? func(getValue) : noop, - cache = memoized.cache; + var memoize = (index ? (lodashBizarro || {}) : _).memoize, + Cache = memoize ? memoize.Cache : undefined, + cache = Cache ? new Cache(pairs) : undefined; - lodashStable.each(cacheKeys, function(key, index) { - if (func) { - var value = getValue(key); - memoized(key); + lodashStable.each(keys, function(key, index) { + if (cache) { + var value = pairs[index][1]; assert.deepEqual(cache.get(key), value); assert.strictEqual(cache.has(key), true); @@ -12735,9 +12734,9 @@ } }); - if (func) { + if (cache) { assert.strictEqual(cache.clear(), undefined); - assert.ok(lodashStable.every(cacheKeys, function(key) { + assert.ok(lodashStable.every(keys, function(key) { return !cache.has(key); })); }