Test cleanup and fixes [m-n]

This commit is contained in:
Angelos Chalaris
2018-06-18 17:40:29 +03:00
parent 82f0d6bc52
commit b393ad5878
20 changed files with 102 additions and 153 deletions

View File

@ -1,12 +1,9 @@
const expect = require('expect');
const mapKeys = require('./mapKeys.js');
test('mapKeys is a Function', () => {
test('mapKeys is a Function', () => {
expect(mapKeys).toBeInstanceOf(Function);
});
test('Maps keys', () => {
expect(mapKeys({ a: 1, b: 2 }, (val, key) => key + val), { a1: 1, b2: 2 }).toEqual()
test('Maps keys', () => {
expect(mapKeys({ a: 1, b: 2 }, (val, key) => key + val)).toEqual({ a1: 1, b2: 2 });
});

View File

@ -1,18 +1,15 @@
const expect = require('expect');
const mapObject = require('./mapObject.js');
test('mapObject is a Function', () => {
test('mapObject is a Function', () => {
expect(mapObject).toBeInstanceOf(Function);
});
test('mapObject([1, 2, 3], a => a * a) returns { 1: 1, 2: 4, 3: 9 }', () => {
expect(mapObject([1, 2, 3], a => a * a), { 1: 1, 2: 4).toEqual(3: 9 })
test('mapObject([1, 2, 3], a => a * a) returns { 1: 1, 2: 4, 3: 9 }', () => {
expect(mapObject([1, 2, 3], a => a * a)).toEqual({ 1: 1, 2: 4, 3: 9 });
});
test('mapObject([1, 2, 3, 4], (a, b) => b - a) returns { 1: -1, 2: -1, 3: -1, 4: -1 }', () => {
expect(mapObject([1, 2, 3, 4], (a, b) => b - a), { 1: -1, 2: -1, 3: -1, 4: -1 }).toEqual()
test('mapObject([1, 2, 3, 4], (a, b) => b - a) returns { 1: -1, 2: -1, 3: -1, 4: -1 }', () => {
expect(mapObject([1, 2, 3, 4], (a, b) => b - a)).toEqual({ 1: -1, 2: -1, 3: -1, 4: -1 });
});
test('mapObject([1, 2, 3, 4], (a, b) => a - b) returns { 1: 1, 2: 1, 3: 1, 4: 1 }', () => {
expect(mapObject([1, 2, 3, 4], (a, b) => a - b), { 1: 1, 2: 1, 3: 1, 4: 1 }).toEqual()
test('mapObject([1, 2, 3, 4], (a, b) => a - b) returns { 1: 1, 2: 1, 3: 1, 4: 1 }', () => {
expect(mapObject([1, 2, 3, 4], (a, b) => a - b)).toEqual({ 1: 1, 2: 1, 3: 1, 4: 1 });
});

View File

@ -1,16 +1,13 @@
const expect = require('expect');
const mapValues = require('./mapValues.js');
test('mapValues is a Function', () => {
test('mapValues is a Function', () => {
expect(mapValues).toBeInstanceOf(Function);
});
const users = {
const users = {
fred: { user: 'fred', age: 40 },
pebbles: { user: 'pebbles', age: 1 }
};
test('Maps values', () => {
expect(mapValues(users, u => u.age), { fred: 40, pebbles: 1 }).toEqual()
};
test('Maps values', () => {
expect(mapValues(users, u => u.age)).toEqual({ fred: 40, pebbles: 1 });
});

View File

@ -1,17 +1,15 @@
const expect = require('expect');
const mask = require('./mask.js');
test('mask is a Function', () => {
test('mask is a Function', () => {
expect(mask).toBeInstanceOf(Function);
});
test('Replaces all but the last num of characters with the specified mask character', () => {
expect(mask(1234567890)).toBe('******7890')
test('Replaces all but the last num of characters with the specified mask character', () => {
expect(mask(1234567890)).toBe('******7890');
});
test('Replaces all but the last num of characters with the specified mask character', () => {
expect(mask(1234567890, 3)).toBe('*******890')
test('Replaces all but the last num of characters with the specified mask character', () => {
expect(mask(1234567890, 3)).toBe('*******890');
});
test('Replaces all but the last num of characters with the specified mask character', () => {
expect(mask(1234567890, -4, '$')).toBe('$$$$567890')
test('Replaces all but the last num of characters with the specified mask character', () => {
expect(mask(1234567890, -4, '$')).toBe('$$$$567890');
});

View File

@ -1,15 +1,12 @@
const expect = require('expect');
const matches = require('./matches.js');
test('matches is a Function', () => {
test('matches is a Function', () => {
expect(matches).toBeInstanceOf(Function);
});
test('Matches returns true for two similar objects', () => {
test('Matches returns true for two similar objects', () => {
expect(matches({ age: 25, hair: 'long', beard: true }, { hair: 'long', beard: true })).toBeTruthy();
});
test('Matches returns false for two non-similar objects', () => {
test('Matches returns false for two non-similar objects', () => {
expect(matches({ hair: 'long', beard: true }, { age: 25, hair: 'long', beard: true })).toBeFalsy();
});

View File

@ -1,15 +1,14 @@
const expect = require('expect');
const matchesWith = require('./matchesWith.js');
test('matchesWith is a Function', () => {
test('matchesWith is a Function', () => {
expect(matchesWith).toBeInstanceOf(Function);
});
const isGreeting = val => /^h(?:i|ello)$/.test(val);
t.true(matchesWith(
const isGreeting = val => /^h(?:i|ello)$/.test(val);
test('Returns true for two objects with similar values, based on the provided function', () => {
expect(matchesWith(
{ greeting: 'hello' },
{ greeting: 'hi' },
(oV, sV) => isGreeting(oV) && isGreeting(sV)
), 'Returns true for two objects with similar values, based on the provided function');
)).toBeTruthy();
});

View File

@ -1,15 +1,12 @@
const expect = require('expect');
const maxBy = require('./maxBy.js');
test('maxBy is a Function', () => {
test('maxBy is a Function', () => {
expect(maxBy).toBeInstanceOf(Function);
});
test('Produces the right result with a function', () => {
expect(maxBy([{ n: 4 }, { n: 2 }, { n: 8 }, { n: 6 }], o => o.n), 8).toBe()
test('Produces the right result with a function', () => {
expect(maxBy([{ n: 4 }, { n: 2 }, { n: 8 }, { n: 6 }], o => o.n)).toBe(8);
});
test('Produces the right result with a property name', () => {
expect(maxBy([{ n: 4 }, { n: 2 }, { n: 8 }, { n: 6 }], 'n'), 8).toBe()
test('Produces the right result with a property name', () => {
expect(maxBy([{ n: 4 }, { n: 2 }, { n: 8 }, { n: 6 }], 'n')).toBe(8);
});

View File

@ -1,14 +1,12 @@
const expect = require('expect');
const maxN = require('./maxN.js');
test('maxN is a Function', () => {
test('maxN is a Function', () => {
expect(maxN).toBeInstanceOf(Function);
});
test('Returns the n maximum elements from the provided array', () => {
expect(maxN([1, 2, 3])).toEqual([3])
test('Returns the n maximum elements from the provided array', () => {
expect(maxN([1, 2, 3])).toEqual([3])l
});
test('Returns the n maximum elements from the provided array', () => {
expect(maxN([1, 2, 3], 2), [3).toEqual(2])
test('Returns the n maximum elements from the provided array', () => {
expect(maxN([1, 2, 3], 2)).toEqual([3, 2])l
});

View File

@ -1,14 +1,12 @@
const expect = require('expect');
const median = require('./median.js');
test('median is a Function', () => {
test('median is a Function', () => {
expect(median).toBeInstanceOf(Function);
});
test('Returns the median of an array of numbers', () => {
test('Returns the median of an array of numbers', () => {
expect(median([5, 6, 50, 1, -5])).toBe(5)
});
test('Returns the median of an array of numbers', () => {
test('Returns the median of an array of numbers', () => {
expect(median([1, 2, 3])).toBe(2)
});

View File

@ -1,20 +1,17 @@
const expect = require('expect');
const memoize = require('./memoize.js');
test('memoize is a Function', () => {
test('memoize is a Function', () => {
expect(memoize).toBeInstanceOf(Function);
});
const f = x => x * x;
const square = memoize(f);
test('Function works properly', () => {
expect(square(2), 4).toBe()
const f = x => x * x;
const square = memoize(f);
test('Function works properly', () => {
expect(square(2)).toBe(4);
});
test('Function works properly', () => {
expect(square(3), 9).toBe()
test('Function works properly', () => {
expect(square(3)).toBe(9);
});
test('Cache stores values', () => {
expect(Array.from(square.cache), [[2,4],[3,9]]).toEqual()
test('Cache stores values', () => {
expect(Array.from(square.cache)).toEqual([[2,4],[3,9]]);
});

View File

@ -1,21 +1,18 @@
const expect = require('expect');
const merge = require('./merge.js');
test('merge is a Function', () => {
test('merge is a Function', () => {
expect(merge).toBeInstanceOf(Function);
});
const object = {
const object = {
a: [{ x: 2 }, { y: 4 }],
b: 1
};
const other = {
};
const other = {
a: { z: 3 },
b: [2, 3],
c: 'foo'
};
test('Merges two objects', () => {
expect(merge(object, other), { a: [ { x: 2 }, { y: 4 }, { z: 3 } ], b: [ 1, 2, 3 ], c: 'foo' }).toEqual()
};
test('Merges two objects', () => {
expect(merge(object, other)).toEqual({ a: [ { x: 2 }, { y: 4 }, { z: 3 } ], b: [ 1, 2, 3 ], c: 'foo' });
});

View File

@ -1,15 +1,12 @@
const expect = require('expect');
const minBy = require('./minBy.js');
test('minBy is a Function', () => {
test('minBy is a Function', () => {
expect(minBy).toBeInstanceOf(Function);
});
test('Produces the right result with a function', () => {
expect(minBy([{ n: 4 }, { n: 2 }, { n: 8 }, { n: 6 }], o => o.n), 2).toBe()
test('Produces the right result with a function', () => {
expect(minBy([{ n: 4 }, { n: 2 }, { n: 8 }, { n: 6 }], o => o.n)).toBe(2);
});
test('Produces the right result with a property name', () => {
expect(minBy([{ n: 4 }, { n: 2 }, { n: 8 }, { n: 6 }], 'n'), 2).toBe()
test('Produces the right result with a property name', () => {
expect(minBy([{ n: 4 }, { n: 2 }, { n: 8 }, { n: 6 }], 'n')).toBe(2);
});

View File

@ -1,14 +1,12 @@
const expect = require('expect');
const minN = require('./minN.js');
test('minN is a Function', () => {
test('minN is a Function', () => {
expect(minN).toBeInstanceOf(Function);
});
test('Returns the n minimum elements from the provided array', () => {
expect(minN([1, 2, 3])).toEqual([1])
test('Returns the n minimum elements from the provided array', () => {
expect(minN([1, 2, 3])).toEqual([1]);
});
test('Returns the n minimum elements from the provided array', () => {
expect(minN([1, 2, 3], 2), [1).toEqual(2])
test('Returns the n minimum elements from the provided array', () => {
expect(minN([1, 2, 3], 2), ).toEqual([1, 2]);
});

View File

@ -1,10 +1,6 @@
const expect = require('expect');
const mostPerformant = require('./mostPerformant.js');
test('mostPerformant is a Function', () => {
test('mostPerformant is a Function', () => {
expect(mostPerformant).toBeInstanceOf(Function);
});

View File

@ -1,12 +1,9 @@
const expect = require('expect');
const negate = require('./negate.js');
test('negate is a Function', () => {
test('negate is a Function', () => {
expect(negate).toBeInstanceOf(Function);
});
test('Negates a predicate function', () => {
expect([1, 2, 3, 4, 5, 6].filter(negate(n => n % 2 === 0)), [1, 3).toEqual(5])
test('Negates a predicate function', () => {
expect([1, 2, 3, 4, 5, 6].filter(negate(n => n % 2 === 0))).toEqual([1, 3, 5]);
});

View File

@ -1,8 +1,6 @@
const expect = require('expect');
const nest = require('./nest.js');
test('nest is a Function', () => {
test('nest is a Function', () => {
expect(nest).toBeInstanceOf(Function);
});

View File

@ -1,8 +1,6 @@
const expect = require('expect');
const nodeListToArray = require('./nodeListToArray.js');
test('nodeListToArray is a Function', () => {
test('nodeListToArray is a Function', () => {
expect(nodeListToArray).toBeInstanceOf(Function);
});

View File

@ -1,21 +1,18 @@
const expect = require('expect');
const none = require('./none.js');
test('none is a Function', () => {
test('none is a Function', () => {
expect(none).toBeInstanceOf(Function);
});
test('Returns true for arrays with no truthy values', () => {
test('Returns true for arrays with no truthy values', () => {
expect(none([0,undefined,NaN,null,''])).toBeTruthy();
});
test('Returns false for arrays with at least one truthy value', () => {
test('Returns false for arrays with at least one truthy value', () => {
expect(none([0,1])).toBeFalsy();
});
test('Returns true with a predicate function', () => {
test('Returns true with a predicate function', () => {
expect(none([4,1,0,3], x => x < 0)).toBeTruthy();
});
test('Returns false with predicate function', () => {
test('Returns false with predicate function', () => {
expect(none([0,1,2], x => x === 1)).toBeFalsy();
});

View File

@ -1,20 +1,18 @@
const expect = require('expect');
const nthArg = require('./nthArg.js');
test('nthArg is a Function', () => {
test('nthArg is a Function', () => {
expect(nthArg).toBeInstanceOf(Function);
});
const third = nthArg(2);
test('Returns the nth argument', () => {
expect(third(1, 2, 3), 3).toBe()
const third = nthArg(2);
test('Returns the nth argument', () => {
expect(third(1, 2, 3)).toBe(3);
});
test('Returns undefined if arguments too few', () => {
expect(third(1, 2), undefined).toBe()
test('Returns undefined if arguments too few', () => {
expect(third(1, 2)).toBe(undefined);
});
const last = nthArg(-1);
test('Works for negative values', () => {
expect(last(1, 2, 3, 4, 5), 5).toBe()
const last = nthArg(-1);
test('Works for negative values', () => {
expect(last(1, 2, 3, 4, 5)).toBe(5);
});

View File

@ -1,14 +1,12 @@
const expect = require('expect');
const nthElement = require('./nthElement.js');
test('nthElement is a Function', () => {
test('nthElement is a Function', () => {
expect(nthElement).toBeInstanceOf(Function);
});
test('Returns the nth element of an array.', () => {
expect(nthElement(['a', 'b', 'c'], 1)).toBe('b')
test('Returns the nth element of an array.', () => {
expect(nthElement(['a', 'b', 'c'], 1)).toBe('b');
});
test('Returns the nth element of an array.', () => {
expect(nthElement(['a', 'b', 'c'], -3)).toBe('a')
test('Returns the nth element of an array.', () => {
expect(nthElement(['a', 'b', 'c'], -3)).toBe('a');
});