Test cleanup and fixes [a-b]

This commit is contained in:
Angelos Chalaris
2018-06-18 15:54:48 +03:00
parent a78f5db260
commit 026c65a5e6
151 changed files with 753 additions and 373 deletions

View File

@ -5,6 +5,6 @@ const JSONToFile = require('./JSONToFile.js');
test('JSONToFile is a Function', () => {
expect(JSONToFile).toBeInstanceOf(Function);
});
t.pass('Tested on 09/02/2018 by @chalarangelo');

View File

@ -5,6 +5,6 @@ const UUIDGeneratorBrowser = require('./UUIDGeneratorBrowser.js');
test('UUIDGeneratorBrowser is a Function', () => {
expect(UUIDGeneratorBrowser).toBeInstanceOf(Function);
});
t.pass('Tested 09/02/2018 by @chalarangelo');

View File

@ -6,7 +6,9 @@ const UUIDGeneratorNode = require('./UUIDGeneratorNode.js');
expect(UUIDGeneratorNode).toBeInstanceOf(Function);
});
const uuid = UUIDGeneratorNode();
t.deepEqual([uuid[8], uuid[13], uuid[18], uuid[23]], ['-', '-', '-', '-'], 'Contains dashes in the proper places');
test('Contains dashes in the proper places', () => {
expect([uuid[8], uuid[13], uuid[18], uuid[23]], ['-', '-', '-', '-']).toEqual()
});
test('Only contains hexadecimal digits', () => {
expect(/^[0-9A-Fa-f-]+$/.test(uuid)).toBeTruthy();
});

View File

