Test migration to jest by hand
Apparently using regular expressions is way easier.
This commit is contained in:
9
test/memoize/memoize.js
Normal file
9
test/memoize/memoize.js
Normal file
@ -0,0 +1,9 @@
|
||||
const memoize = fn => {
|
||||
const cache = new Map();
|
||||
const cached = function(val) {
|
||||
return cache.has(val) ? cache.get(val) : cache.set(val, fn.call(this, val)) && cache.get(val);
|
||||
};
|
||||
cached.cache = cache;
|
||||
return cached;
|
||||
};
|
||||
module.exports = memoize;
|
||||
14
test/memoize/memoize.test.js
Normal file
14
test/memoize/memoize.test.js
Normal file
@ -0,0 +1,14 @@
|
||||
const expect = require('expect');
|
||||
const memoize = require('./memoize.js');
|
||||
|
||||
|
||||
test('memoize is a Function', () => {
|
||||
expect(memoize).toBeInstanceOf(Function);
|
||||
});
|
||||
const f = x => x * x;
|
||||
const square = memoize(f);
|
||||
t.equal(square(2), 4, 'Function works properly');
|
||||
t.equal(square(3), 9, 'Function works properly');
|
||||
t.deepEqual(Array.from(square.cache), [[2,4],[3,9]], 'Cache stores values');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user