Test cleanup and fixes [o-p]
This commit is contained in:
@ -1,11 +1,9 @@
|
|||||||
const expect = require('expect');
|
const expect = require('expect');
|
||||||
const objectFromPairs = require('./objectFromPairs.js');
|
const objectFromPairs = require('./objectFromPairs.js');
|
||||||
|
|
||||||
|
test('objectFromPairs is a Function', () => {
|
||||||
test('objectFromPairs is a Function', () => {
|
|
||||||
expect(objectFromPairs).toBeInstanceOf(Function);
|
expect(objectFromPairs).toBeInstanceOf(Function);
|
||||||
});
|
});
|
||||||
test('Creates an object from the given key-value pairs.', () => {
|
test('Creates an object from the given key-value pairs.', () => {
|
||||||
expect(objectFromPairs([['a', 1], ['b', 2]]), {a: 1).toEqual(b: 2})
|
expect(objectFromPairs([['a', 1], ['b', 2]])).toEqual({a: 1, b: 2});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -1,11 +1,9 @@
|
|||||||
const expect = require('expect');
|
const expect = require('expect');
|
||||||
const objectToPairs = require('./objectToPairs.js');
|
const objectToPairs = require('./objectToPairs.js');
|
||||||
|
|
||||||
|
test('objectToPairs is a Function', () => {
|
||||||
test('objectToPairs is a Function', () => {
|
|
||||||
expect(objectToPairs).toBeInstanceOf(Function);
|
expect(objectToPairs).toBeInstanceOf(Function);
|
||||||
});
|
});
|
||||||
test('Creates an array of key-value pair arrays from an object.', () => {
|
test('Creates an array of key-value pair arrays from an object.', () => {
|
||||||
expect(objectToPairs({ a: 1, b: 2 }), [['a',1],['b').toEqual(2]])
|
expect(objectToPairs({ a: 1, b: 2 })).toEqual([['a',1],['b', 2]]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -1,10 +1,6 @@
|
|||||||
const expect = require('expect');
|
const expect = require('expect');
|
||||||
const observeMutations = require('./observeMutations.js');
|
const observeMutations = require('./observeMutations.js');
|
||||||
|
|
||||||
|
test('observeMutations is a Function', () => {
|
||||||
test('observeMutations is a Function', () => {
|
|
||||||
expect(observeMutations).toBeInstanceOf(Function);
|
expect(observeMutations).toBeInstanceOf(Function);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1,10 +1,6 @@
|
|||||||
const expect = require('expect');
|
const expect = require('expect');
|
||||||
const off = require('./off.js');
|
const off = require('./off.js');
|
||||||
|
|
||||||
|
test('off is a Function', () => {
|
||||||
test('off is a Function', () => {
|
|
||||||
expect(off).toBeInstanceOf(Function);
|
expect(off).toBeInstanceOf(Function);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1,27 +1,24 @@
|
|||||||
const expect = require('expect');
|
const expect = require('expect');
|
||||||
const offset = require('./offset.js');
|
const offset = require('./offset.js');
|
||||||
|
|
||||||
|
test('offset is a Function', () => {
|
||||||
test('offset is a Function', () => {
|
|
||||||
expect(offset).toBeInstanceOf(Function);
|
expect(offset).toBeInstanceOf(Function);
|
||||||
});
|
});
|
||||||
test('Offset of 0 returns the same array.', () => {
|
test('Offset of 0 returns the same array.', () => {
|
||||||
expect(offset([1, 2, 3, 4, 5], 0), [1, 2, 3, 4, 5]).toEqual()
|
expect(offset([1, 2, 3, 4, 5], 0)).toEqual([1, 2, 3, 4, 5]);
|
||||||
});
|
});
|
||||||
test('Offset > 0 returns the offsetted array.', () => {
|
test('Offset > 0 returns the offsetted array.', () => {
|
||||||
expect(offset([1, 2, 3, 4, 5], 2), [3, 4, 5, 1, 2]).toEqual()
|
expect(offset([1, 2, 3, 4, 5], 2)).toEqual([3, 4, 5, 1, 2]);
|
||||||
});
|
});
|
||||||
test('Offset < 0 returns the reverse offsetted array.', () => {
|
test('Offset < 0 returns the reverse offsetted array.', () => {
|
||||||
expect(offset([1, 2, 3, 4, 5], -2), [4, 5, 1, 2, 3]).toEqual()
|
expect(offset([1, 2, 3, 4, 5], -2)).toEqual([4, 5, 1, 2, 3]);
|
||||||
});
|
});
|
||||||
test('Offset greater than the length of the array returns the same array.', () => {
|
test('Offset greater than the length of the array returns the same array.', () => {
|
||||||
expect(offset([1, 2, 3, 4, 5], 6),[1, 2, 3, 4, 5]).toEqual()
|
expect(offset([1, 2, 3, 4, 5], 6)).toEqual([1, 2, 3, 4, 5]);
|
||||||
});
|
});
|
||||||
test('Offset less than the negative length of the array returns the same array.', () => {
|
test('Offset less than the negative length of the array returns the same array.', () => {
|
||||||
expect(offset([1, 2, 3, 4, 5], -6), [1, 2, 3, 4, 5]).toEqual()
|
expect(offset([1, 2, 3, 4, 5], -6)).toEqual([1, 2, 3, 4, 5]);
|
||||||
});
|
});
|
||||||
test('Offsetting empty array returns an empty array.', () => {
|
test('Offsetting empty array returns an empty array.', () => {
|
||||||
expect(offset([], 3), []).toEqual()
|
expect(offset([], 3)).toEqual([]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1,12 +1,9 @@
|
|||||||
const expect = require('expect');
|
const expect = require('expect');
|
||||||
const omit = require('./omit.js');
|
const omit = require('./omit.js');
|
||||||
|
|
||||||
|
test('omit is a Function', () => {
|
||||||
test('omit is a Function', () => {
|
|
||||||
expect(omit).toBeInstanceOf(Function);
|
expect(omit).toBeInstanceOf(Function);
|
||||||
});
|
});
|
||||||
test('Omits the key-value pairs corresponding to the given keys from an object', () => {
|
test('Omits the key-value pairs corresponding to the given keys from an object', () => {
|
||||||
expect(omit({ a: 1, b: '2', c: 3 }, ['b']), { 'a': 1, 'c': 3 }).toEqual()
|
expect(omit({ a: 1, b: '2', c: 3 }, ['b'])).toEqual({ 'a': 1, 'c': 3 });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1,12 +1,9 @@
|
|||||||
const expect = require('expect');
|
const expect = require('expect');
|
||||||
const omitBy = require('./omitBy.js');
|
const omitBy = require('./omitBy.js');
|
||||||
|
|
||||||
|
test('omitBy is a Function', () => {
|
||||||
test('omitBy is a Function', () => {
|
|
||||||
expect(omitBy).toBeInstanceOf(Function);
|
expect(omitBy).toBeInstanceOf(Function);
|
||||||
});
|
});
|
||||||
test('Creates an object composed of the properties the given function returns falsey for', () => {
|
test('Creates an object composed of the properties the given function returns falsey for', () => {
|
||||||
expect(omitBy({ a: 1, b: '2', c: 3 }, x => typeof x === 'number'), { b: '2' }).toEqual()
|
expect(omitBy({ a: 1, b: '2', c: 3 }, x => typeof x === 'number')).toEqual( { b: '2' });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1,10 +1,6 @@
|
|||||||
const expect = require('expect');
|
const expect = require('expect');
|
||||||
const on = require('./on.js');
|
const on = require('./on.js');
|
||||||
|
|
||||||
|
test('on is a Function', () => {
|
||||||
test('on is a Function', () => {
|
|
||||||
expect(on).toBeInstanceOf(Function);
|
expect(on).toBeInstanceOf(Function);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1,10 +1,6 @@
|
|||||||
const expect = require('expect');
|
const expect = require('expect');
|
||||||
const onUserInputChange = require('./onUserInputChange.js');
|
const onUserInputChange = require('./onUserInputChange.js');
|
||||||
|
|
||||||
|
test('onUserInputChange is a Function', () => {
|
||||||
test('onUserInputChange is a Function', () => {
|
|
||||||
expect(onUserInputChange).toBeInstanceOf(Function);
|
expect(onUserInputChange).toBeInstanceOf(Function);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1,10 +1,6 @@
|
|||||||
const expect = require('expect');
|
const expect = require('expect');
|
||||||
const once = require('./once.js');
|
const once = require('./once.js');
|
||||||
|
|
||||||
|
test('once is a Function', () => {
|
||||||
test('once is a Function', () => {
|
|
||||||
expect(once).toBeInstanceOf(Function);
|
expect(once).toBeInstanceOf(Function);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1,15 +1,13 @@
|
|||||||
const expect = require('expect');
|
const expect = require('expect');
|
||||||
const orderBy = require('./orderBy.js');
|
const orderBy = require('./orderBy.js');
|
||||||
|
|
||||||
|
test('orderBy is a Function', () => {
|
||||||
test('orderBy is a Function', () => {
|
|
||||||
expect(orderBy).toBeInstanceOf(Function);
|
expect(orderBy).toBeInstanceOf(Function);
|
||||||
});
|
});
|
||||||
const users = [{ name: 'fred', age: 48 }, { name: 'barney', age: 36 }, { name: 'fred', age: 40 }];
|
const users = [{ name: 'fred', age: 48 }, { name: 'barney', age: 36 }, { name: 'fred', age: 40 }];
|
||||||
test('Returns a sorted array of objects ordered by properties and orders.', () => {
|
test('Returns a sorted array of objects ordered by properties and orders.', () => {
|
||||||
expect(orderBy(users, ['name', 'age'], ['asc', 'desc']), [{name: 'barney', age: 36}, {name: 'fred', age: 48}, {name: 'fred').toEqual(age: 40}])
|
expect(orderBy(users, ['name', 'age'], ['asc', 'desc'])).toEqual([{name: 'barney', age: 36}, {name: 'fred', age: 48}, {name: 'fred', age: 40}]);
|
||||||
});
|
});
|
||||||
test('Returns a sorted array of objects ordered by properties and orders.', () => {
|
test('Returns a sorted array of objects ordered by properties and orders.', () => {
|
||||||
expect(orderBy(users, ['name', 'age']), [{name: 'barney', age: 36}, {name: 'fred', age: 40}, {name: 'fred').toEqual(age: 48}])
|
expect(orderBy(users, ['name', 'age'])).toEqual( [{name: 'barney', age: 36}, {name: 'fred', age: 40}, {name: 'fred', age: 48}]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -1,13 +1,10 @@
|
|||||||
const expect = require('expect');
|
const expect = require('expect');
|
||||||
const over = require('./over.js');
|
const over = require('./over.js');
|
||||||
|
|
||||||
|
test('over is a Function', () => {
|
||||||
test('over is a Function', () => {
|
|
||||||
expect(over).toBeInstanceOf(Function);
|
expect(over).toBeInstanceOf(Function);
|
||||||
});
|
});
|
||||||
const minMax = over(Math.min, Math.max);
|
const minMax = over(Math.min, Math.max);
|
||||||
test('Applies given functions over multiple arguments', () => {
|
test('Applies given functions over multiple arguments', () => {
|
||||||
expect(minMax(1, 2, 3, 4, 5), [1,5]).toEqual()
|
expect(minMax(1, 2, 3, 4, 5)).toEqual([1,5]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1,15 +1,12 @@
|
|||||||
const expect = require('expect');
|
const expect = require('expect');
|
||||||
const overArgs = require('./overArgs.js');
|
const overArgs = require('./overArgs.js');
|
||||||
|
|
||||||
|
test('overArgs is a Function', () => {
|
||||||
test('overArgs is a Function', () => {
|
|
||||||
expect(overArgs).toBeInstanceOf(Function);
|
expect(overArgs).toBeInstanceOf(Function);
|
||||||
});
|
});
|
||||||
const square = n => n * n;
|
const square = n => n * n;
|
||||||
const double = n => n * 2;
|
const double = n => n * 2;
|
||||||
const fn = overArgs((x, y) => [x, y], [square, double]);
|
const fn = overArgs((x, y) => [x, y], [square, double]);
|
||||||
test('Invokes the provided function with its arguments transformed', () => {
|
test('Invokes the provided function with its arguments transformed', () => {
|
||||||
expect(fn(9, 3), [81, 6]).toEqual()
|
expect(fn(9, 3)).toEqual([81, 6]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1,21 +1,18 @@
|
|||||||
const expect = require('expect');
|
const expect = require('expect');
|
||||||
const pad = require('./pad.js');
|
const pad = require('./pad.js');
|
||||||
|
|
||||||
|
test('pad is a Function', () => {
|
||||||
test('pad is a Function', () => {
|
|
||||||
expect(pad).toBeInstanceOf(Function);
|
expect(pad).toBeInstanceOf(Function);
|
||||||
});
|
});
|
||||||
test('cat is padded on both sides', () => {
|
test('cat is padded on both sides', () => {
|
||||||
expect(pad('cat',8), ' cat ').toBe()
|
expect(pad('cat',8)).toBe(' cat ');
|
||||||
});
|
});
|
||||||
test('length of string is 8', () => {
|
test('length of string is 8', () => {
|
||||||
expect(pad('cat',8).length, 8).toBe()
|
expect(pad('cat',8).length).toBe(8);
|
||||||
});
|
});
|
||||||
test('pads 42 with "0"', () => {
|
test('pads 42 with "0"', () => {
|
||||||
expect(pad(String(42), 6, '0'), '004200').toBe()
|
expect(pad(String(42), 6, '0')).toBe('004200');
|
||||||
});
|
});
|
||||||
test('does not truncates if string exceeds length', () => {
|
test('does not truncates if string exceeds length', () => {
|
||||||
expect(pad('foobar', 3), 'foobar').toBe()
|
expect(pad('foobar', 3)).toBe('foobar');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1,14 +1,12 @@
|
|||||||
const expect = require('expect');
|
const expect = require('expect');
|
||||||
const palindrome = require('./palindrome.js');
|
const palindrome = require('./palindrome.js');
|
||||||
|
|
||||||
|
test('palindrome is a Function', () => {
|
||||||
test('palindrome is a Function', () => {
|
|
||||||
expect(palindrome).toBeInstanceOf(Function);
|
expect(palindrome).toBeInstanceOf(Function);
|
||||||
});
|
});
|
||||||
test('Given string is a palindrome', () => {
|
test('Given string is a palindrome', () => {
|
||||||
expect(palindrome('taco cat')).toBe(true)
|
expect(palindrome('taco cat')).toBeTruthy();
|
||||||
});
|
});
|
||||||
test('Given string is not a palindrome', () => {
|
test('Given string is not a palindrome', () => {
|
||||||
expect(palindrome('foobar')).toBe(false)
|
expect(palindrome('foobar')).toBeFalsy();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -1,12 +1,9 @@
|
|||||||
const expect = require('expect');
|
const expect = require('expect');
|
||||||
const parseCookie = require('./parseCookie.js');
|
const parseCookie = require('./parseCookie.js');
|
||||||
|
|
||||||
|
test('parseCookie is a Function', () => {
|
||||||
test('parseCookie is a Function', () => {
|
|
||||||
expect(parseCookie).toBeInstanceOf(Function);
|
expect(parseCookie).toBeInstanceOf(Function);
|
||||||
});
|
});
|
||||||
test('Parses the cookie', () => {
|
test('Parses the cookie', () => {
|
||||||
expect(parseCookie('foo=bar; equation=E%3Dmc%5E2'), { foo: 'bar', equation: 'E=mc^2' }).toEqual()
|
expect(parseCookie('foo=bar; equation=E%3Dmc%5E2')).toEqual({ foo: 'bar', equation: 'E=mc^2' });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1,16 +1,13 @@
|
|||||||
const expect = require('expect');
|
const expect = require('expect');
|
||||||
const partial = require('./partial.js');
|
const partial = require('./partial.js');
|
||||||
|
|
||||||
|
test('partial is a Function', () => {
|
||||||
test('partial is a Function', () => {
|
|
||||||
expect(partial).toBeInstanceOf(Function);
|
expect(partial).toBeInstanceOf(Function);
|
||||||
});
|
});
|
||||||
function greet(greeting, name) {
|
function greet(greeting, name) {
|
||||||
return greeting + ' ' + name + '!';
|
return greeting + ' ' + name + '!';
|
||||||
}
|
}
|
||||||
const greetHello = partial(greet, 'Hello');
|
const greetHello = partial(greet, 'Hello');
|
||||||
test('Prepends arguments', () => {
|
test('Prepends arguments', () => {
|
||||||
expect(greetHello('John'), 'Hello John!').toBe()
|
expect(greetHello('John')).toBe('Hello John!');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1,16 +1,13 @@
|
|||||||
const expect = require('expect');
|
const expect = require('expect');
|
||||||
const partialRight = require('./partialRight.js');
|
const partialRight = require('./partialRight.js');
|
||||||
|
|
||||||
|
test('partialRight is a Function', () => {
|
||||||
test('partialRight is a Function', () => {
|
|
||||||
expect(partialRight).toBeInstanceOf(Function);
|
expect(partialRight).toBeInstanceOf(Function);
|
||||||
});
|
});
|
||||||
function greet(greeting, name) {
|
function greet(greeting, name) {
|
||||||
return greeting + ' ' + name + '!';
|
return greeting + ' ' + name + '!';
|
||||||
}
|
}
|
||||||
const greetJohn = partialRight(greet, 'John');
|
const greetJohn = partialRight(greet, 'John');
|
||||||
test('Appends arguments', () => {
|
test('Appends arguments', () => {
|
||||||
expect(greetJohn('Hello'), 'Hello John!').toBe()
|
expect(greetJohn('Hello')).toBe('Hello John!');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1,12 +1,10 @@
|
|||||||
const expect = require('expect');
|
const expect = require('expect');
|
||||||
const partition = require('./partition.js');
|
const partition = require('./partition.js');
|
||||||
|
|
||||||
|
test('partition is a Function', () => {
|
||||||
test('partition is a Function', () => {
|
|
||||||
expect(partition).toBeInstanceOf(Function);
|
expect(partition).toBeInstanceOf(Function);
|
||||||
});
|
});
|
||||||
const users = [{ user: 'barney', age: 36, active: false }, { user: 'fred', age: 40, active: true }];
|
const users = [{ user: 'barney', age: 36, active: false }, { user: 'fred', age: 40, active: true }];
|
||||||
test('Groups the elements into two arrays, depending on the provided function's truthiness for each element.', () => {
|
test('Groups the elements into two arrays, depending on the provided function\'s truthiness for each element.', () => {
|
||||||
expect(partition(users, o => o.active), [[{ 'user': 'fred', 'age': 40, 'active': true }],[{ 'user': 'barney', 'age': 36).toEqual('active': false }]])
|
expect(partition(users, o => o.active)).toEqual([[{ 'user': 'fred', 'age': 40, 'active': true }],[{ 'user': 'barney', 'age': 36, 'active': false }]]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -1,11 +1,9 @@
|
|||||||
const expect = require('expect');
|
const expect = require('expect');
|
||||||
const percentile = require('./percentile.js');
|
const percentile = require('./percentile.js');
|
||||||
|
|
||||||
|
test('percentile is a Function', () => {
|
||||||
test('percentile is a Function', () => {
|
|
||||||
expect(percentile).toBeInstanceOf(Function);
|
expect(percentile).toBeInstanceOf(Function);
|
||||||
});
|
});
|
||||||
test('Uses the percentile formula to calculate how many numbers in the given array are less or equal to the given value.', () => {
|
test('Uses the percentile formula to calculate how many numbers in the given array are less or equal to the given value.', () => {
|
||||||
expect(percentile([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 6)).toBe(55)
|
expect(percentile([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 6)).toBe(55);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -1,12 +1,9 @@
|
|||||||
const expect = require('expect');
|
const expect = require('expect');
|
||||||
const permutations = require('./permutations.js');
|
const permutations = require('./permutations.js');
|
||||||
|
|
||||||
|
test('permutations is a Function', () => {
|
||||||
test('permutations is a Function', () => {
|
|
||||||
expect(permutations).toBeInstanceOf(Function);
|
expect(permutations).toBeInstanceOf(Function);
|
||||||
});
|
});
|
||||||
test('Generates all permutations of an array', () => {
|
test('Generates all permutations of an array', () => {
|
||||||
expect(permutations([1, 33, 5]), [ [ 1, 33, 5 ], [ 1, 5, 33 ], [ 33, 1, 5 ], [ 33, 5, 1 ], [ 5, 1, 33 ], [ 5, 33, 1 ] ]).toEqual()
|
expect(permutations([1, 33, 5])).toEqual([ [ 1, 33, 5 ], [ 1, 5, 33 ], [ 33, 1, 5 ], [ 33, 5, 1 ], [ 5, 1, 33 ], [ 5, 33, 1 ] ]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1,11 +1,9 @@
|
|||||||
const expect = require('expect');
|
const expect = require('expect');
|
||||||
const pick = require('./pick.js');
|
const pick = require('./pick.js');
|
||||||
|
|
||||||
|
test('pick is a Function', () => {
|
||||||
test('pick is a Function', () => {
|
|
||||||
expect(pick).toBeInstanceOf(Function);
|
expect(pick).toBeInstanceOf(Function);
|
||||||
});
|
});
|
||||||
test('Picks the key-value pairs corresponding to the given keys from an object.', () => {
|
test('Picks the key-value pairs corresponding to the given keys from an object.', () => {
|
||||||
expect(pick({ a: 1, b: '2', c: 3 }, ['a', 'c']), { 'a': 1).toEqual('c': 3 })
|
expect(pick({ a: 1, b: '2', c: 3 }, ['a', 'c'])).toEqual({ 'a': 1, 'c': 3 });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -1,12 +1,9 @@
|
|||||||
const expect = require('expect');
|
const expect = require('expect');
|
||||||
const pickBy = require('./pickBy.js');
|
const pickBy = require('./pickBy.js');
|
||||||
|
|
||||||
|
test('pickBy is a Function', () => {
|
||||||
test('pickBy is a Function', () => {
|
|
||||||
expect(pickBy).toBeInstanceOf(Function);
|
expect(pickBy).toBeInstanceOf(Function);
|
||||||
});
|
});
|
||||||
test('Creates an object composed of the properties the given function returns truthy for.', () => {
|
test('Creates an object composed of the properties the given function returns truthy for.', () => {
|
||||||
expect(pickBy({ a: 1, b: '2', c: 3 }, x => typeof x === 'number'), { 'a': 1, 'c': 3 }).toEqual()
|
expect(pickBy({ a: 1, b: '2', c: 3 }, x => typeof x === 'number')).toEqual({ 'a': 1, 'c': 3 });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1,19 +1,15 @@
|
|||||||
const expect = require('expect');
|
const expect = require('expect');
|
||||||
const pipeAsyncFunctions = require('./pipeAsyncFunctions.js');
|
const pipeAsyncFunctions = require('./pipeAsyncFunctions.js');
|
||||||
|
|
||||||
|
test('pipeAsyncFunctions is a Function', () => {
|
||||||
test('pipeAsyncFunctions is a Function', () => {
|
|
||||||
expect(pipeAsyncFunctions).toBeInstanceOf(Function);
|
expect(pipeAsyncFunctions).toBeInstanceOf(Function);
|
||||||
});
|
});
|
||||||
t.equal(
|
test('pipeAsyncFunctions result should be 15', () => {
|
||||||
await pipeAsyncFunctions(
|
expect(await pipeAsyncFunctions(
|
||||||
(x) => x + 1,
|
(x) => x + 1,
|
||||||
(x) => new Promise((resolve) => setTimeout(() => resolve(x + 2), 0)),
|
(x) => new Promise((resolve) => setTimeout(() => resolve(x + 2), 0)),
|
||||||
(x) => x + 3,
|
(x) => x + 3,
|
||||||
async (x) => await x + 4,
|
async (x) => await x + 4,
|
||||||
)
|
)
|
||||||
(5),
|
(5)).toBe(15);
|
||||||
15,
|
});
|
||||||
'pipeAsyncFunctions result should be 15'
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|||||||
@ -1,15 +1,12 @@
|
|||||||
const expect = require('expect');
|
const expect = require('expect');
|
||||||
const pipeFunctions = require('./pipeFunctions.js');
|
const pipeFunctions = require('./pipeFunctions.js');
|
||||||
|
|
||||||
|
test('pipeFunctions is a Function', () => {
|
||||||
test('pipeFunctions is a Function', () => {
|
|
||||||
expect(pipeFunctions).toBeInstanceOf(Function);
|
expect(pipeFunctions).toBeInstanceOf(Function);
|
||||||
});
|
});
|
||||||
const add5 = x => x + 5;
|
const add5 = x => x + 5;
|
||||||
const multiply = (x, y) => x * y;
|
const multiply = (x, y) => x * y;
|
||||||
const multiplyAndAdd5 = pipeFunctions(multiply, add5);
|
const multiplyAndAdd5 = pipeFunctions(multiply, add5);
|
||||||
test('Performs left-to-right function composition', () => {
|
test('Performs left-to-right function composition', () => {
|
||||||
expect(multiplyAndAdd5(5, 2), 15).toBe()
|
expect(multiplyAndAdd5(5, 2)).toBe(15);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1,29 +1,26 @@
|
|||||||
const expect = require('expect');
|
const expect = require('expect');
|
||||||
const pluralize = require('./pluralize.js');
|
const pluralize = require('./pluralize.js');
|
||||||
|
|
||||||
|
test('pluralize is a Function', () => {
|
||||||
test('pluralize is a Function', () => {
|
|
||||||
expect(pluralize).toBeInstanceOf(Function);
|
expect(pluralize).toBeInstanceOf(Function);
|
||||||
});
|
});
|
||||||
test('Produces the plural of the word', () => {
|
test('Produces the plural of the word', () => {
|
||||||
expect(pluralize(0, 'apple'), 'apples').toBe()
|
expect(pluralize(0, 'apple')).toBe('apples');
|
||||||
});
|
});
|
||||||
test('Produces the singular of the word', () => {
|
test('Produces the singular of the word', () => {
|
||||||
expect(pluralize(1, 'apple'), 'apple').toBe()
|
expect(pluralize(1, 'apple')).toBe('apple');
|
||||||
});
|
});
|
||||||
test('Produces the plural of the word', () => {
|
test('Produces the plural of the word', () => {
|
||||||
expect(pluralize(2, 'apple'), 'apples').toBe()
|
expect(pluralize(2, 'apple')).toBe('apples');
|
||||||
});
|
});
|
||||||
test('Prodices the defined plural of the word', () => {
|
test('Prodices the defined plural of the word', () => {
|
||||||
expect(pluralize(2, 'person', 'people'), 'people').toBe()
|
expect(pluralize(2, 'person', 'people')).toBe('people');
|
||||||
});
|
});
|
||||||
const PLURALS = {
|
const PLURALS = {
|
||||||
person: 'people',
|
person: 'people',
|
||||||
radius: 'radii'
|
radius: 'radii'
|
||||||
};
|
};
|
||||||
const autoPluralize = pluralize(PLURALS);
|
const autoPluralize = pluralize(PLURALS);
|
||||||
test('Works with a dictionary', () => {
|
test('Works with a dictionary', () => {
|
||||||
expect(autoPluralize(2, 'person'), 'people').toBe()
|
expect(autoPluralize(2, 'person')).toBe('people');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1,11 +1,9 @@
|
|||||||
const expect = require('expect');
|
const expect = require('expect');
|
||||||
const powerset = require('./powerset.js');
|
const powerset = require('./powerset.js');
|
||||||
|
|
||||||
|
test('powerset is a Function', () => {
|
||||||
test('powerset is a Function', () => {
|
|
||||||
expect(powerset).toBeInstanceOf(Function);
|
expect(powerset).toBeInstanceOf(Function);
|
||||||
});
|
});
|
||||||
test('Returns the powerset of a given array of numbers.', () => {
|
test('Returns the powerset of a given array of numbers.', () => {
|
||||||
expect(powerset([1, 2]), [[], [1], [2], [2).toEqual(1]])
|
expect(powerset([1, 2])).toEqual([[], [1], [2], [2, 1]]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -1,8 +1,6 @@
|
|||||||
const expect = require('expect');
|
const expect = require('expect');
|
||||||
const prefix = require('./prefix.js');
|
const prefix = require('./prefix.js');
|
||||||
|
|
||||||
|
test('prefix is a Function', () => {
|
||||||
test('prefix is a Function', () => {
|
|
||||||
expect(prefix).toBeInstanceOf(Function);
|
expect(prefix).toBeInstanceOf(Function);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -1,17 +1,15 @@
|
|||||||
const expect = require('expect');
|
const expect = require('expect');
|
||||||
const prettyBytes = require('./prettyBytes.js');
|
const prettyBytes = require('./prettyBytes.js');
|
||||||
|
|
||||||
|
test('prettyBytes is a Function', () => {
|
||||||
test('prettyBytes is a Function', () => {
|
|
||||||
expect(prettyBytes).toBeInstanceOf(Function);
|
expect(prettyBytes).toBeInstanceOf(Function);
|
||||||
});
|
});
|
||||||
test('Converts a number in bytes to a human-readable string.', () => {
|
test('Converts a number in bytes to a human-readable string.', () => {
|
||||||
expect(prettyBytes(1000)).toBe('1 KB')
|
expect(prettyBytes(1000)).toBe('1 KB');
|
||||||
});
|
});
|
||||||
test('Converts a number in bytes to a human-readable string.', () => {
|
test('Converts a number in bytes to a human-readable string.', () => {
|
||||||
expect(prettyBytes(-27145424323.5821, 5)).toBe('-27.145 GB')
|
expect(prettyBytes(-27145424323.5821, 5)).toBe('-27.145 GB');
|
||||||
});
|
});
|
||||||
test('Converts a number in bytes to a human-readable string.', () => {
|
test('Converts a number in bytes to a human-readable string.', () => {
|
||||||
expect(prettyBytes(123456789, 3, false)).toBe('123MB')
|
expect(prettyBytes(123456789, 3, false)).toBe('123MB');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -1,11 +1,9 @@
|
|||||||
const expect = require('expect');
|
const expect = require('expect');
|
||||||
const primes = require('./primes.js');
|
const primes = require('./primes.js');
|
||||||
|
|
||||||
|
test('primes is a Function', () => {
|
||||||
test('primes is a Function', () => {
|
|
||||||
expect(primes).toBeInstanceOf(Function);
|
expect(primes).toBeInstanceOf(Function);
|
||||||
});
|
});
|
||||||
test('Generates primes up to a given number, using the Sieve of Eratosthenes.', () => {
|
test('Generates primes up to a given number, using the Sieve of Eratosthenes.', () => {
|
||||||
expect(primes(10), [2, 3, 5).toEqual(7])
|
expect(primes(10)).toEqual([2, 3, 5, 7]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -1,15 +1,14 @@
|
|||||||
const expect = require('expect');
|
const expect = require('expect');
|
||||||
const promisify = require('./promisify.js');
|
const promisify = require('./promisify.js');
|
||||||
|
|
||||||
|
test('promisify is a Function', () => {
|
||||||
test('promisify is a Function', () => {
|
|
||||||
expect(promisify).toBeInstanceOf(Function);
|
expect(promisify).toBeInstanceOf(Function);
|
||||||
});
|
});
|
||||||
const x = promisify(Math.max);
|
const x = promisify(Math.max);
|
||||||
test('Returns a promise', () => {
|
test('Returns a promise', () => {
|
||||||
expect(x() instanceof Promise).toBeTruthy();
|
expect(x() instanceof Promise).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
test('Runs the function provided', () => {
|
||||||
const delay = promisify((d, cb) => setTimeout(cb, d));
|
const delay = promisify((d, cb) => setTimeout(cb, d));
|
||||||
delay(200).then(() =>
|
delay(200).then(() => expect(true).toBeTruthy());
|
||||||
|
});
|
||||||
|
|
||||||
|
|||||||
@ -1,14 +1,11 @@
|
|||||||
const expect = require('expect');
|
const expect = require('expect');
|
||||||
const pull = require('./pull.js');
|
const pull = require('./pull.js');
|
||||||
|
|
||||||
|
test('pull is a Function', () => {
|
||||||
test('pull is a Function', () => {
|
|
||||||
expect(pull).toBeInstanceOf(Function);
|
expect(pull).toBeInstanceOf(Function);
|
||||||
});
|
});
|
||||||
let myArray = ['a', 'b', 'c', 'a', 'b', 'c'];
|
let myArray = ['a', 'b', 'c', 'a', 'b', 'c'];
|
||||||
pull(myArray, 'a', 'c');
|
pull(myArray, 'a', 'c');
|
||||||
test('Pulls the specified values', () => {
|
test('Pulls the specified values', () => {
|
||||||
expect(myArray, ['b','b']).toEqual()
|
expect(myArray).toEqual(['b','b'])
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1,17 +1,14 @@
|
|||||||
const expect = require('expect');
|
const expect = require('expect');
|
||||||
const pullAtIndex = require('./pullAtIndex.js');
|
const pullAtIndex = require('./pullAtIndex.js');
|
||||||
|
|
||||||
|
test('pullAtIndex is a Function', () => {
|
||||||
test('pullAtIndex is a Function', () => {
|
|
||||||
expect(pullAtIndex).toBeInstanceOf(Function);
|
expect(pullAtIndex).toBeInstanceOf(Function);
|
||||||
});
|
});
|
||||||
let myArray = ['a', 'b', 'c', 'd'];
|
let myArray = ['a', 'b', 'c', 'd'];
|
||||||
let pulled = pullAtIndex(myArray, [1, 3]);
|
let pulled = pullAtIndex(myArray, [1, 3]);
|
||||||
test('Pulls the given values', () => {
|
test('Pulls the given values', () => {
|
||||||
expect(myArray, [ 'a', 'c' ]).toEqual()
|
expect(myArray).toEqual([ 'a', 'c' ]);
|
||||||
});
|
});
|
||||||
test('Pulls the given values', () => {
|
test('Pulls the given values', () => {
|
||||||
expect(pulled, [ 'b', 'd' ]).toEqual()
|
expect(pulled).toEqual([ 'b', 'd' ]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1,17 +1,14 @@
|
|||||||
const expect = require('expect');
|
const expect = require('expect');
|
||||||
const pullAtValue = require('./pullAtValue.js');
|
const pullAtValue = require('./pullAtValue.js');
|
||||||
|
|
||||||
|
test('pullAtValue is a Function', () => {
|
||||||
test('pullAtValue is a Function', () => {
|
|
||||||
expect(pullAtValue).toBeInstanceOf(Function);
|
expect(pullAtValue).toBeInstanceOf(Function);
|
||||||
});
|
});
|
||||||
let myArray = ['a', 'b', 'c', 'd'];
|
let myArray = ['a', 'b', 'c', 'd'];
|
||||||
let pulled = pullAtValue(myArray, ['b', 'd']);
|
let pulled = pullAtValue(myArray, ['b', 'd']);
|
||||||
test('Pulls the specified values', () => {
|
test('Pulls the specified values', () => {
|
||||||
expect(myArray, [ 'a', 'c' ]).toEqual()
|
expect(myArray).toEqual([ 'a', 'c' ]);
|
||||||
});
|
});
|
||||||
test('Pulls the specified values', () => {
|
test('Pulls the specified values', () => {
|
||||||
expect(pulled, [ 'b', 'd' ]).toEqual()
|
expect(pulled).toEqual([ 'b', 'd' ]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1,14 +1,11 @@
|
|||||||
const expect = require('expect');
|
const expect = require('expect');
|
||||||
const pullBy = require('./pullBy.js');
|
const pullBy = require('./pullBy.js');
|
||||||
|
|
||||||
|
test('pullBy is a Function', () => {
|
||||||
test('pullBy is a Function', () => {
|
|
||||||
expect(pullBy).toBeInstanceOf(Function);
|
expect(pullBy).toBeInstanceOf(Function);
|
||||||
});
|
});
|
||||||
var myArray = [{ x: 1 }, { x: 2 }, { x: 3 }, { x: 1 }];
|
var myArray = [{ x: 1 }, { x: 2 }, { x: 3 }, { x: 1 }];
|
||||||
pullBy(myArray, [{ x: 1 }, { x: 3 }], o => o.x);
|
pullBy(myArray, [{ x: 1 }, { x: 3 }], o => o.x);
|
||||||
test('Pulls the specified values', () => {
|
test('Pulls the specified values', () => {
|
||||||
expect(myArray, [{ x: 2 }]).toEqual()
|
expect(myArray).toEqual([{ x: 2 }]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user