@ -1,21 +1,18 @@
const expect = require('expect');
const approximatelyEqual = require('./approximatelyEqual.js');
test('approximatelyEqual is a Function', () => {
test('approximatelyEqual is a Function', () => {
expect(approximatelyEqual).toBeInstanceOf(Function);
});
test('Works for PI / 2', () => {
test('Works for PI / 2', () => {
expect(approximatelyEqual(Math.PI / 2.0 , 1.5708)).toBeTruthy();
});
test('Works for 0.1 + 0.2 === 0.3', () => {
test('Works for 0.1 + 0.2 === 0.3', () => {
expect(approximatelyEqual(0.1 + 0.2, 0.3)).toBeTruthy();
});
test('Works for exactly equal values', () => {
test('Works for exactly equal values', () => {
expect(approximatelyEqual(0.5, 0.5)).toBeTruthy();
});
test('Works for a custom epsilon', () => {
test('Works for a custom epsilon', () => {
expect(approximatelyEqual(0.501, 0.5, 0.1)).toBeTruthy();
});

View File

@ -1,10 +1,6 @@
const expect = require('expect');
const arrayToHtmlList = require('./arrayToHtmlList.js');
test('arrayToHtmlList is a Function', () => {
test('arrayToHtmlList is a Function', () => {
expect(arrayToHtmlList).toBeInstanceOf(Function);
});
t.pass('Tested by @chalarangelo on 16/02/2018');

View File

@ -1,13 +1,10 @@
const expect = require('expect');
const ary = require('./ary.js');
test('ary is a Function', () => {
test('ary is a Function', () => {
expect(ary).toBeInstanceOf(Function);
});
const firstTwoMax = ary(Math.max, 2);
test('Discards arguments with index >=n', () => {
expect([[2, 6, 'a'], [8, 4, 6], [10]].map(x => firstTwoMax(...x)), [6, 8, 10]).toEqual()
const firstTwoMax = ary(Math.max, 2);
test('Discards arguments with index >=n', () => {
expect([[2, 6, 'a'], [8, 4, 6], [10]].map(x => firstTwoMax(...x))).toEqual([6, 8, 10]);
});

View File

@ -1,15 +1,12 @@
const expect = require('expect');
const atob = require('./atob.js');
test('atob is a Function', () => {
test('atob is a Function', () => {
expect(atob).toBeInstanceOf(Function);
});
test('atob("Zm9vYmFy") equals "foobar"', () => {
expect(atob('Zm9vYmFy'), 'foobar').toBe()
test('atob("Zm9vYmFy") equals "foobar"', () => {
expect(atob('Zm9vYmFy')).toBe('foobar');
});
test('atob("Z") returns ""', () => {
expect(atob('Z'), '').toBe()
test('atob("Z") returns ""', () => {
expect(atob('Z')).toBe('');
});

View File

@ -1,15 +1,12 @@
const expect = require('expect');
const attempt = require('./attempt.js');
test('attempt is a Function', () => {
test('attempt is a Function', () => {
expect(attempt).toBeInstanceOf(Function);
});
test('Returns a value', () => {
expect(attempt(() => 0), 0).toBe()
test('Returns a value', () => {
expect(attempt(() => 0)).toBe(0);
});
test('Returns an error', () => {
expect(attempt(() => {throw new Error();}) instanceof Error).toBeTruthy();
test('Returns an error', () => {
expect(attempt(() => {throw new Error();})).toBeInstanceOf(Error);
});

View File

@ -1,37 +1,43 @@
const expect = require('expect');
const average = require('./average.js');
test('average is a Function', () => {
test('average is a Function', () => {
expect(average).toBeInstanceOf(Function);
});
test('average(true) returns 0', () => {
test('average(true) returns 0', () => {
expect(average(true) === 1).toBeTruthy();
});
test('average(false) returns 1', () => {
test('average(false) returns 1', () => {
expect(average(false) === 0).toBeTruthy();
});
t.equal(average(9, 1), 5, 'average(9, 1) returns 5');
t.equal(average(153, 44, 55, 64, 71, 1122, 322774, 2232, 23423, 234, 3631), 32163.909090909092, 'average(153, 44, 55, 64, 71, 1122, 322774, 2232, 23423, 234, 3631) returns 32163.909090909092 ');
t.equal(average(1, 2, 3), 2, 'average(1, 2, 3) returns 2');
t.equal(average(null), 0, 'average(null) returns 0');
test('average(1, 2, 3) returns NaN', () => {
test('average(9, 1) returns 5', () => {
expect(average(9, 1)).toBe(5);
});
test('average(153, 44, 55, 64, 71, 1122, 322774, 2232, 23423, 234, 3631) returns 32163.909090909092 ', () => {
expect(average(153, 44, 55, 64, 71, 1122, 322774, 2232, 23423, 234, 3631)).toBeCloseTo(32163.909090909092, 3);
});
test('average(1, 2, 3) returns 2', () => {
expect(average(1, 2, 3)).toBe(2);
});
test('average(null) returns 0', () => {
expect(average(null)).toBe(0);
});
test('average(1, 2, 3) returns NaN', () => {
expect(isNaN(average(undefined))).toBeTruthy();
});
test('average(String) returns NaN', () => {
test('average(String) returns NaN', () => {
expect(isNaN(average('String'))).toBeTruthy();
});
test('average({ a: 123}) returns NaN', () => {
test('average({ a: 123}) returns NaN', () => {
expect(isNaN(average({ a: 123}))).toBeTruthy();
});
test('average([undefined, 0, string]) returns NaN', () => {
test('average([undefined, 0, string]) returns NaN', () => {
expect(isNaN(average([undefined, 0, 'string']))).toBeTruthy();
});
let start = new Date().getTime();
average(153, 44, 55, 64, 71, 1122, 322774, 2232, 23423, 234, 3631);
let end = new Date().getTime();
test('average([1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 1122, 32124, 23232]) takes less than 2s to run', () => {
let start = new Date().getTime();
average(153, 44, 55, 64, 71, 1122, 322774, 2232, 23423, 234, 3631);
let end = new Date().getTime();
test('average([1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 1122, 32124, 23232]) takes less than 2s to run', () => {
expect((end - start) < 2000).toBeTruthy();
});

View File

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

View File

@ -1,10 +1,9 @@
const expect = require('expect');
const bifurcate = require('./bifurcate.js');
test('bifurcate is a Function', () => {
test('bifurcate is a Function', () => {
expect(bifurcate).toBeInstanceOf(Function);
});
t.deepEqual(bifurcate([ 'beep', 'boop', 'foo', 'bar' ], [ true, true, false, true ]), [ ['beep', 'boop', 'bar'], ['foo'] ], 'Splits the collection into two groups');
test('Splits the collection into two groups', () => {
expect(bifurcate([ 'beep', 'boop', 'foo', 'bar' ], [ true, true, false, true ])).toEqual([ ['beep', 'boop', 'bar'], ['foo'] ]);
});

View File

@ -1,10 +1,9 @@
const expect = require('expect');
const bifurcateBy = require('./bifurcateBy.js');
test('bifurcateBy is a Function', () => {
test('bifurcateBy is a Function', () => {
expect(bifurcateBy).toBeInstanceOf(Function);
});
t.deepEqual(bifurcateBy([ 'beep', 'boop', 'foo', 'bar' ], x => x[0] === 'b'), [ ['beep', 'boop', 'bar'], ['foo'] ], 'Splits the collection into two groups');
test('Splits the collection into two groups', () => {
expect(bifurcateBy([ 'beep', 'boop', 'foo', 'bar' ], x => x[0] === 'b')).toEqual([ ['beep', 'boop', 'bar'], ['foo'] ]);
});

View File

@ -1,12 +1,18 @@
const expect = require('expect');
const binarySearch = require('./binarySearch.js');
test('binarySearch is a Function', () => {
test('binarySearch is a Function', () => {
expect(binarySearch).toBeInstanceOf(Function);
});
t.equal(binarySearch([1, 4, 6, 7, 12, 13, 15, 18, 19, 20, 22, 24], 6), 2, 'Finds item in array');
t.equal(binarySearch([1, 4, 6, 7, 12, 13, 15, 18, 19, 20, 22, 24], 21), -1, 'Returns -1 when not found');
t.equal(binarySearch([], 21), -1, 'Works with empty arrays');
t.equal(binarySearch([1], 1), 0, "Works for one element arrays");
test('Finds item in array', () => {
expect(binarySearch([1, 4, 6, 7, 12, 13, 15, 18, 19, 20, 22, 24], 6)).toBe(2);
});
test('Returns -1 when not found', () => {
expect(binarySearch([1, 4, 6, 7, 12, 13, 15, 18, 19, 20, 22, 24], 21)).toBe(-1);
});
test('Works with empty arrays', () => {
expect(binarySearch([], 21)).toBe(-1)
});
test('Works for one element arrays', () => {
expect(binarySearch([1], 1)).toBe(0);
});

View File

@ -1,17 +1,14 @@
const expect = require('expect');
const bind = require('./bind.js');
test('bind is a Function', () => {
test('bind is a Function', () => {
expect(bind).toBeInstanceOf(Function);
});
function greet(greeting, punctuation) {
return greeting + ' ' + this.user + punctuation;
}
const freddy = { user: 'fred' };
const freddyBound = bind(greet, freddy);
test('Binds to an object context', () => {
expect(freddyBound('hi', '!'),'hi fred!').toBe()
function greet(greeting, punctuation) {
return greeting + ' ' + this.user + punctuation;
}
const freddy = { user: 'fred' };
const freddyBound = bind(greet, freddy);
test('Binds to an object context', () => {
expect(freddyBound('hi', '!')).toBe('hi fred!');
});

View File

@ -1,17 +1,16 @@
const expect = require('expect');
const bindAll = require('./bindAll.js');
test('bindAll is a Function', () => {
test('bindAll is a Function', () => {
expect(bindAll).toBeInstanceOf(Function);
});
var view = {
label: 'docs',
'click': function() {
return 'clicked ' + this.label;
}
};
bindAll(view, 'click');
t.equal(view.click(), 'clicked docs', 'Binds to an object context');
var view = {
label: 'docs',
'click': function() {
return 'clicked ' + this.label;
}
};
bindAll(view, 'click');
test('Binds to an object context', () => {
expect(view.click()).toBe('clicked docs')
});

View File

@ -1,17 +1,16 @@
const expect = require('expect');
const bindKey = require('./bindKey.js');
test('bindKey is a Function', () => {
test('bindKey is a Function', () => {
expect(bindKey).toBeInstanceOf(Function);
});
const freddy = {
user: 'fred',
greet: function(greeting, punctuation) {
return greeting + ' ' + this.user + punctuation;
}
};
const freddyBound = bindKey(freddy, 'greet');
t.equal(freddyBound('hi', '!'), 'hi fred!', 'Binds function to an object context');
const freddy = {
user: 'fred',
greet: function(greeting, punctuation) {
return greeting + ' ' + this.user + punctuation;
}
};
const freddyBound = bindKey(freddy, 'greet');
test('Binds function to an object context', () => {
expect(freddyBound('hi', '!')).toBe('hi fred!')
});

View File

@ -1,18 +1,21 @@
const expect = require('expect');
const binomialCoefficient = require('./binomialCoefficient.js');
test('binomialCoefficient is a Function', () => {
test('binomialCoefficient is a Function', () => {
expect(binomialCoefficient).toBeInstanceOf(Function);
});
t.equal(binomialCoefficient(8, 2), 28, 'Returns the appropriate value');
t.equal(binomialCoefficient(0, 0), 1, 'Returns the appropriate value');
t.equal(binomialCoefficient(5, 3), 10, 'Returns the appropriate value');
test('Returns NaN', () => {
test('Returns the appropriate value', () => {
expect(binomialCoefficient(8, 2)).toBe(28);
});
test('Returns the appropriate value', () => {
expect(binomialCoefficient(0, 0)).toBe(1);
});
test('Returns the appropriate value', () => {
expect(binomialCoefficient(5, 3)).toBe(10);
});
test('Returns NaN', () => {
expect(Number.isNaN(binomialCoefficient(NaN, 3))).toBeTruthy();
});
test('Returns NaN', () => {
test('Returns NaN', () => {
expect(Number.isNaN(binomialCoefficient(5, NaN))).toBeTruthy();
});

View File

@ -1,10 +1,6 @@
const expect = require('expect');
const bottomVisible = require('./bottomVisible.js');
test('bottomVisible is a Function', () => {
test('bottomVisible is a Function', () => {
expect(bottomVisible).toBeInstanceOf(Function);
});
t.pass('Tested on 09/02/2018 by @chalarangelo');

View File

@ -1,12 +1,9 @@
const expect = require('expect');
const btoa = require('./btoa.js');
test('btoa is a Function', () => {
test('btoa is a Function', () => {
expect(btoa).toBeInstanceOf(Function);
});
test('btoa("foobar") equals "Zm9vYmFy"', () => {
expect(btoa('foobar'), 'Zm9vYmFy').toBe()
test('btoa("foobar") equals "Zm9vYmFy"', () => {
expect(btoa('foobar')).toBe('Zm9vYmFy');
});

View File

@ -8,11 +8,15 @@ const Blob = class{
};
const byteSize = str => new Blob([str]).size;
test('byteSize is a Function', () => {
test('byteSize is a Function', () => {
expect(byteSize).toBeInstanceOf(Function);
});
t.equal(byteSize('a'), 1, 'Works for a single letter');
t.equal(byteSize('Hello World'), 11, 'Works for a common string');
t.equal(byteSize('😀'), 4, 'Works for emoji');
test('Works for a single letter', () => {
expect(byteSize('a')).toBe(1);
});
test('Works for a common string', () => {
expect(byteSize('Hello World')).toBe(11);
});
test('Works for emoji', () => {
expect(byteSize('😀')).toBe(4);
});

View File

@ -5,10 +5,20 @@ const castArray = require('./castArray.js');
test('castArray is a Function', () => {
expect(castArray).toBeInstanceOf(Function);
});
t.deepEqual(castArray(1), [1], 'Works for single values');
t.deepEqual(castArray([1]), [1], 'Works for arrays with one value');
t.deepEqual(castArray([1,2,3]), [1,2,3], 'Works for arrays with multiple value');
t.deepEqual(castArray('test'), ['test'], 'Works for strings');
t.deepEqual(castArray({}), [{}], 'Works for objects');
test('Works for single values', () => {
expect(castArray(1), [1]).toEqual()
});
test('Works for arrays with one value', () => {
expect(castArray([1]), [1]).toEqual()
});
test('Works for arrays with multiple value', () => {
expect(castArray([1,2,3]), [1,2,3]).toEqual()
});
test('Works for strings', () => {
expect(castArray('test'), ['test']).toEqual()
});
test('Works for objects', () => {
expect(castArray({}), [{}]).toEqual()
});

View File

@ -15,7 +15,7 @@ const chainAsync = require('./chainAsync.js');
})();
},
next => {
t.pass("Calls all functions in an array");
}
]);

View File

@ -6,10 +6,18 @@ const chunk = require('./chunk.js');
expect(chunk).toBeInstanceOf(Function);
});
t.deepEqual(chunk([1, 2, 3, 4, 5], 2), [[1,2],[3,4],[5]], "chunk([1, 2, 3, 4, 5], 2) returns [[1,2],[3,4],[5]] ");
t.deepEqual(chunk([]), [], 'chunk([]) returns []');
t.deepEqual(chunk(123), [], 'chunk(123) returns []');
t.deepEqual(chunk({ a: 123}), [], 'chunk({ a: 123}) returns []');
t.deepEqual(chunk('string', 2), [ 'st', 'ri', 'ng' ], 'chunk(string, 2) returns [ st, ri, ng ]');
test('chunk([]) returns []', () => {
expect(chunk([]), []).toEqual()
});
test('chunk(123) returns []', () => {
expect(chunk(123), []).toEqual()
});
test('chunk({ a: 123}) returns []', () => {
expect(chunk({ a: 123}), []).toEqual()
});
test('chunk(string, 2) returns [ st, ri, ng ]', () => {
expect(chunk('string', 2), [ 'st', 'ri', 'ng' ]).toEqual()
});
t.throws(() => chunk(), 'chunk() throws an error');
t.throws(() => chunk(undefined), 'chunk(undefined) throws an error');
t.throws(() => chunk(null), 'chunk(null) throws an error');

View File

@ -5,13 +5,17 @@ const collatz = require('./collatz.js');
test('collatz is a Function', () => {
expect(collatz).toBeInstanceOf(Function);
});
t.equal(collatz(8), 4, 'When n is even, divide by 2');
t.equal(collatz(9), 28, 'When n is odd, times by 3 and add 1');
test('When n is even, divide by 2', () => {
expect(collatz(8), 4).toBe()
});
test('When n is odd, times by 3 and add 1', () => {
expect(collatz(9), 28).toBe()
});
let n = 9;
while(true){
if (n === 1){
t.pass('Eventually reaches 1');
break;
}
n = collatz(n);

View File

@ -9,6 +9,8 @@ const collectInto = require('./collectInto.js');
let p1 = Promise.resolve(1);
let p2 = Promise.resolve(2);
let p3 = new Promise(resolve => setTimeout(resolve, 2000, 3));
Pall(p1, p2, p3).then(function(val){ t.deepEqual(val, [1,2,3], 'Works with multiple promises');}, function(reason){
Pall(p1, p2, p3).then(function(val){ test('Works with multiple promises', () => {
expect(val, [1,2,3]).toEqual()
});}, function(reason){

View File

@ -5,6 +5,6 @@ const colorize = require('./colorize.js');
test('colorize is a Function', () => {
expect(colorize).toBeInstanceOf(Function);
});
t.pass('Tested on 09/02/2018 by @chalarangelo');

View File

@ -9,11 +9,15 @@ const converge = require('./converge.js');
arr => arr.reduce((a, v) => a + v, 0),
arr => arr.length,
]);
t.equal(average([1, 2, 3, 4, 5, 6, 7]), 4, 'Produces the average of the array');
test('Produces the average of the array', () => {
expect(average([1, 2, 3, 4, 5, 6, 7]), 4).toBe()
});
const strangeConcat = converge((a, b) => a + b, [
x => x.toUpperCase(),
x => x.toLowerCase()]
);
t.equal(strangeConcat('Yodel'), "YODELyodel", 'Produces the strange concatenation');
test('Produces the strange concatenation', () => {
expect(strangeConcat('Yodel'), "YODELyodel").toBe()
});

View File

@ -5,6 +5,6 @@ const copyToClipboard = require('./copyToClipboard.js');
test('copyToClipboard is a Function', () => {
expect(copyToClipboard).toBeInstanceOf(Function);
});
t.pass('Tested on 09/02/2018 by @chalarangelo');

View File

@ -5,7 +5,11 @@ const countBy = require('./countBy.js');
test('countBy is a Function', () => {
expect(countBy).toBeInstanceOf(Function);
});
t.deepEqual(countBy([6.1, 4.2, 6.3], Math.floor), {4: 1, 6: 2}, 'Works for functions');
t.deepEqual(countBy(['one', 'two', 'three'], 'length'), {3: 2, 5: 1}, 'Works for property names');
test('Works for functions', () => {
expect(countBy([6.1, 4.2, 6.3], Math.floor), {4: 1, 6: 2}).toEqual()
});
test('Works for property names', () => {
expect(countBy(['one', 'two', 'three'], 'length'), {3: 2, 5: 1}).toEqual()
});

View File

@ -5,6 +5,6 @@ const createElement = require('./createElement.js');
test('createElement is a Function', () => {
expect(createElement).toBeInstanceOf(Function);
});
t.pass('Tested by @chalarangelo on 16/02/2018');

View File

@ -5,6 +5,6 @@ const createEventHub = require('./createEventHub.js');
test('createEventHub is a Function', () => {
expect(createEventHub).toBeInstanceOf(Function);
});
t.pass('Tested by @chalarangelo on 16/02/2018');

View File

@ -5,6 +5,6 @@ const currentURL = require('./currentURL.js');
test('currentURL is a Function', () => {
expect(currentURL).toBeInstanceOf(Function);
});
t.pass('Tested by @chalarangelo on 16/02/2018');

View File

@ -5,6 +5,6 @@ const debounce = require('./debounce.js');
test('debounce is a Function', () => {
expect(debounce).toBeInstanceOf(Function);
});
debounce(() => {t.pass('Works as expected');}, 250);
debounce(() => {

View File

@ -5,7 +5,11 @@ const decapitalize = require('./decapitalize.js');
test('decapitalize is a Function', () => {
expect(decapitalize).toBeInstanceOf(Function);
});
t.equal(decapitalize('FooBar'), 'fooBar', 'Works with default parameter');
t.equal(decapitalize('FooBar', true), 'fOOBAR', 'Works with second parameter set to true');
test('Works with default parameter', () => {
expect(decapitalize('FooBar'), 'fooBar').toBe()
});
test('Works with second parameter set to true', () => {
expect(decapitalize('FooBar', true), 'fOOBAR').toBe()
});

View File

@ -5,6 +5,8 @@ const defaults = require('./defaults.js');
test('defaults is a Function', () => {
expect(defaults).toBeInstanceOf(Function);
});
t.deepEqual(defaults({ a: 1 }, { b: 2 }, { b: 6 }, { a: 3 }), { a: 1, b: 2 }, 'Assigns default values for undefined properties');
test('Assigns default values for undefined properties', () => {
expect(defaults({ a: 1 }, { b: 2 }, { b: 6 }, { a: 3 }), { a: 1, b: 2 }).toEqual()
});

View File

@ -5,6 +5,6 @@ const defer = require('./defer.js');
test('defer is a Function', () => {
expect(defer).toBeInstanceOf(Function);
});
t.pass('Tested by @chalarangelo on 16/02/2018');

View File

@ -5,6 +5,6 @@ const detectDeviceType = require('./detectDeviceType.js');
test('detectDeviceType is a Function', () => {
expect(detectDeviceType).toBeInstanceOf(Function);
});
t.pass('Tested on 09/02/2018 by @chalarangelo');

View File

@ -5,7 +5,11 @@ const differenceBy = require('./differenceBy.js');
test('differenceBy is a Function', () => {
expect(differenceBy).toBeInstanceOf(Function);
});
t.deepEqual(differenceBy([2.1, 1.2], [2.3, 3.4], Math.floor), [1.2], 'Works using a native function and numbers');
t.deepEqual(differenceBy([{ x: 2 }, { x: 1 }], [{ x: 1 }], v => v.x), [ { x: 2 } ], 'Works with arrow function and objects');
test('Works using a native function and numbers', () => {
expect(differenceBy([2.1, 1.2], [2.3, 3.4], Math.floor), [1.2]).toEqual()
});
test('Works with arrow function and objects', () => {
expect(differenceBy([{ x: 2 }, { x: 1 }], [{ x: 1 }], v => v.x), [ { x: 2 } ]).toEqual()
});

View File

@ -5,8 +5,14 @@ const drop = require('./drop.js');
test('drop is a Function', () => {
expect(drop).toBeInstanceOf(Function);
});
t.deepEqual(drop([1, 2, 3]), [2,3], 'Works without the last argument');
t.deepEqual(drop([1, 2, 3], 2), [3], 'Removes appropriate element count as specified');
t.deepEqual(drop([1, 2, 3], 42), [], 'Empties array given a count greater than length');
test('Works without the last argument', () => {
expect(drop([1, 2, 3]), [2,3]).toEqual()
});
test('Removes appropriate element count as specified', () => {
expect(drop([1, 2, 3], 2), [3]).toEqual()
});
test('Empties array given a count greater than length', () => {
expect(drop([1, 2, 3], 42), []).toEqual()
});

View File

@ -5,6 +5,8 @@ const dropRightWhile = require('./dropRightWhile.js');
test('dropRightWhile is a Function', () => {
expect(dropRightWhile).toBeInstanceOf(Function);
});
t.deepEqual(dropRightWhile([1, 2, 3, 4], n => n < 3), [1, 2], 'Removes elements from the end of an array until the passed function returns true.');
test('Removes elements from the end of an array until the passed function returns true.', () => {
expect(dropRightWhile([1, 2, 3, 4], n => n < 3), [1, 2]).toEqual()
});

View File

@ -5,6 +5,8 @@ const dropWhile = require('./dropWhile.js');
test('dropWhile is a Function', () => {
expect(dropWhile).toBeInstanceOf(Function);
});
t.deepEqual(dropWhile([1, 2, 3, 4], n => n >= 3), [3,4], 'Removes elements in an array until the passed function returns true.');
test('Removes elements in an array until the passed function returns true.', () => {
expect(dropWhile([1, 2, 3, 4], n => n >= 3), [3,4]).toEqual()
});

View File

@ -5,6 +5,6 @@ const elementIsVisibleInViewport = require('./elementIsVisibleInViewport.js');
test('elementIsVisibleInViewport is a Function', () => {
expect(elementIsVisibleInViewport).toBeInstanceOf(Function);
});
t.pass('Tested on 09/02/2018 by @chalarangelo');

View File

@ -5,6 +5,8 @@ const findLast = require('./findLast.js');
test('findLast is a Function', () => {
expect(findLast).toBeInstanceOf(Function);
});
t.equal(findLast([1, 2, 3, 4], n => n % 2 === 1), 3, 'Finds last element for which the given function returns true');
test('Finds last element for which the given function returns true', () => {
expect(findLast([1, 2, 3, 4], n => n % 2 === 1), 3).toBe()
});

View File

@ -5,6 +5,8 @@ const findLastIndex = require('./findLastIndex.js');
test('findLastIndex is a Function', () => {
expect(findLastIndex).toBeInstanceOf(Function);
});
t.equal(findLastIndex([1, 2, 3, 4], n => n % 2 === 1), 2, 'Finds last index for which the given function returns true');
test('Finds last index for which the given function returns true', () => {
expect(findLastIndex([1, 2, 3, 4], n => n % 2 === 1), 2).toBe()
});

View File

@ -5,7 +5,11 @@ const flattenObject = require('./flattenObject.js');
test('flattenObject is a Function', () => {
expect(flattenObject).toBeInstanceOf(Function);
});
t.deepEqual(flattenObject({ a: { b: { c: 1 } }, d: 1 }), { 'a.b.c': 1, d: 1 }, 'Flattens an object with the paths for keys');
t.deepEqual(flattenObject([0,1,[2,[1]],1]), { 0: 0, 1: 1, 3: 1, '2.0': 2, '2.1.0': 1 }, 'Works with arrays');
test('Flattens an object with the paths for keys', () => {
expect(flattenObject({ a: { b: { c: 1 } }, d: 1 }), { 'a.b.c': 1, d: 1 }).toEqual()
});
test('Works with arrays', () => {
expect(flattenObject([0,1,[2,[1]],1]), { 0: 0, 1: 1, 3: 1, '2.0': 2, '2.1.0': 1 }).toEqual()
});

View File

@ -9,6 +9,8 @@ const flip = require('./flip.js');
let b = {};
const mergeFrom = flip(Object.assign);
let mergePerson = mergeFrom.bind(null, a);
t.deepEqual(mergePerson(b), a, 'Flips argument order');
test('Flips argument order', () => {
expect(mergePerson(b), a).toEqual()
});

View File

@ -7,6 +7,8 @@ const forEachRight = require('./forEachRight.js');
});
let output = '';
forEachRight([1, 2, 3, 4], val => output+=val);
t.equal(output, '4321', 'Iterates over the array in reverse');
test('Iterates over the array in reverse', () => {
expect(output, '4321').toBe()
});

View File

@ -7,6 +7,8 @@ const forOwn = require('./forOwn.js');
});
let output = [];
forOwn({ foo: 'bar', a: 1 }, v => output.push(v));
t.deepEqual(output, ['bar', 1], 'Iterates over an element\'s key-value pairs');
test('Iterates over an element\'s key-value pairs', () => {
expect(output, ['bar', 1]).toEqual()
});

View File

@ -7,6 +7,8 @@ const forOwnRight = require('./forOwnRight.js');
});
let output = [];
forOwnRight({ foo: 'bar', a: 1 }, v => output.push(v));
t.deepEqual(output, [1, 'bar'], 'Iterates over an element\'s key-value pairs in reverse');
test('Iterates over an element\'s key-value pairs in reverse', () => {
expect(output, [1, 'bar']).toEqual()
});

View File

@ -8,12 +8,18 @@ const functionName = fn => (console.debug(fn.name), fn);
expect(functionName).toBeInstanceOf(Function);
});
functionName(Math.max);
t.equal(output, 'max', 'Works for native functions');
test('Works for native functions', () => {
expect(output, 'max').toBe()
});
function fun(x) {return x;}
functionName(fun);
t.equal(output, 'fun', 'Works for functions');
test('Works for functions', () => {
expect(output, 'fun').toBe()
});
const fn = x => x;
functionName(fn);
t.equal(output, 'fn', 'Works for arrow functions');
test('Works for arrow functions', () => {
expect(output, 'fn').toBe()
});

View File

@ -10,7 +10,11 @@ const functions = require('./functions.js');
this.b = () => 2;
}
Foo.prototype.c = () => 3;
t.deepEqual(functions(new Foo()), ['a', 'b'], 'Returns own methods');
t.deepEqual(functions(new Foo(), true), ['a', 'b', 'c'], 'Returns own and inherited methods');
test('Returns own methods', () => {
expect(functions(new Foo()), ['a', 'b']).toEqual()
});
test('Returns own and inherited methods', () => {
expect(functions(new Foo(), true), ['a', 'b', 'c']).toEqual()
});

View File

@ -5,6 +5,6 @@ const getScrollPosition = require('./getScrollPosition.js');
test('getScrollPosition is a Function', () => {
expect(getScrollPosition).toBeInstanceOf(Function);
});
t.pass('Tested by @chalarangelo on 16/02/2018');

View File

@ -5,6 +5,6 @@ const getStyle = require('./getStyle.js');
test('getStyle is a Function', () => {
expect(getStyle).toBeInstanceOf(Function);
});
t.pass('Tested by @chalarangelo on 16/02/2018');

View File

@ -5,6 +5,6 @@ const hasFlags = require('./hasFlags.js');
test('hasFlags is a Function', () => {
expect(hasFlags).toBeInstanceOf(Function);
});
t.pass('Tested by @chalarangelo on 16/02/2018');

View File

@ -5,6 +5,6 @@ const hashBrowser = require('./hashBrowser.js');
test('hashBrowser is a Function', () => {
expect(hashBrowser).toBeInstanceOf(Function);
});
t.pass('Tested by @chalarangelo on 16/02/2018');

View File

@ -9,8 +9,12 @@ const head = require('./head.js');
expect(head({ a: 1234}) === undefined).toBeTruthy();
});
t.equal(head([1, 2, 3]), 1, "head([1, 2, 3]) returns 1");
t.equal(head({ 0: false}), false, 'head({ 0: false}) returns false');
t.equal(head('String'), 'S', 'head(String) returns S');
test('head({ 0: false}) returns false', () => {
expect(head({ 0: false}), false).toBe()
});
test('head(String) returns S', () => {
expect(head('String'), 'S').toBe()
});
t.throws(() => head(null), 'head(null) throws an Error');
t.throws(() => head(undefined), 'head(undefined) throws an Error');
t.throws(() => head(), 'head() throws an Error');

View File

@ -5,6 +5,6 @@ const hide = require('./hide.js');
test('hide is a Function', () => {
expect(hide).toBeInstanceOf(Function);
});
t.pass('Tested by @chalarangelo on 16/02/2018');

View File

@ -17,7 +17,9 @@ const httpPost = (url, data, callback, err = console.error) => {
userId: 1
};
httpPost('https:
t.deepEqual(JSON.parse(response).id, 101, 'Sends a POST request');
test('Sends a POST request', () => {
expect(JSON.parse(response).id, 101).toEqual()
});

View File

@ -5,6 +5,6 @@ const httpsRedirect = require('./httpsRedirect.js');
test('httpsRedirect is a Function', () => {
expect(httpsRedirect).toBeInstanceOf(Function);
});
t.pass('Tested on 09/02/2018 by @chalarangelo');

View File

@ -5,6 +5,8 @@ const intersectionBy = require('./intersectionBy.js');
test('intersectionBy is a Function', () => {
expect(intersectionBy).toBeInstanceOf(Function);
});
t.deepEqual(intersectionBy([2.1, 1.2], [2.3, 3.4], Math.floor), [2.1], 'Returns a list of elements that exist in both arrays, after applying the provided function to each array element of both');
test('Returns a list of elements that exist in both arrays, after applying the provided function to each array element of both', () => {
expect(intersectionBy([2.1, 1.2], [2.3, 3.4], Math.floor), [2.1]).toEqual()
});

View File

@ -5,6 +5,8 @@ const intersectionWith = require('./intersectionWith.js');
test('intersectionWith is a Function', () => {
expect(intersectionWith).toBeInstanceOf(Function);
});
t.deepEqual(intersectionWith([1, 1.2, 1.5, 3, 0], [1.9, 3, 0, 3.9], (a, b) => Math.round(a) === Math.round(b)), [1.5, 3, 0], 'Returns a list of elements that exist in both arrays, using a provided comparator function');
test('Returns a list of elements that exist in both arrays, using a provided comparator function', () => {
expect(intersectionWith([1, 1.2, 1.5, 3, 0], [1.9, 3, 0, 3.9], (a, b) => Math.round(a) === Math.round(b)), [1.5, 3, 0]).toEqual()
});

View File

@ -5,8 +5,14 @@ const isArrayLike = require('./isArrayLike.js');
test('isArrayLike is a Function', () => {
expect(isArrayLike).toBeInstanceOf(Function);
});
t.equal(isArrayLike('abc'), true, 'Returns true for a string');
t.equal(isArrayLike([1,2,3]), true, 'Returns true for an array');
t.equal(isArrayLike(null), false, 'Returns false for null');
test('Returns true for a string', () => {
expect(isArrayLike('abc'), true).toBe()
});
test('Returns true for an array', () => {
expect(isArrayLike([1,2,3]), true).toBe()
});
test('Returns false for null', () => {
expect(isArrayLike(null), false).toBe()
});

View File

@ -5,5 +5,7 @@ const isDivisible = require('./isDivisible.js');
test('isDivisible is a Function', () => {
expect(isDivisible).toBeInstanceOf(Function);
});
t.equal(isDivisible(6, 3), true, 'The number 6 is divisible by 3');
test('The number 6 is divisible by 3', () => {
expect(isDivisible(6, 3), true).toBe()
});

View File

@ -5,15 +5,35 @@ const isEmpty = require('./isEmpty.js');
test('isEmpty is a Function', () => {
expect(isEmpty).toBeInstanceOf(Function);
});
t.equal(isEmpty(new Map()), true, 'Returns true for empty Map');
t.equal(isEmpty(new Set()), true, 'Returns true for empty Set');
t.equal(isEmpty([]), true, 'Returns true for empty array');
t.equal(isEmpty({}), true, 'Returns true for empty object');
t.equal(isEmpty(''), true, 'Returns true for empty string');
t.equal(isEmpty([1, 2]), false, 'Returns false for non-empty array');
t.equal(isEmpty({ a: 1, b: 2 }), false, 'Returns false for non-empty object');
t.equal(isEmpty('text'), false, 'Returns false for non-empty string');
t.equal(isEmpty(123), true, 'Returns true - type is not considered a collection');
t.equal(isEmpty(true), true, 'Returns true - type is not considered a collection');
test('Returns true for empty Map', () => {
expect(isEmpty(new Map()), true).toBe()
});
test('Returns true for empty Set', () => {
expect(isEmpty(new Set()), true).toBe()
});
test('Returns true for empty array', () => {
expect(isEmpty([]), true).toBe()
});
test('Returns true for empty object', () => {
expect(isEmpty({}), true).toBe()
});
test('Returns true for empty string', () => {
expect(isEmpty(''), true).toBe()
});
test('Returns false for non-empty array', () => {
expect(isEmpty([1, 2]), false).toBe()
});
test('Returns false for non-empty object', () => {
expect(isEmpty({ a: 1, b: 2 }), false).toBe()
});
test('Returns false for non-empty string', () => {
expect(isEmpty('text'), false).toBe()
});
test('Returns true - type is not considered a collection', () => {
expect(isEmpty(123), true).toBe()
});
test('Returns true - type is not considered a collection', () => {
expect(isEmpty(true), true).toBe()
});

View File

@ -5,7 +5,9 @@ const isEven = require('./isEven.js');
test('isEven is a Function', () => {
expect(isEven).toBeInstanceOf(Function);
});
t.equal(isEven(4), true, '4 is even number');
test('4 is even number', () => {
expect(isEven(4), true).toBe()
});
test('5 is not an even number', () => {
expect(isEven(5), false).toBeFalsy();
});

View File

@ -5,8 +5,14 @@ const isNil = require('./isNil.js');
test('isNil is a Function', () => {
expect(isNil).toBeInstanceOf(Function);
});
t.equal(isNil(null), true, 'Returns true for null');
t.equal(isNil(undefined), true, 'Returns true for undefined');
t.equal(isNil(''), false, 'Returns false for an empty string');
test('Returns true for null', () => {
expect(isNil(null), true).toBe()
});
test('Returns true for undefined', () => {
expect(isNil(undefined), true).toBe()
});
test('Returns false for an empty string', () => {
expect(isNil(''), false).toBe()
});

View File

@ -5,9 +5,17 @@ const isObjectLike = require('./isObjectLike.js');
test('isObjectLike is a Function', () => {
expect(isObjectLike).toBeInstanceOf(Function);
});
t.equal(isObjectLike({}), true, 'Returns true for an object');
t.equal(isObjectLike([1, 2, 3]), true, 'Returns true for an array');
t.equal(isObjectLike(x => x), false, 'Returns false for a function');
t.equal(isObjectLike(null), false, 'Returns false for null');
test('Returns true for an object', () => {
expect(isObjectLike({}), true).toBe()
});
test('Returns true for an array', () => {
expect(isObjectLike([1, 2, 3]), true).toBe()
});
test('Returns false for a function', () => {
expect(isObjectLike(x => x), false).toBe()
});
test('Returns false for null', () => {
expect(isObjectLike(null), false).toBe()
});

View File

@ -5,7 +5,11 @@ const isPlainObject = require('./isPlainObject.js');
test('isPlainObject is a Function', () => {
expect(isPlainObject).toBeInstanceOf(Function);
});
t.equal(isPlainObject({ a: 1 }), true, 'Returns true for a plain object');
t.equal(isPlainObject(new Map()), false, 'Returns false for a Map (example of non-plain object)');
test('Returns true for a plain object', () => {
expect(isPlainObject({ a: 1 }), true).toBe()
});
test('Returns false for a Map (example of non-plain object)', () => {
expect(isPlainObject(new Map()), false).toBe()
});

View File

@ -10,7 +10,11 @@ const isPromiseLike = require('./isPromiseLike.js');
return '';
}
}), true, 'Returns true for a promise-like object');
t.equal(isPromiseLike(null), false, 'Returns false for null');
t.equal(isPromiseLike({}), false, 'Returns false for an empty object');
test('Returns false for null', () => {
expect(isPromiseLike(null), false).toBe()
});
test('Returns false for an empty object', () => {
expect(isPromiseLike({}), false).toBe()
});

View File

@ -5,16 +5,38 @@ const isSorted = require('./isSorted.js');
test('isSorted is a Function', () => {
expect(isSorted).toBeInstanceOf(Function);
});
t.equal(isSorted([0, 1, 2]), 1, 'Array is sorted in ascending order');
t.equal(isSorted([0, 1, 2, 2]), 1, 'Array is sorted in ascending order');
t.equal(isSorted([-4, -3, -2]), 1, 'Array is sorted in ascending order');
t.equal(isSorted([0, 0, 1, 2]), 1, 'Array is sorted in ascending order');
t.equal(isSorted([2, 1, 0]), -1, 'Array is sorted in descending order');
t.equal(isSorted([2, 2, 1, 0]), -1, 'Array is sorted in descending order');
t.equal(isSorted([-2, -3, -4]), -1, 'Array is sorted in descending order');
t.equal(isSorted([2, 1, 0, 0]), -1, 'Array is sorted in descending order');
t.equal(isSorted([]), undefined, 'Array is empty');
t.equal(isSorted([1]), 0, 'Array is not sorted, direction changed in array');
t.equal(isSorted([1, 2, 1]), 0, 'Array is not sorted, direction changed in array');
test('Array is sorted in ascending order', () => {
expect(isSorted([0, 1, 2]), 1).toBe()
});
test('Array is sorted in ascending order', () => {
expect(isSorted([0, 1, 2, 2]), 1).toBe()
});
test('Array is sorted in ascending order', () => {
expect(isSorted([-4, -3, -2]), 1).toBe()
});
test('Array is sorted in ascending order', () => {
expect(isSorted([0, 0, 1, 2]), 1).toBe()
});
test('Array is sorted in descending order', () => {
expect(isSorted([2, 1, 0]), -1).toBe()
});
test('Array is sorted in descending order', () => {
expect(isSorted([2, 2, 1, 0]), -1).toBe()
});
test('Array is sorted in descending order', () => {
expect(isSorted([-2, -3, -4]), -1).toBe()
});
test('Array is sorted in descending order', () => {
expect(isSorted([2, 1, 0, 0]), -1).toBe()
});
test('Array is empty', () => {
expect(isSorted([]), undefined).toBe()
});
test('Array is not sorted, direction changed in array', () => {
expect(isSorted([1]), 0).toBe()
});
test('Array is not sorted, direction changed in array', () => {
expect(isSorted([1, 2, 1]), 0).toBe()
});

View File

@ -5,9 +5,19 @@ const isString = require('./isString.js');
test('isString is a Function', () => {
expect(isString).toBeInstanceOf(Function);
});
t.equal(isString('foo'), true, 'foo is a string');
t.equal(isString('10'), true, '"10" is a string');
t.equal(isString(''), true, 'Empty string is a string');
t.equal(isString(10), false, '10 is not a string');
t.equal(isString(true), false, 'true is not string');
test('foo is a string', () => {
expect(isString('foo'), true).toBe()
});
test('"10" is a string', () => {
expect(isString('10'), true).toBe()
});
test('Empty string is a string', () => {
expect(isString(''), true).toBe()
});
test('10 is not a string', () => {
expect(isString(10), false).toBe()
});
test('true is not string', () => {
expect(isString(true), false).toBe()
});

View File

@ -5,7 +5,13 @@ const isUpperCase = require('./isUpperCase.js');
test('isUpperCase is a Function', () => {
expect(isUpperCase).toBeInstanceOf(Function);
});
t.equal(isUpperCase('ABC'), true, 'ABC is all upper case');
t.equal(isUpperCase('abc'), false, 'abc is not all upper case');
t.equal(isUpperCase('A3@$'), true, 'A3@$ is all uppercase');
test('ABC is all upper case', () => {
expect(isUpperCase('ABC'), true).toBe()
});
test('abc is not all upper case', () => {
expect(isUpperCase('abc'), false).toBe()
});
test('A3@$ is all uppercase', () => {
expect(isUpperCase('A3@$'), true).toBe()
});

View File

@ -5,7 +5,13 @@ const isValidJSON = require('./isValidJSON.js');
test('isValidJSON is a Function', () => {
expect(isValidJSON).toBeInstanceOf(Function);
});
t.equal(isValidJSON('{"name":"Adam","age":20}'), true, '{"name":"Adam","age":20} is a valid JSON');
t.equal(isValidJSON('{"name":"Adam",age:"20"}'), false, '{"name":"Adam",age:"20"} is not a valid JSON');
t.equal(isValidJSON(null), true, 'null is a valid JSON');
test('{"name":"Adam","age":20} is a valid JSON', () => {
expect(isValidJSON('{"name":"Adam","age":20}'), true).toBe()
});
test('{"name":"Adam",age:"20"} is not a valid JSON', () => {
expect(isValidJSON('{"name":"Adam",age:"20"}'), false).toBe()
});
test('null is a valid JSON', () => {
expect(isValidJSON(null), true).toBe()
});

View File

@ -9,8 +9,12 @@ const last = require('./last.js');
expect(last({ a: 1234}) === undefined).toBeTruthy();
});
t.equal(last([1, 2, 3]), 3, "last([1, 2, 3]) returns 3");
t.equal(last({ 0: false}), undefined, 'last({ 0: false}) returns undefined');
t.equal(last('String'), 'g', 'last(String) returns g');
test('last({ 0: false}) returns undefined', () => {
expect(last({ 0: false}), undefined).toBe()
});
test('last(String) returns g', () => {
expect(last('String'), 'g').toBe()
});
t.throws(() => last(null), 'last(null) throws an Error');
t.throws(() => last(undefined), 'last(undefined) throws an Error');
t.throws(() => last(), 'last() throws an Error');

View File

@ -7,7 +7,11 @@ const lowercaseKeys = require('./lowercaseKeys.js');
});
const myObj = { Name: 'Adam', sUrnAME: 'Smith' };
const myObjLower = lowercaseKeys(myObj);
t.deepEqual(myObjLower, {name: 'Adam', surname: 'Smith'}, 'Lowercases object keys');
t.deepEqual(myObj, { Name: 'Adam', sUrnAME: 'Smith' }, 'Does not mutate original object');
test('Lowercases object keys', () => {
expect(myObjLower, {name: 'Adam', surname: 'Smith'}).toEqual()
});
test('Does not mutate original object', () => {
expect(myObj, { Name: 'Adam', sUrnAME: 'Smith' }).toEqual()
});

View File

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

View File

@ -6,7 +6,11 @@ const mapObject = require('./mapObject.js');
expect(mapObject).toBeInstanceOf(Function);
});
t.deepEqual(mapObject([1, 2, 3], a => a * a), { 1: 1, 2: 4, 3: 9 }, "mapObject([1, 2, 3], a => a * a) returns { 1: 1, 2: 4, 3: 9 }");
t.deepEqual(mapObject([1, 2, 3, 4], (a, b) => b - a), { 1: -1, 2: -1, 3: -1, 4: -1 }, 'mapObject([1, 2, 3, 4], (a, b) => b - a) returns { 1: -1, 2: -1, 3: -1, 4: -1 }');
t.deepEqual(mapObject([1, 2, 3, 4], (a, b) => a - b), { 1: 1, 2: 1, 3: 1, 4: 1 }, 'mapObject([1, 2, 3, 4], (a, b) => a - b) returns { 1: 1, 2: 1, 3: 1, 4: 1 }');
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) => 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()
});

View File

@ -9,6 +9,8 @@ const mapValues = require('./mapValues.js');
fred: { user: 'fred', age: 40 },
pebbles: { user: 'pebbles', age: 1 }
};
t.deepEqual(mapValues(users, u => u.age), { fred: 40, pebbles: 1 }, 'Maps values');
test('Maps values', () => {
expect(mapValues(users, u => u.age), { fred: 40, pebbles: 1 }).toEqual()
});

View File

@ -7,8 +7,14 @@ const memoize = require('./memoize.js');
});
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');
test('Function works properly', () => {
expect(square(2), 4).toBe()
});
test('Function works properly', () => {
expect(square(3), 9).toBe()
});
test('Cache stores values', () => {
expect(Array.from(square.cache), [[2,4],[3,9]]).toEqual()
});

View File

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

View File

@ -5,6 +5,6 @@ const mostPerformant = require('./mostPerformant.js');
test('mostPerformant is a Function', () => {
expect(mostPerformant).toBeInstanceOf(Function);
});
t.pass('Tested by @chalarangelo on 16/02/2018');

View File

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

View File

@ -5,6 +5,6 @@ const observeMutations = require('./observeMutations.js');
test('observeMutations is a Function', () => {
expect(observeMutations).toBeInstanceOf(Function);
});
t.pass('Tested on 09/02/2018 by @chalarangelo');

View File

@ -5,6 +5,6 @@ const off = require('./off.js');
test('off is a Function', () => {
expect(off).toBeInstanceOf(Function);
});
t.pass('Tested by @chalarangelo on 16/02/2018');

View File

@ -5,11 +5,23 @@ const offset = require('./offset.js');
test('offset is a Function', () => {
expect(offset).toBeInstanceOf(Function);
});
t.deepEqual(offset([1, 2, 3, 4, 5], 0), [1, 2, 3, 4, 5], 'Offset of 0 returns the same array.');
t.deepEqual(offset([1, 2, 3, 4, 5], 2), [3, 4, 5, 1, 2], 'Offset > 0 returns the offsetted array.');
t.deepEqual(offset([1, 2, 3, 4, 5], -2), [4, 5, 1, 2, 3], 'Offset < 0 returns the reverse offsetted array.');
t.deepEqual(offset([1, 2, 3, 4, 5], 6),[1, 2, 3, 4, 5], 'Offset greater than the length of the array returns the same array.');
t.deepEqual(offset([1, 2, 3, 4, 5], -6), [1, 2, 3, 4, 5], 'Offset less than the negative length of the array returns the same array.');
t.deepEqual(offset([], 3), [], 'Offsetting empty array returns an empty array.');
test('Offset of 0 returns the same array.', () => {
expect(offset([1, 2, 3, 4, 5], 0), [1, 2, 3, 4, 5]).toEqual()
});
test('Offset > 0 returns the offsetted array.', () => {
expect(offset([1, 2, 3, 4, 5], 2), [3, 4, 5, 1, 2]).toEqual()
});
test('Offset < 0 returns the reverse offsetted array.', () => {
expect(offset([1, 2, 3, 4, 5], -2), [4, 5, 1, 2, 3]).toEqual()
});
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()
});
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()
});
test('Offsetting empty array returns an empty array.', () => {
expect(offset([], 3), []).toEqual()
});

View File

@ -5,6 +5,8 @@ const omit = require('./omit.js');
test('omit is a Function', () => {
expect(omit).toBeInstanceOf(Function);
});
t.deepEqual(omit({ a: 1, b: '2', c: 3 }, ['b']), { 'a': 1, 'c': 3 }, '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()
});

View File

@ -5,6 +5,8 @@ const omitBy = require('./omitBy.js');
test('omitBy is a Function', () => {
expect(omitBy).toBeInstanceOf(Function);
});
t.deepEqual(omitBy({ a: 1, b: '2', c: 3 }, x => typeof x === 'number'), { b: '2' }, '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()
});

View File

@ -5,6 +5,6 @@ const on = require('./on.js');
test('on is a Function', () => {
expect(on).toBeInstanceOf(Function);
});
t.pass('Tested by @chalarangelo on 16/02/2018');

View File

@ -5,6 +5,6 @@ const onUserInputChange = require('./onUserInputChange.js');
test('onUserInputChange is a Function', () => {
expect(onUserInputChange).toBeInstanceOf(Function);
});
t.pass('Tested by @chalarangelo on 16/02/2018');

View File

@ -5,6 +5,6 @@ const once = require('./once.js');
test('once is a Function', () => {
expect(once).toBeInstanceOf(Function);
});
t.pass('Tested by @chalarangelo on 16/02/2018');

View File

@ -6,6 +6,8 @@ const over = require('./over.js');
expect(over).toBeInstanceOf(Function);
});
const minMax = over(Math.min, Math.max);
t.deepEqual(minMax(1, 2, 3, 4, 5), [1,5], 'Applies given functions over multiple arguments');
test('Applies given functions over multiple arguments', () => {
expect(minMax(1, 2, 3, 4, 5), [1,5]).toEqual()
});

View File

@ -8,6 +8,8 @@ const overArgs = require('./overArgs.js');
const square = n => n * n;
const double = n => n * 2;
const fn = overArgs((x, y) => [x, y], [square, double]);
t.deepEqual(fn(9, 3), [81, 6], 'Invokes the provided function with its arguments transformed');
test('Invokes the provided function with its arguments transformed', () => {
expect(fn(9, 3), [81, 6]).toEqual()
});

View File

@ -5,9 +5,17 @@ const pad = require('./pad.js');
test('pad is a Function', () => {
expect(pad).toBeInstanceOf(Function);
});
t.equal(pad('cat',8), ' cat ', 'cat is padded on both sides');
t.equal(pad('cat',8).length, 8, 'length of string is 8');
t.equal(pad(String(42), 6, '0'), '004200', 'pads 42 with "0"');
t.equal(pad('foobar', 3), 'foobar', 'does not truncates if string exceeds length');
test('cat is padded on both sides', () => {
expect(pad('cat',8), ' cat ').toBe()
});
test('length of string is 8', () => {
expect(pad('cat',8).length, 8).toBe()
});
test('pads 42 with "0"', () => {
expect(pad(String(42), 6, '0'), '004200').toBe()
});
test('does not truncates if string exceeds length', () => {
expect(pad('foobar', 3), 'foobar').toBe()
});

View File

@ -5,6 +5,8 @@ const parseCookie = require('./parseCookie.js');
test('parseCookie is a Function', () => {
expect(parseCookie).toBeInstanceOf(Function);
});
t.deepEqual(parseCookie('foo=bar; equation=E%3Dmc%5E2'), { foo: 'bar', equation: 'E=mc^2' }, 'Parses the cookie');
test('Parses the cookie', () => {
expect(parseCookie('foo=bar; equation=E%3Dmc%5E2'), { foo: 'bar', equation: 'E=mc^2' }).toEqual()
});

View File

@ -9,6 +9,8 @@ const partial = require('./partial.js');
return greeting + ' ' + name + '!';
}
const greetHello = partial(greet, 'Hello');
t.equal(greetHello('John'), 'Hello John!', 'Prepends arguments');
test('Prepends arguments', () => {
expect(greetHello('John'), 'Hello John!').toBe()
});

View File

@ -9,6 +9,8 @@ const partialRight = require('./partialRight.js');
return greeting + ' ' + name + '!';
}
const greetJohn = partialRight(greet, 'John');
t.equal(greetJohn('Hello'), 'Hello John!', 'Appends arguments');
test('Appends arguments', () => {
expect(greetJohn('Hello'), 'Hello John!').toBe()
});

View File

@ -5,6 +5,8 @@ const permutations = require('./permutations.js');
test('permutations is a Function', () => {
expect(permutations).toBeInstanceOf(Function);
});
t.deepEqual(permutations([1, 33, 5]), [ [ 1, 33, 5 ], [ 1, 5, 33 ], [ 33, 1, 5 ], [ 33, 5, 1 ], [ 5, 1, 33 ], [ 5, 33, 1 ] ], '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()
});

View File

@ -5,6 +5,8 @@ const pickBy = require('./pickBy.js');
test('pickBy is a Function', () => {
expect(pickBy).toBeInstanceOf(Function);
});
t.deepEqual(pickBy({ a: 1, b: '2', c: 3 }, x => typeof x === 'number'), { 'a': 1, 'c': 3 }, '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()
});

View File

@ -8,6 +8,8 @@ const pipeFunctions = require('./pipeFunctions.js');
const add5 = x => x + 5;
const multiply = (x, y) => x * y;
const multiplyAndAdd5 = pipeFunctions(multiply, add5);
t.equal(multiplyAndAdd5(5, 2), 15, 'Performs left-to-right function composition');
test('Performs left-to-right function composition', () => {
expect(multiplyAndAdd5(5, 2), 15).toBe()
});

View File

@ -5,15 +5,25 @@ const pluralize = require('./pluralize.js');
test('pluralize is a Function', () => {
expect(pluralize).toBeInstanceOf(Function);
});
t.equal(pluralize(0, 'apple'), 'apples', 'Produces the plural of the word');
t.equal(pluralize(1, 'apple'), 'apple', 'Produces the singular of the word');
t.equal(pluralize(2, 'apple'), 'apples', 'Produces the plural of the word');
t.equal(pluralize(2, 'person', 'people'), 'people', 'Prodices the defined plural of the word');
test('Produces the plural of the word', () => {
expect(pluralize(0, 'apple'), 'apples').toBe()
});
test('Produces the singular of the word', () => {
expect(pluralize(1, 'apple'), 'apple').toBe()
});
test('Produces the plural of the word', () => {
expect(pluralize(2, 'apple'), 'apples').toBe()
});
test('Prodices the defined plural of the word', () => {
expect(pluralize(2, 'person', 'people'), 'people').toBe()
});
const PLURALS = {
person: 'people',
radius: 'radii'
};
const autoPluralize = pluralize(PLURALS);
t.equal(autoPluralize(2, 'person'), 'people', 'Works with a dictionary');
test('Works with a dictionary', () => {
expect(autoPluralize(2, 'person'), 'people').toBe()
});

Some files were not shown because too many files have changed in this diff Show More