Test files linted

This commit is contained in:
Angelos Chalaris
2018-08-03 10:39:26 +03:00
parent 5ef1fab5fd
commit cc7b76d0b3
153 changed files with 754 additions and 463 deletions

View File

@ -5,8 +5,14 @@ test('CSVToJSON is a Function', () => {
expect(CSVToJSON).toBeInstanceOf(Function); expect(CSVToJSON).toBeInstanceOf(Function);
}); });
test('CSVToJSON works with default delimiter', () => { test('CSVToJSON works with default delimiter', () => {
expect(CSVToJSON('col1,col2\na,b\nc,d')).toEqual([{'col1': 'a', 'col2': 'b'}, {'col1': 'c', 'col2': 'd'}]); expect(CSVToJSON('col1,col2\na,b\nc,d')).toEqual([
{ col1: 'a', col2: 'b' },
{ col1: 'c', col2: 'd' }
]);
}); });
test('CSVToJSON works with custom delimiter', () => { test('CSVToJSON works with custom delimiter', () => {
expect(CSVToJSON('col1;col2\na;b\nc;d', ';')).toEqual([{'col1': 'a', 'col2': 'b'}, {'col1': 'c', 'col2': 'd'}]); expect(CSVToJSON('col1;col2\na;b\nc;d', ';')).toEqual([
{ col1: 'a', col2: 'b' },
{ col1: 'c', col2: 'd' }
]);
}); });

View File

@ -5,8 +5,12 @@ test('JSONtoCSV is a Function', () => {
expect(JSONtoCSV).toBeInstanceOf(Function); expect(JSONtoCSV).toBeInstanceOf(Function);
}); });
test('JSONtoCSV works with default delimiter', () => { test('JSONtoCSV works with default delimiter', () => {
expect(JSONtoCSV([{ a: 1, b: 2 }, { a: 3, b: 4, c: 5 }, { a: 6 }, { b: 7 }], ['a', 'b'])).toBe('a,b\n"1","2"\n"3","4"\n"6",""\n"","7"'); expect(JSONtoCSV([{ a: 1, b: 2 }, { a: 3, b: 4, c: 5 }, { a: 6 }, { b: 7 }], ['a', 'b'])).toBe(
'a,b\n"1","2"\n"3","4"\n"6",""\n"","7"'
);
}); });
test('JSONtoCSV works with custom delimiter', () => { test('JSONtoCSV works with custom delimiter', () => {
expect(JSONtoCSV([{ a: 1, b: 2 }, { a: 3, b: 4, c: 5 }, { a: 6 }, { b: 7 }], ['a', 'b'], ';')).toBe('a;b\n"1";"2"\n"3";"4"\n"6";""\n"";"7"'); expect(
JSONtoCSV([{ a: 1, b: 2 }, { a: 3, b: 4, c: 5 }, { a: 6 }, { b: 7 }], ['a', 'b'], ';')
).toBe('a;b\n"1";"2"\n"3";"4"\n"6";""\n"";"7"');
}); });

View File

@ -5,8 +5,12 @@ test('URLJoin is a Function', () => {
expect(URLJoin).toBeInstanceOf(Function); expect(URLJoin).toBeInstanceOf(Function);
}); });
test('Returns proper URL', () => { test('Returns proper URL', () => {
expect(URLJoin('http://www.google.com', 'a', '/b/cd', '?foo=123', '?bar=foo')).toBe('http://www.google.com/a/b/cd?foo=123&bar=foo'); expect(URLJoin('http://www.google.com', 'a', '/b/cd', '?foo=123', '?bar=foo')).toBe(
'http://www.google.com/a/b/cd?foo=123&bar=foo'
);
}); });
test('Returns proper URL', () => { test('Returns proper URL', () => {
expect(URLJoin('file://www.google.com', 'a', '/b/cd', '?foo=123', '?bar=foo')).toBe('file:///www.google.com/a/b/cd?foo=123&bar=foo'); expect(URLJoin('file://www.google.com', 'a', '/b/cd', '?foo=123', '?bar=foo')).toBe(
'file:///www.google.com/a/b/cd?foo=123&bar=foo'
);
}); });

View File

@ -8,5 +8,9 @@ test('Returns a value', () => {
expect(attempt(() => 0)).toBe(0); expect(attempt(() => 0)).toBe(0);
}); });
test('Returns an error', () => { test('Returns an error', () => {
expect(attempt(() => {throw new Error();})).toBeInstanceOf(Error); expect(
attempt(() => {
throw new Error();
})
).toBeInstanceOf(Error);
}); });

View File

@ -14,7 +14,10 @@ test('average(9, 1) returns 5', () => {
expect(average(9, 1)).toBe(5); expect(average(9, 1)).toBe(5);
}); });
test('average(153, 44, 55, 64, 71, 1122, 322774, 2232, 23423, 234, 3631) returns 32163.909090909092 ', () => { 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); expect(average(153, 44, 55, 64, 71, 1122, 322774, 2232, 23423, 234, 3631)).toBeCloseTo(
32163.909090909092,
3
);
}); });
test('average(1, 2, 3) returns 2', () => { test('average(1, 2, 3) returns 2', () => {
expect(average(1, 2, 3)).toBe(2); expect(average(1, 2, 3)).toBe(2);
@ -39,5 +42,5 @@ let start = new Date().getTime();
average(153, 44, 55, 64, 71, 1122, 322774, 2232, 23423, 234, 3631); average(153, 44, 55, 64, 71, 1122, 322774, 2232, 23423, 234, 3631);
let end = new Date().getTime(); 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', () => { 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(); expect(end - start < 2000).toBeTruthy();
}); });

View File

@ -5,5 +5,8 @@ test('bifurcate is a Function', () => {
expect(bifurcate).toBeInstanceOf(Function); expect(bifurcate).toBeInstanceOf(Function);
}); });
test('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'] ]); expect(bifurcate(['beep', 'boop', 'foo', 'bar'], [true, true, false, true])).toEqual([
['beep', 'boop', 'bar'],
['foo']
]);
}); });

View File

@ -5,5 +5,8 @@ test('bifurcateBy is a Function', () => {
expect(bifurcateBy).toBeInstanceOf(Function); expect(bifurcateBy).toBeInstanceOf(Function);
}); });
test('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'] ]); expect(bifurcateBy(['beep', 'boop', 'foo', 'bar'], x => x[0] === 'b')).toEqual([
['beep', 'boop', 'bar'],
['foo']
]);
}); });

View File

@ -6,7 +6,7 @@ test('bindAll is a Function', () => {
}); });
var view = { var view = {
label: 'docs', label: 'docs',
'click': function() { click: function() {
return 'clicked ' + this.label; return 'clicked ' + this.label;
} }
}; };

View File

@ -20,17 +20,23 @@ test('chunk(string, 2) returns [ st, ri, ng ]', () => {
expect(chunk('string', 2)).toEqual(['st', 'ri', 'ng']); expect(chunk('string', 2)).toEqual(['st', 'ri', 'ng']);
}); });
test('chunk() throws an error', () => { test('chunk() throws an error', () => {
expect(() => {chunk();}).toThrow(); expect(() => {
chunk();
}).toThrow();
}); });
test('chunk(undefined) throws an error', () => { test('chunk(undefined) throws an error', () => {
expect(() => {chunk(undefined);}).toThrow(); expect(() => {
chunk(undefined);
}).toThrow();
}); });
test('chunk(null) throws an error', () => { test('chunk(null) throws an error', () => {
expect(() => {chunk(null);}).toThrow(); expect(() => {
chunk(null);
}).toThrow();
}); });
let start = new Date().getTime(); let start = new Date().getTime();
chunk('This is a string', 2); chunk('This is a string', 2);
let end = new Date().getTime(); let end = new Date().getTime();
test('chunk(This is a string, 2) takes less than 2s to run', () => { test('chunk(This is a string, 2) takes less than 2s to run', () => {
expect((end - start) < 2000).toBeTruthy(); expect(end - start < 2000).toBeTruthy();
}); });

View File

@ -9,5 +9,10 @@ let p1 = Promise.resolve(1);
let p2 = Promise.resolve(2); let p2 = Promise.resolve(2);
let p3 = new Promise(resolve => setTimeout(resolve, 2000, 3)); let p3 = new Promise(resolve => setTimeout(resolve, 2000, 3));
test('Works with multiple promises', () => { test('Works with multiple promises', () => {
Pall(p1, p2, p3).then(function(val) { expect(val).toBe([1, 2, 3]);}, function(reason){}); Pall(p1, p2, p3).then(
function(val) {
expect(val).toBe([1, 2, 3]);
},
function(reason) {}
);
}); });

View File

@ -5,5 +5,12 @@ test('compact is a Function', () => {
expect(compact).toBeInstanceOf(Function); expect(compact).toBeInstanceOf(Function);
}); });
test('Removes falsey values from an array', () => { test('Removes falsey values from an array', () => {
expect(compact([0, 1, false, 2, '', 3, 'a', 'e' * 23, NaN, 's', 34])).toEqual([ 1, 2, 3, 'a', 's', 34 ]); expect(compact([0, 1, false, 2, '', 3, 'a', 'e' * 23, NaN, 's', 34])).toEqual([
1,
2,
3,
'a',
's',
34
]);
}); });

View File

@ -6,7 +6,10 @@ test('compose is a 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 = compose(add5, multiply); const multiplyAndAdd5 = compose(
add5,
multiply
);
test('Performs right-to-left function composition', () => { test('Performs right-to-left function composition', () => {
expect(multiplyAndAdd5(5, 2)).toBe(15); expect(multiplyAndAdd5(5, 2)).toBe(15);
}); });

View File

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

View File

@ -5,5 +5,7 @@ test('debounce is a Function', () => {
expect(debounce).toBeInstanceOf(Function); expect(debounce).toBeInstanceOf(Function);
}); });
test('Works as expected', () => { test('Works as expected', () => {
debounce(() => { expect(true).toBeTruthy(); }); debounce(() => {
expect(true).toBeTruthy();
});
}); });

View File

@ -6,7 +6,7 @@ test('deepClone is a Function', () => {
}); });
const a = { foo: 'bar', obj: { a: 1, b: 2 } }; const a = { foo: 'bar', obj: { a: 1, b: 2 } };
const b = deepClone(a); const b = deepClone(a);
const c = [{foo: "bar"}]; const c = [{ foo: 'bar' }];
const d = deepClone(c); const d = deepClone(c);
test('Shallow cloning works', () => { test('Shallow cloning works', () => {
expect(a).not.toBe(b); expect(a).not.toBe(b);

View File

@ -5,5 +5,7 @@ test('differenceWith is a Function', () => {
expect(differenceWith).toBeInstanceOf(Function); expect(differenceWith).toBeInstanceOf(Function);
}); });
test('Filters out all values from an array', () => { test('Filters out all values from an array', () => {
expect(differenceWith([1, 1.2, 1.5, 3, 0], [1.9, 3, 0], (a, b) => Math.round(a) === Math.round(b))).toEqual([1, 1.2]); expect(
differenceWith([1, 1.2, 1.5, 3, 0], [1.9, 3, 0], (a, b) => Math.round(a) === Math.round(b))
).toEqual([1, 1.2]);
}); });

View File

@ -1,32 +1,32 @@
const expect = require("expect"); const expect = require('expect');
const dig = require("./dig.js"); const dig = require('./dig.js');
const data = { const data = {
level1: { level1: {
level2: { level2: {
level3: "some data", level3: 'some data',
level3f: false, level3f: false,
level3a: [1, 2, 3, 4] level3a: [1, 2, 3, 4]
} }
} }
}; };
test("dig is a Function", () => { test('dig is a Function', () => {
expect(dig).toBeInstanceOf(Function); expect(dig).toBeInstanceOf(Function);
}); });
test("Dig target success", () => { test('Dig target success', () => {
expect(dig(data, "level3")).toEqual("some data"); expect(dig(data, 'level3')).toEqual('some data');
}); });
test("Dig target with falsey value", () => { test('Dig target with falsey value', () => {
expect(dig(data, "level3f")).toEqual(false); expect(dig(data, 'level3f')).toEqual(false);
}); });
test("Dig target with array", () => { test('Dig target with array', () => {
expect(dig(data, "level3a")).toEqual([1,2,3,4]); expect(dig(data, 'level3a')).toEqual([1, 2, 3, 4]);
}); });
test("Unknown target return undefined", () => { test('Unknown target return undefined', () => {
expect(dig(data, "level4")).toEqual(undefined); expect(dig(data, 'level4')).toEqual(undefined);
}); });

View File

@ -4,8 +4,10 @@ const equals = require('./equals.js');
test('equals is a Function', () => { test('equals is a Function', () => {
expect(equals).toBeInstanceOf(Function); expect(equals).toBeInstanceOf(Function);
}); });
test('{ a: [2, {e: 3}], b: [4], c: \'foo\' } is equal to { a: [2, {e: 3}], b: [4], c: \'foo\' }', () => { test("{ a: [2, {e: 3}], b: [4], c: 'foo' } is equal to { a: [2, {e: 3}], b: [4], c: 'foo' }", () => {
expect(equals({ a: [2, {e: 3}], b: [4], c: 'foo' }, { a: [2, {e: 3}], b: [4], c: 'foo' })).toBeTruthy(); expect(
equals({ a: [2, { e: 3 }], b: [4], c: 'foo' }, { a: [2, { e: 3 }], b: [4], c: 'foo' })
).toBeTruthy();
}); });
test('[1,2,3] is equal to [1,2,3]', () => { test('[1,2,3] is equal to [1,2,3]', () => {
expect(equals([1, 2, 3], [1, 2, 3])).toBeTruthy(); expect(equals([1, 2, 3], [1, 2, 3])).toBeTruthy();

View File

@ -5,5 +5,7 @@ test('escapeHTML is a Function', () => {
expect(escapeHTML).toBeInstanceOf(Function); expect(escapeHTML).toBeInstanceOf(Function);
}); });
test('Escapes a string for use in HTML', () => { test('Escapes a string for use in HTML', () => {
expect(escapeHTML('<a href="#">Me & you</a>')).toBe('&lt;a href=&quot;#&quot;&gt;Me &amp; you&lt;/a&gt;'); expect(escapeHTML('<a href="#">Me & you</a>')).toBe(
'&lt;a href=&quot;#&quot;&gt;Me &amp; you&lt;/a&gt;'
);
}); });

View File

@ -7,4 +7,3 @@ test('filterNonUnique is a Function', () => {
test('Filters out the non-unique values in an array', () => { test('Filters out the non-unique values in an array', () => {
expect(filterNonUnique([1, 2, 2, 3, 4, 4, 5])).toEqual([1, 3, 5]); expect(filterNonUnique([1, 2, 2, 3, 4, 4, 5])).toEqual([1, 3, 5]);
}); });

View File

@ -6,27 +6,31 @@ test('filterNonUniqueBy is a Function', () => {
}); });
test('filterNonUniqueBy works for properties', () => { test('filterNonUniqueBy works for properties', () => {
expect(filterNonUniqueBy( expect(
filterNonUniqueBy(
[ [
{ id: 0, value: 'a' }, { id: 0, value: 'a' },
{ id: 1, value: 'b' }, { id: 1, value: 'b' },
{ id: 2, value: 'c' }, { id: 2, value: 'c' },
{ id: 1, value: 'd' }, { id: 1, value: 'd' },
{ id: 0, value: 'e' }, { id: 0, value: 'e' }
], ],
(a, b) => a.id === b.id (a, b) => a.id === b.id
)).toEqual([ { id: 2, value: 'c' } ]); )
).toEqual([{ id: 2, value: 'c' }]);
}); });
test('filterNonUniqueBy works for nested properties', () => { test('filterNonUniqueBy works for nested properties', () => {
expect(filterNonUniqueBy( expect(
filterNonUniqueBy(
[ [
{ id: 0, value: 'a', n: { p: 0 } }, { id: 0, value: 'a', n: { p: 0 } },
{ id: 1, value: 'b', n: { p: 1 } }, { id: 1, value: 'b', n: { p: 1 } },
{ id: 2, value: 'c', n: { p: 2 } }, { id: 2, value: 'c', n: { p: 2 } },
{ id: 1, value: 'd', n: { p: 0 } }, { id: 1, value: 'd', n: { p: 0 } },
{ id: 0, value: 'e', n: {p: 1} }, { id: 0, value: 'e', n: { p: 1 } }
], ],
(a, b) => a.id === b.id (a, b) => a.id === b.id
)).toEqual([ { id: 2, value: 'c', n: {p: 2} } ]); )
).toEqual([{ id: 2, value: 'c', n: { p: 2 } }]);
}); });

View File

@ -5,11 +5,14 @@ test('findKey is a Function', () => {
expect(findKey).toBeInstanceOf(Function); expect(findKey).toBeInstanceOf(Function);
}); });
test('Returns the appropriate key', () => { test('Returns the appropriate key', () => {
expect(findKey( expect(
findKey(
{ {
barney: { age: 36, active: true }, barney: { age: 36, active: true },
fred: { age: 40, active: false }, fred: { age: 40, active: false },
pebbles: { age: 1, active: true } pebbles: { age: 1, active: true }
}, },
o => o['active'])).toBe('barney'); o => o['active']
)
).toBe('barney');
}); });

View File

@ -5,11 +5,14 @@ test('findLastKey is a Function', () => {
expect(findLastKey).toBeInstanceOf(Function); expect(findLastKey).toBeInstanceOf(Function);
}); });
test('eturns the appropriate key', () => { test('eturns the appropriate key', () => {
expect(findLastKey( expect(
findLastKey(
{ {
barney: { age: 36, active: true }, barney: { age: 36, active: true },
fred: { age: 40, active: false }, fred: { age: 40, active: false },
pebbles: { age: 1, active: true } pebbles: { age: 1, active: true }
}, },
o => o['active'])).toBe('pebbles'); o => o['active']
)
).toBe('pebbles');
}); });

View File

@ -5,7 +5,7 @@ test('forEachRight is a Function', () => {
expect(forEachRight).toBeInstanceOf(Function); expect(forEachRight).toBeInstanceOf(Function);
}); });
let output = ''; let output = '';
forEachRight([1, 2, 3, 4], val => output+=val); forEachRight([1, 2, 3, 4], val => (output += val));
test('Iterates over the array in reverse', () => { test('Iterates over the array in reverse', () => {
expect(output).toBe('4321'); expect(output).toBe('4321');
}); });

View File

@ -6,6 +6,6 @@ test('forOwn is a Function', () => {
}); });
let output = []; let output = [];
forOwn({ foo: 'bar', a: 1 }, v => output.push(v)); forOwn({ foo: 'bar', a: 1 }, v => output.push(v));
test('Iterates over an element\'s key-value pairs', () => { test("Iterates over an element's key-value pairs", () => {
expect(output).toEqual(['bar', 1]); expect(output).toEqual(['bar', 1]);
}); });

View File

@ -6,6 +6,6 @@ test('forOwnRight is a Function', () => {
}); });
let output = []; let output = [];
forOwnRight({ foo: 'bar', a: 1 }, v => output.push(v)); forOwnRight({ foo: 'bar', a: 1 }, v => output.push(v));
test('Iterates over an element\'s key-value pairs in reverse', () => { test("Iterates over an element's key-value pairs in reverse", () => {
expect(output).toEqual([1, 'bar']); expect(output).toEqual([1, 'bar']);
}); });

View File

@ -8,5 +8,7 @@ test('Returns the human readable format of the given number of milliseconds', ()
expect(formatDuration(1001)).toBe('1 second, 1 millisecond'); expect(formatDuration(1001)).toBe('1 second, 1 millisecond');
}); });
test('Returns the human readable format of the given number of milliseconds', () => { test('Returns the human readable format of the given number of milliseconds', () => {
expect(formatDuration(34325055574)).toBe('397 days, 6 hours, 44 minutes, 15 seconds, 574 milliseconds'); expect(formatDuration(34325055574)).toBe(
'397 days, 6 hours, 44 minutes, 15 seconds, 574 milliseconds'
);
}); });

View File

@ -8,7 +8,9 @@ test('Converts a string from camelcase', () => {
expect(fromCamelCase('someDatabaseFieldName', ' ')).toBe('some database field name'); expect(fromCamelCase('someDatabaseFieldName', ' ')).toBe('some database field name');
}); });
test('Converts a string from camelcase', () => { test('Converts a string from camelcase', () => {
expect(fromCamelCase('someLabelThatNeedsToBeCamelized', '-')).toBe('some-label-that-needs-to-be-camelized'); expect(fromCamelCase('someLabelThatNeedsToBeCamelized', '-')).toBe(
'some-label-that-needs-to-be-camelized'
);
}); });
test('Converts a string from camelcase', () => { test('Converts a string from camelcase', () => {
expect(fromCamelCase('someJavascriptProperty', '_')).toBe('some_javascript_property'); expect(fromCamelCase('someJavascriptProperty', '_')).toBe('some_javascript_property');

View File

@ -8,7 +8,9 @@ test('functionName is a Function', () => {
test('Works for native functions', () => { test('Works for native functions', () => {
expect(functionName(Math.max)).toBe('max'); expect(functionName(Math.max)).toBe('max');
}); });
function fun(x) {return x;} function fun(x) {
return x;
}
test('Works for functions', () => { test('Works for functions', () => {
expect(functionName(fun)).toBe('fun'); expect(functionName(fun)).toBe('fun');
}); });

View File

@ -5,5 +5,8 @@ test('getURLParameters is a Function', () => {
expect(getURLParameters).toBeInstanceOf(Function); expect(getURLParameters).toBeInstanceOf(Function);
}); });
test('Returns an object containing the parameters of the current URL', () => { test('Returns an object containing the parameters of the current URL', () => {
expect(getURLParameters('http://url.com/page?name=Adam&surname=Smith')).toEqual({name: 'Adam', surname: 'Smith'}); expect(getURLParameters('http://url.com/page?name=Adam&surname=Smith')).toEqual({
name: 'Adam',
surname: 'Smith'
});
}); });

View File

@ -5,5 +5,7 @@ test('hashNode is a Function', () => {
expect(hashNode).toBeInstanceOf(Function); expect(hashNode).toBeInstanceOf(Function);
}); });
test('Produces the appropriate hash', () => { test('Produces the appropriate hash', () => {
hashNode(JSON.stringify({ a: 'a', b: [1, 2, 3, 4], foo: { c: 'bar' } })).then(v => expect(v).toBe('04aa106279f5977f59f9067fa9712afc4aedc6f5862a8defc34552d8c7206393')); hashNode(JSON.stringify({ a: 'a', b: [1, 2, 3, 4], foo: { c: 'bar' } })).then(v =>
expect(v).toBe('04aa106279f5977f59f9067fa9712afc4aedc6f5862a8defc34552d8c7206393')
);
}); });

View File

@ -17,17 +17,23 @@ test('head(String) returns S', () => {
expect(head('String')).toBe('S'); expect(head('String')).toBe('S');
}); });
test('head(null) throws an Error', () => { test('head(null) throws an Error', () => {
expect(() => { head(null); }).toThrow(); expect(() => {
head(null);
}).toThrow();
}); });
test('head(undefined) throws an Error', () => { test('head(undefined) throws an Error', () => {
expect(() => { head(undefined); }).toThrow(); expect(() => {
head(undefined);
}).toThrow();
}); });
test('head() throws an Error', () => { test('head() throws an Error', () => {
expect(() => { head(); }).toThrow(); expect(() => {
head();
}).toThrow();
}); });
let start = new Date().getTime(); let start = new Date().getTime();
head([1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 1122, 32124, 23232]); head([1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 1122, 32124, 23232]);
let end = new Date().getTime(); let end = new Date().getTime();
test('head([1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 1122, 32124, 23232]) takes less than 2s to run', () => { test('head([1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 1122, 32124, 23232]) takes less than 2s to run', () => {
expect((end - start) < 2000).toBeTruthy(); expect(end - start < 2000).toBeTruthy();
}); });

View File

@ -1,6 +1,6 @@
const httpDelete = (url, callback, err = console.error) => { const httpDelete = (url, callback, err = console.error) => {
const request = new XMLHttpRequest(); const request = new XMLHttpRequest();
request.open("DELETE", url, true); request.open('DELETE', url, true);
request.onload = () => callback(request); request.onload = () => callback(request);
request.onerror = () => err(request); request.onerror = () => err(request);
request.send(); request.send();

View File

@ -1,6 +1,6 @@
const httpPut = (url, data, callback, err = console.error) => { const httpPut = (url, data, callback, err = console.error) => {
const request = new XMLHttpRequest(); const request = new XMLHttpRequest();
request.open("PUT", url, true); request.open('PUT', url, true);
request.setRequestHeader('Content-type', 'application/json; charset=utf-8'); request.setRequestHeader('Content-type', 'application/json; charset=utf-8');
request.onload = () => callback(request); request.onload = () => callback(request);
request.onerror = () => err(request); request.onerror = () => err(request);

View File

@ -5,5 +5,11 @@ test('intersectionWith is a Function', () => {
expect(intersectionWith).toBeInstanceOf(Function); expect(intersectionWith).toBeInstanceOf(Function);
}); });
test('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))).toEqual([1.5, 3, 0]); expect(
intersectionWith(
[1, 1.2, 1.5, 3, 0],
[1.9, 3, 0, 3.9],
(a, b) => Math.round(a) === Math.round(b)
)
).toEqual([1.5, 3, 0]);
}); });

View File

@ -4,9 +4,12 @@ const invertKeyValues = require('./invertKeyValues.js');
test('invertKeyValues is a Function', () => { test('invertKeyValues is a Function', () => {
expect(invertKeyValues).toBeInstanceOf(Function); expect(invertKeyValues).toBeInstanceOf(Function);
}); });
test('invertKeyValues({ a: 1, b: 2, c: 1 }) returns { 1: [ \'a\', \'c\' ], 2: [ \'b\' ] }', () => { test("invertKeyValues({ a: 1, b: 2, c: 1 }) returns { 1: [ 'a', 'c' ], 2: [ 'b' ] }", () => {
expect(invertKeyValues({ a: 1, b: 2, c: 1 })).toEqual({ 1: ['a', 'c'], 2: ['b'] }); expect(invertKeyValues({ a: 1, b: 2, c: 1 })).toEqual({ 1: ['a', 'c'], 2: ['b'] });
}); });
test('invertKeyValues({ a: 1, b: 2, c: 1 }, value => \'group\' + value) returns { group1: [ \'a\', \'c\' ], group2: [ \'b\' ] }', () => { test("invertKeyValues({ a: 1, b: 2, c: 1 }, value => 'group' + value) returns { group1: [ 'a', 'c' ], group2: [ 'b' ] }", () => {
expect(invertKeyValues({ a: 1, b: 2, c: 1 }, value => 'group' + value)).toEqual( { group1: [ 'a', 'c' ], group2: [ 'b' ] }); expect(invertKeyValues({ a: 1, b: 2, c: 1 }, value => 'group' + value)).toEqual({
group1: ['a', 'c'],
group2: ['b']
});
}); });

View File

@ -7,4 +7,3 @@ test('isDivisible is a Function', () => {
test('The number 6 is divisible by 3', () => { test('The number 6 is divisible by 3', () => {
expect(isDivisible(6, 3)).toBeTruthy(); expect(isDivisible(6, 3)).toBeTruthy();
}); });

View File

@ -10,4 +10,3 @@ test('passed value is a function', () => {
test('passed value is not a function', () => { test('passed value is not a function', () => {
expect(isFunction('x')).toBeFalsy(); expect(isFunction('x')).toBeFalsy();
}); });

View File

@ -16,4 +16,3 @@ test('isObject({ a:1 }) is a object', () => {
test('isObject(true) is not a object', () => { test('isObject(true) is not a object', () => {
expect(isObject(true)).toBeFalsy(); expect(isObject(true)).toBeFalsy();
}); });

View File

@ -19,7 +19,7 @@ test('isPrimitive(true) is primitive', () => {
test('isPrimitive(50) is primitive', () => { test('isPrimitive(50) is primitive', () => {
expect(isPrimitive(50)).toBeTruthy(); expect(isPrimitive(50)).toBeTruthy();
}); });
test('isPrimitive(\'Hello\') is primitive', () => { test("isPrimitive('Hello') is primitive", () => {
expect(isPrimitive('Hello')).toBeTruthy(); expect(isPrimitive('Hello')).toBeTruthy();
}); });
test('isPrimitive(false) is primitive', () => { test('isPrimitive(false) is primitive', () => {
@ -38,5 +38,5 @@ let start = new Date().getTime();
isPrimitive({ a: 123 }); isPrimitive({ a: 123 });
let end = new Date().getTime(); let end = new Date().getTime();
test('isPrimitive({ a: 123 }) takes less than 2s to run', () => { test('isPrimitive({ a: 123 }) takes less than 2s to run', () => {
expect((end - start) < 2000).toBeTruthy(); expect(end - start < 2000).toBeTruthy();
}); });

View File

@ -5,11 +5,13 @@ test('isPromiseLike is a Function', () => {
expect(isPromiseLike).toBeInstanceOf(Function); expect(isPromiseLike).toBeInstanceOf(Function);
}); });
test('Returns true for a promise-like object', () => { test('Returns true for a promise-like object', () => {
expect(isPromiseLike({ expect(
isPromiseLike({
then: function() { then: function() {
return ''; return '';
} }
})).toBeTruthy(); })
).toBeTruthy();
}); });
test('Returns false for an empty object', () => { test('Returns false for an empty object', () => {
expect(isPromiseLike({})).toBeFalsy(); expect(isPromiseLike({})).toBeFalsy();

View File

@ -1,5 +1,11 @@
const isSimilar = (pattern, str) => const isSimilar = (pattern, str) =>
[...str].reduce( [...str].reduce(
(matchIndex, char) => char.toLowerCase() === (pattern[matchIndex] || '').toLowerCase() ? matchIndex + 1 : matchIndex, 0 (matchIndex, char) =>
) === pattern.length ? true : false; char.toLowerCase() === (pattern[matchIndex] || '').toLowerCase()
? matchIndex + 1
: matchIndex,
0
) === pattern.length
? true
: false;
module.exports = isSimilar; module.exports = isSimilar;

View File

@ -17,17 +17,23 @@ test('last(String) returns g', () => {
expect(last('String')).toBe('g'); expect(last('String')).toBe('g');
}); });
test('last(null) throws an Error', () => { test('last(null) throws an Error', () => {
expect(() => { last(null); }).toThrow(); expect(() => {
last(null);
}).toThrow();
}); });
test('last(undefined) throws an Error', () => { test('last(undefined) throws an Error', () => {
expect(() => { last(undefined); }).toThrow(); expect(() => {
last(undefined);
}).toThrow();
}); });
test('last() throws an Error', () => { test('last() throws an Error', () => {
expect(() => { last(); }).toThrow(); expect(() => {
last();
}).toThrow();
}); });
let start = new Date().getTime(); let start = new Date().getTime();
last([1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 1122, 32124, 23232]); last([1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 1122, 32124, 23232]);
let end = new Date().getTime(); let end = new Date().getTime();
test('last([1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 1122, 32124, 23232]) takes less than 2s to run', () => { test('last([1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 1122, 32124, 23232]) takes less than 2s to run', () => {
expect((end - start) < 2000).toBeTruthy(); expect(end - start < 2000).toBeTruthy();
}); });

View File

@ -1,15 +1,22 @@
const levenshteinDistance = (string1, string2) => { const levenshteinDistance = (string1, string2) => {
if (string1.length === 0) return string2.length; if (string1.length === 0) return string2.length;
if (string2.length === 0) return string1.length; if (string2.length === 0) return string1.length;
let matrix = Array(string2.length + 1).fill(0).map((x,i) => [i]); let matrix = Array(string2.length + 1)
matrix[0] = Array(string1.length + 1).fill(0).map((x,i) => i); .fill(0)
.map((x, i) => [i]);
matrix[0] = Array(string1.length + 1)
.fill(0)
.map((x, i) => i);
for (let i = 1; i <= string2.length; i++) { for (let i = 1; i <= string2.length; i++) {
for (let j = 1; j <= string1.length; j++) { for (let j = 1; j <= string1.length; j++) {
if (string2[i - 1] === string1[j - 1]) { if (string2[i - 1] === string1[j - 1]) {
matrix[i][j] = matrix[i - 1][j - 1]; matrix[i][j] = matrix[i - 1][j - 1];
} } else {
else{ matrix[i][j] = Math.min(
matrix[i][j] = Math.min(matrix[i-1][j-1]+1, matrix[i][j-1]+1, matrix[i-1][j]+1); matrix[i - 1][j - 1] + 1,
matrix[i][j - 1] + 1,
matrix[i - 1][j] + 1
);
} }
} }
} }

View File

@ -5,8 +5,12 @@ test('matches is a Function', () => {
expect(matches).toBeInstanceOf(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(); 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(); expect(
matches({ hair: 'long', beard: true }, { age: 25, hair: 'long', beard: true })
).toBeFalsy();
}); });

View File

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

View File

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

View File

@ -8,5 +8,5 @@ test('Returns the n minimum elements from the provided array', () => {
expect(minN([1, 2, 3])).toEqual([1]); expect(minN([1, 2, 3])).toEqual([1]);
}); });
test('Returns the n minimum elements from the provided array', () => { test('Returns the n minimum elements from the provided array', () => {
expect(minN([1, 2, 3], 2), ).toEqual([1, 2]); expect(minN([1, 2, 3], 2)).toEqual([1, 2]);
}); });

View File

@ -15,4 +15,3 @@ const last = nthArg(-1);
test('Works for negative values', () => { test('Works for negative values', () => {
expect(last(1, 2, 3, 4, 5)).toBe(5); expect(last(1, 2, 3, 4, 5)).toBe(5);
}); });

View File

@ -5,5 +5,5 @@ 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'])).toEqual({ 'a': 1, 'c': 3 }); expect(omit({ a: 1, b: '2', c: 3 }, ['b'])).toEqual({ a: 1, c: 3 });
}); });

View File

@ -6,8 +6,16 @@ test('orderBy is a 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'])).toEqual([{name: 'barney', age: 36}, {name: 'fred', age: 48}, {name: 'fred', 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'])).toEqual( [{name: 'barney', age: 36}, {name: 'fred', age: 40}, {name: 'fred', age: 48}]); expect(orderBy(users, ['name', 'age'])).toEqual([
{ name: 'barney', age: 36 },
{ name: 'fred', age: 40 },
{ name: 'fred', age: 48 }
]);
}); });

View File

@ -5,6 +5,9 @@ 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)).toEqual([[{ 'user': 'fred', 'age': 40, 'active': true }],[{ 'user': 'barney', 'age': 36, 'active': false }]]); expect(partition(users, o => o.active)).toEqual([
[{ user: 'fred', age: 40, active: true }],
[{ user: 'barney', age: 36, active: false }]
]);
}); });

View File

@ -5,5 +5,12 @@ 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])).toEqual([ [ 1, 33, 5 ], [ 1, 5, 33 ], [ 33, 1, 5 ], [ 33, 5, 1 ], [ 5, 1, 33 ], [ 5, 33, 1 ] ]); expect(permutations([1, 33, 5])).toEqual([
[1, 33, 5],
[1, 5, 33],
[33, 1, 5],
[33, 5, 1],
[5, 1, 33],
[5, 33, 1]
]);
}); });

View File

@ -5,5 +5,5 @@ 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'])).toEqual({ 'a': 1, 'c': 3 }); expect(pick({ a: 1, b: '2', c: 3 }, ['a', 'c'])).toEqual({ a: 1, c: 3 });
}); });

View File

@ -5,5 +5,5 @@ 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')).toEqual({ 'a': 1, 'c': 3 }); expect(pickBy({ a: 1, b: '2', c: 3 }, x => typeof x === 'number')).toEqual({ a: 1, c: 3 });
}); });

View File

@ -5,11 +5,12 @@ test('pipeAsyncFunctions is a Function', () => {
expect(pipeAsyncFunctions).toBeInstanceOf(Function); expect(pipeAsyncFunctions).toBeInstanceOf(Function);
}); });
test('pipeAsyncFunctions result should be 15', () => { test('pipeAsyncFunctions result should be 15', () => {
expect(pipeAsyncFunctions( expect(
(x) => x + 1, pipeAsyncFunctions(
(x) => new Promise((resolve) => setTimeout(() => resolve(x + 2), 0)), x => x + 1,
(x) => x + 3, x => new Promise(resolve => setTimeout(() => resolve(x + 2), 0)),
async(x) => await x + 4, x => x + 3,
) async x => (await x) + 4
(5)).resolves.toBe(15); )(5)
).resolves.toBe(15);
}); });

View File

@ -11,23 +11,33 @@ test('quickSort([-1, 0, -2]) returns [-2, -1, 0]', () => {
expect(quickSort([-1, 0, -2])).toEqual([-2, -1, 0]); expect(quickSort([-1, 0, -2])).toEqual([-2, -1, 0]);
}); });
test('quickSort() throws an error', () => { test('quickSort() throws an error', () => {
expect(() => { quickSort(); }).toThrow(); expect(() => {
quickSort();
}).toThrow();
}); });
test('quickSort(123) throws an error', () => { test('quickSort(123) throws an error', () => {
expect(() => { quickSort(123); }).toThrow(); expect(() => {
quickSort(123);
}).toThrow();
}); });
test('quickSort({ 234: string}) throws an error', () => { test('quickSort({ 234: string}) throws an error', () => {
expect(() => { quickSort({ 234: string}); }).toThrow(); expect(() => {
quickSort({ 234: string });
}).toThrow();
}); });
test('quickSort(null) throws an error', () => { test('quickSort(null) throws an error', () => {
expect(() => { quickSort(null); }).toThrow(); expect(() => {
quickSort(null);
}).toThrow();
}); });
test('quickSort(undefined) throws an error', () => { test('quickSort(undefined) throws an error', () => {
expect(() => { quickSort(undefined); }).toThrow(); expect(() => {
quickSort(undefined);
}).toThrow();
}); });
let start = new Date().getTime(); let start = new Date().getTime();
quickSort([11, 1, 324, 23232, -1, 53, 2, 524, 32, 13, 156, 133, 62, 12, 4]); quickSort([11, 1, 324, 23232, -1, 53, 2, 524, 32, 13, 156, 133, 62, 12, 4]);
let end = new Date().getTime(); let end = new Date().getTime();
test('quickSort([11, 1, 324, 23232, -1, 53, 2, 524, 32, 13, 156, 133, 62, 12, 4]) takes less than 2s to run', () => { test('quickSort([11, 1, 324, 23232, -1, 53, 2, 524, 32, 13, 156, 133, 62, 12, 4]) takes less than 2s to run', () => {
expect((end - start) < 2000).toBeTruthy(); expect(end - start < 2000).toBeTruthy();
}); });

View File

@ -11,5 +11,9 @@ test('The color code starts with "#"', () => {
expect(randomHexColorCode().startsWith('#')).toBeTruthy(); expect(randomHexColorCode().startsWith('#')).toBeTruthy();
}); });
test('The color code contains only valid hex-digits', () => { test('The color code contains only valid hex-digits', () => {
expect(randomHexColorCode().slice(1).match(/[^0123456789abcdef]/i) === null).toBeTruthy(); expect(
randomHexColorCode()
.slice(1)
.match(/[^0123456789abcdef]/i) === null
).toBeTruthy();
}); });

View File

@ -13,6 +13,6 @@ test('The returned array contains only integers', () => {
test('The returned array has the proper length', () => { test('The returned array has the proper length', () => {
expect(arr.length).toBe(10); expect(arr.length).toBe(10);
}); });
test('The returned array\'s values lie between provided lowerLimit and upperLimit (both inclusive).', () => { test("The returned array's values lie between provided lowerLimit and upperLimit (both inclusive).", () => {
expect(arr.every(x => (x >= lowerLimit) && (x <= upperLimit))).toBeTruthy(); expect(arr.every(x => x >= lowerLimit && x <= upperLimit)).toBeTruthy();
}); });

View File

@ -11,5 +11,5 @@ test('The returned value is an integer', () => {
}); });
const numberForTest = randomIntegerInRange(lowerLimit, upperLimit); const numberForTest = randomIntegerInRange(lowerLimit, upperLimit);
test('The returned value lies between provided lowerLimit and upperLimit (both inclusive).', () => { test('The returned value lies between provided lowerLimit and upperLimit (both inclusive).', () => {
expect((numberForTest >= lowerLimit) && (numberForTest <= upperLimit)).toBeTruthy(); expect(numberForTest >= lowerLimit && numberForTest <= upperLimit).toBeTruthy();
}); });

View File

@ -11,5 +11,5 @@ test('The returned value is a number', () => {
}); });
const numberForTest = randomNumberInRange(lowerLimit, upperLimit); const numberForTest = randomNumberInRange(lowerLimit, upperLimit);
test('The returned value lies between provided lowerLimit and upperLimit (both inclusive).', () => { test('The returned value lies between provided lowerLimit and upperLimit (both inclusive).', () => {
expect((numberForTest >= lowerLimit) && (numberForTest <= upperLimit)).toBeTruthy(); expect(numberForTest >= lowerLimit && numberForTest <= upperLimit).toBeTruthy();
}); });

View File

@ -5,5 +5,13 @@ test('reduceSuccessive is a Function', () => {
expect(reduceSuccessive).toBeInstanceOf(Function); expect(reduceSuccessive).toBeInstanceOf(Function);
}); });
test('Returns the array of successively reduced values', () => { test('Returns the array of successively reduced values', () => {
expect(reduceSuccessive([1, 2, 3, 4, 5, 6], (acc, val) => acc + val, 0)).toEqual([0, 1, 3, 6, 10, 15, 21]); expect(reduceSuccessive([1, 2, 3, 4, 5, 6], (acc, val) => acc + val, 0)).toEqual([
0,
1,
3,
6,
10,
15,
21
]);
}); });

View File

@ -11,8 +11,10 @@ test('Returns the maximum of an array', () => {
expect(reduceWhich([1, 3, 2], (a, b) => b - a)).toBe(3); expect(reduceWhich([1, 3, 2], (a, b) => b - a)).toBe(3);
}); });
test('Returns the object with the minimum specified value in an array', () => { test('Returns the object with the minimum specified value in an array', () => {
expect(reduceWhich( expect(
reduceWhich(
[{ name: 'Tom', age: 12 }, { name: 'Jack', age: 18 }, { name: 'Lucy', age: 9 }], [{ name: 'Tom', age: 12 }, { name: 'Jack', age: 18 }, { name: 'Lucy', age: 9 }],
(a, b) => a.age - b.age (a, b) => a.age - b.age
)).toEqual({name: "Lucy", age: 9}); )
).toEqual({ name: 'Lucy', age: 9 });
}); });

View File

@ -17,5 +17,7 @@ const data = [
} }
]; ];
test('Filter an array of objects based on a condition while also filtering out unspecified keys.', () => { test('Filter an array of objects based on a condition while also filtering out unspecified keys.', () => {
expect(reducedFilter(data, ['id', 'name'], item => item.age > 24)).toEqual([{ id: 2, name: 'mike'}]); expect(reducedFilter(data, ['id', 'name'], item => item.age > 24)).toEqual([
{ id: 2, name: 'mike' }
]);
}); });

View File

@ -4,17 +4,11 @@ const reject = require('./reject.js');
test('reject is a Function', () => { test('reject is a Function', () => {
expect(reject).toBeInstanceOf(Function); expect(reject).toBeInstanceOf(Function);
}); });
const noEvens = reject( const noEvens = reject(x => x % 2 === 0, [1, 2, 3, 4, 5]);
(x) => x % 2 === 0,
[1, 2, 3, 4, 5]
);
test('Works with numbers', () => { test('Works with numbers', () => {
expect(noEvens).toEqual([1, 3, 5]); expect(noEvens).toEqual([1, 3, 5]);
}); });
const fourLettersOrLess = reject( const fourLettersOrLess = reject(word => word.length > 4, ['Apple', 'Pear', 'Kiwi', 'Banana']);
(word) => word.length > 4,
['Apple', 'Pear', 'Kiwi', 'Banana']
);
test('Works with strings', () => { test('Works with strings', () => {
expect(fourLettersOrLess).toEqual(['Pear', 'Kiwi']); expect(fourLettersOrLess).toEqual(['Pear', 'Kiwi']);
}); });

View File

@ -35,5 +35,5 @@ let start = new Date().getTime();
round(123.3423345345345345344, 11); round(123.3423345345345345344, 11);
let end = new Date().getTime(); let end = new Date().getTime();
test('round(123.3423345345345345344, 11) takes less than 2s to run', () => { test('round(123.3423345345345345344, 11) takes less than 2s to run', () => {
expect((end - start) < 2000).toBeTruthy(); expect(end - start < 2000).toBeTruthy();
}); });

View File

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

View File

@ -5,5 +5,11 @@ test('splitLines is a Function', () => {
expect(splitLines).toBeInstanceOf(Function); expect(splitLines).toBeInstanceOf(Function);
}); });
test('Splits a multiline string into an array of lines.', () => { test('Splits a multiline string into an array of lines.', () => {
expect(splitLines('This\nis a\nmultiline\nstring.\n')).toEqual(['This', 'is a', 'multiline', 'string.', '']); expect(splitLines('This\nis a\nmultiline\nstring.\n')).toEqual([
'This',
'is a',
'multiline',
'string.',
''
]);
}); });

View File

@ -5,5 +5,7 @@ test('stripHTMLTags is a Function', () => {
expect(stripHTMLTags).toBeInstanceOf(Function); expect(stripHTMLTags).toBeInstanceOf(Function);
}); });
test('Removes HTML tags', () => { test('Removes HTML tags', () => {
expect(stripHTMLTags('<p><em>lorem</em> <strong>ipsum</strong></p><img /><br>')).toBe('lorem ipsum'); expect(stripHTMLTags('<p><em>lorem</em> <strong>ipsum</strong></p><img /><br>')).toBe(
'lorem ipsum'
);
}); });

View File

@ -5,8 +5,11 @@ test('symmetricDifferenceWith is a Function', () => {
expect(symmetricDifferenceWith).toBeInstanceOf(Function); expect(symmetricDifferenceWith).toBeInstanceOf(Function);
}); });
test('Returns the symmetric difference between two arrays, using a provided function as a comparator', () => { test('Returns the symmetric difference between two arrays, using a provided function as a comparator', () => {
expect(symmetricDifferenceWith( expect(
symmetricDifferenceWith(
[1, 1.2, 1.5, 3, 0], [1, 1.2, 1.5, 3, 0],
[1.9, 3, 0, 3.9], [1.9, 3, 0, 3.9],
(a, b) => Math.round(a) === Math.round(b))).toEqual([1, 1.2, 3.9]); (a, b) => Math.round(a) === Math.round(b)
)
).toEqual([1, 1.2, 3.9]);
}); });

View File

@ -4,33 +4,45 @@ const toCamelCase = require('./toCamelCase.js');
test('toCamelCase is a Function', () => { test('toCamelCase is a Function', () => {
expect(toCamelCase).toBeInstanceOf(Function); expect(toCamelCase).toBeInstanceOf(Function);
}); });
test('toCamelCase(\'some_database_field_name\') returns someDatabaseFieldName', () => { test("toCamelCase('some_database_field_name') returns someDatabaseFieldName", () => {
expect(toCamelCase('some_database_field_name')).toBe('someDatabaseFieldName'); expect(toCamelCase('some_database_field_name')).toBe('someDatabaseFieldName');
}); });
test('toCamelCase(\'Some label that needs to be camelized\') returns someLabelThatNeedsToBeCamelized', () => { test("toCamelCase('Some label that needs to be camelized') returns someLabelThatNeedsToBeCamelized", () => {
expect(toCamelCase('Some label that needs to be camelized')).toBe('someLabelThatNeedsToBeCamelized'); expect(toCamelCase('Some label that needs to be camelized')).toBe(
'someLabelThatNeedsToBeCamelized'
);
}); });
test('toCamelCase(\'some-javascript-property\') return someJavascriptProperty', () => { test("toCamelCase('some-javascript-property') return someJavascriptProperty", () => {
expect(toCamelCase('some-javascript-property')).toBe('someJavascriptProperty'); expect(toCamelCase('some-javascript-property')).toBe('someJavascriptProperty');
}); });
test('toCamelCase(\'some-mixed_string with spaces_underscores-and-hyphens\') returns someMixedStringWithSpacesUnderscoresAndHyphens', () => { test("toCamelCase('some-mixed_string with spaces_underscores-and-hyphens') returns someMixedStringWithSpacesUnderscoresAndHyphens", () => {
expect(toCamelCase('some-mixed_string with spaces_underscores-and-hyphens')).toBe('someMixedStringWithSpacesUnderscoresAndHyphens'); expect(toCamelCase('some-mixed_string with spaces_underscores-and-hyphens')).toBe(
'someMixedStringWithSpacesUnderscoresAndHyphens'
);
}); });
test('toCamelCase() throws a error', () => { test('toCamelCase() throws a error', () => {
expect(() => {toCamelCase(); }).toThrow(); expect(() => {
toCamelCase();
}).toThrow();
}); });
test('toCamelCase([]) throws a error', () => { test('toCamelCase([]) throws a error', () => {
expect(() => {toCamelCase([]); }).toThrow(); expect(() => {
toCamelCase([]);
}).toThrow();
}); });
test('toCamelCase({}) throws a error', () => { test('toCamelCase({}) throws a error', () => {
expect(() => {toCamelCase({}); }).toThrow(); expect(() => {
toCamelCase({});
}).toThrow();
}); });
test('toCamelCase(123) throws a error', () => { test('toCamelCase(123) throws a error', () => {
expect(() => {toCamelCase(123); }).toThrow(); expect(() => {
toCamelCase(123);
}).toThrow();
}); });
let start = new Date().getTime(); let start = new Date().getTime();
toCamelCase('some-mixed_string with spaces_underscores-and-hyphens'); toCamelCase('some-mixed_string with spaces_underscores-and-hyphens');
let end = new Date().getTime(); let end = new Date().getTime();
test('toCamelCase(some-mixed_string with spaces_underscores-and-hyphens) takes less than 2s to run', () => { test('toCamelCase(some-mixed_string with spaces_underscores-and-hyphens) takes less than 2s to run', () => {
expect((end - start) < 2000).toBeTruthy(); expect(end - start < 2000).toBeTruthy();
}); });

View File

@ -11,5 +11,7 @@ test(' currency: US Dollar | currencyLangFormat: English (United States)', () =>
expect(toCurrency(123456.789, 'USD', 'en-us')).toEqual(expect.stringMatching(/\$\s*123,456.79/g)); expect(toCurrency(123456.789, 'USD', 'en-us')).toEqual(expect.stringMatching(/\$\s*123,456.79/g));
}); });
test('currency: Japanese Yen | currencyLangFormat: Local', () => { test('currency: Japanese Yen | currencyLangFormat: Local', () => {
expect(toCurrency(322342436423.2435, 'JPY')).toEqual(expect.stringMatching(/J*P*¥\s*322,342,436,423/g)); expect(toCurrency(322342436423.2435, 'JPY')).toEqual(
expect.stringMatching(/J*P*¥\s*322,342,436,423/g)
);
}); });

View File

@ -5,5 +5,5 @@ test('toDecimalMark is a Function', () => {
expect(toDecimalMark).toBeInstanceOf(Function); expect(toDecimalMark).toBeInstanceOf(Function);
}); });
test('convert a float-point arithmetic to the Decimal mark form', () => { test('convert a float-point arithmetic to the Decimal mark form', () => {
expect(toDecimalMark(12305030388.9087)).toBe("12,305,030,388.909"); expect(toDecimalMark(12305030388.9087)).toBe('12,305,030,388.909');
}); });

View File

@ -4,33 +4,45 @@ const toKebabCase = require('./toKebabCase.js');
test('toKebabCase is a Function', () => { test('toKebabCase is a Function', () => {
expect(toKebabCase).toBeInstanceOf(Function); expect(toKebabCase).toBeInstanceOf(Function);
}); });
test('toKebabCase(\'camelCase\') returns camel-case', () => { test("toKebabCase('camelCase') returns camel-case", () => {
expect(toKebabCase('camelCase')).toBe('camel-case'); expect(toKebabCase('camelCase')).toBe('camel-case');
}); });
test('toKebabCase(\'some text\') returns some-text', () => { test("toKebabCase('some text') returns some-text", () => {
expect(toKebabCase('some text')).toBe('some-text'); expect(toKebabCase('some text')).toBe('some-text');
}); });
test('toKebabCase(\'some-mixed-string With spaces-underscores-and-hyphens\') returns some-mixed-string-with-spaces-underscores-and-hyphens', () => { test("toKebabCase('some-mixed-string With spaces-underscores-and-hyphens') returns some-mixed-string-with-spaces-underscores-and-hyphens", () => {
expect(toKebabCase('some-mixed-string With spaces-underscores-and-hyphens')).toBe('some-mixed-string-with-spaces-underscores-and-hyphens'); expect(toKebabCase('some-mixed-string With spaces-underscores-and-hyphens')).toBe(
'some-mixed-string-with-spaces-underscores-and-hyphens'
);
}); });
test('toKebabCase(\'IAmListeningToFMWhileLoadingDifferentURLOnMyBrowserAndAlsoEditingSomeXMLAndHTML\') returns i-am-listening-to-fm-while-loading-different-url-on-my-browser-and-also-editing-some-xml-and-html', () => { test("toKebabCase('IAmListeningToFMWhileLoadingDifferentURLOnMyBrowserAndAlsoEditingSomeXMLAndHTML') returns i-am-listening-to-fm-while-loading-different-url-on-my-browser-and-also-editing-some-xml-and-html", () => {
expect(toKebabCase('IAmListeningToFMWhileLoadingDifferentURLOnMyBrowserAndAlsoEditingSomeXMLAndHTML')).toBe('i-am-listening-to-fm-while-loading-different-url-on-my-browser-and-also-editing-some-xml-and-html'); expect(
toKebabCase('IAmListeningToFMWhileLoadingDifferentURLOnMyBrowserAndAlsoEditingSomeXMLAndHTML')
).toBe(
'i-am-listening-to-fm-while-loading-different-url-on-my-browser-and-also-editing-some-xml-and-html'
);
}); });
test('toKebabCase() returns undefined', () => { test('toKebabCase() returns undefined', () => {
expect(toKebabCase()).toBe(undefined); expect(toKebabCase()).toBe(undefined);
}); });
test('toKebabCase([]) throws an erro', () => { test('toKebabCase([]) throws an erro', () => {
expect(() => { toKebabCase([]); }).toThrow(); expect(() => {
toKebabCase([]);
}).toThrow();
}); });
test('toKebabCase({}) throws an erro', () => { test('toKebabCase({}) throws an erro', () => {
expect(() => { toKebabCase({}); }).toThrow(); expect(() => {
toKebabCase({});
}).toThrow();
}); });
test('toKebabCase(123) throws an erro', () => { test('toKebabCase(123) throws an erro', () => {
expect(() => { toKebabCase(123); }).toThrow(); expect(() => {
toKebabCase(123);
}).toThrow();
}); });
let start = new Date().getTime(); let start = new Date().getTime();
toKebabCase('IAmListeningToFMWhileLoadingDifferentURLOnMyBrowserAndAlsoEditingSomeXMLAndHTML'); toKebabCase('IAmListeningToFMWhileLoadingDifferentURLOnMyBrowserAndAlsoEditingSomeXMLAndHTML');
let end = new Date().getTime(); let end = new Date().getTime();
test('toKebabCase(IAmListeningToFMWhileLoadingDifferentURLOnMyBrowserAndAlsoEditingSomeXMLAndHTML) takes less than 2s to run', () => { test('toKebabCase(IAmListeningToFMWhileLoadingDifferentURLOnMyBrowserAndAlsoEditingSomeXMLAndHTML) takes less than 2s to run', () => {
expect((end - start) < 2000).toBeTruthy(); expect(end - start < 2000).toBeTruthy();
}); });

View File

@ -10,7 +10,7 @@ test('Number(toSafeInteger(3.2)) is a number', () => {
test('Converts a value to a safe integer', () => { test('Converts a value to a safe integer', () => {
expect(toSafeInteger(3.2)).toBe(3); expect(toSafeInteger(3.2)).toBe(3);
}); });
test('toSafeInteger(\'4.2\') returns 4', () => { test("toSafeInteger('4.2') returns 4", () => {
expect(toSafeInteger('4.2')).toBe(4); expect(toSafeInteger('4.2')).toBe(4);
}); });
test('toSafeInteger(4.6) returns 5', () => { test('toSafeInteger(4.6) returns 5', () => {
@ -22,7 +22,7 @@ test('toSafeInteger([]) returns 0', () => {
test('isNaN(toSafeInteger([1.5, 3124])) is true', () => { test('isNaN(toSafeInteger([1.5, 3124])) is true', () => {
expect(isNaN(toSafeInteger([1.5, 3124]))).toBeTruthy(); expect(isNaN(toSafeInteger([1.5, 3124]))).toBeTruthy();
}); });
test('isNaN(toSafeInteger(\'string\')) is true', () => { test("isNaN(toSafeInteger('string')) is true", () => {
expect(isNaN(toSafeInteger('string'))).toBeTruthy(); expect(isNaN(toSafeInteger('string'))).toBeTruthy();
}); });
test('isNaN(toSafeInteger({})) is true', () => { test('isNaN(toSafeInteger({})) is true', () => {
@ -38,5 +38,5 @@ let start = new Date().getTime();
toSafeInteger(3.2); toSafeInteger(3.2);
let end = new Date().getTime(); let end = new Date().getTime();
test('toSafeInteger(3.2) takes less than 2s to run', () => { test('toSafeInteger(3.2) takes less than 2s to run', () => {
expect((end - start) < 2000).toBeTruthy(); expect(end - start < 2000).toBeTruthy();
}); });

View File

@ -4,33 +4,45 @@ const toSnakeCase = require('./toSnakeCase.js');
test('toSnakeCase is a Function', () => { test('toSnakeCase is a Function', () => {
expect(toSnakeCase).toBeInstanceOf(Function); expect(toSnakeCase).toBeInstanceOf(Function);
}); });
test('toSnakeCase(\'camelCase\') returns camel_case', () => { test("toSnakeCase('camelCase') returns camel_case", () => {
expect(toSnakeCase('camelCase')).toBe('camel_case'); expect(toSnakeCase('camelCase')).toBe('camel_case');
}); });
test('toSnakeCase(\'some text\') returns some_text', () => { test("toSnakeCase('some text') returns some_text", () => {
expect(toSnakeCase('some text')).toBe('some_text'); expect(toSnakeCase('some text')).toBe('some_text');
}); });
test('toSnakeCase(\'some-mixed_string With spaces_underscores-and-hyphens\') returns some_mixed_string_with_spaces_underscores_and_hyphens', () => { test("toSnakeCase('some-mixed_string With spaces_underscores-and-hyphens') returns some_mixed_string_with_spaces_underscores_and_hyphens", () => {
expect(toSnakeCase('some-mixed_string With spaces_underscores-and-hyphens')).toBe('some_mixed_string_with_spaces_underscores_and_hyphens'); expect(toSnakeCase('some-mixed_string With spaces_underscores-and-hyphens')).toBe(
'some_mixed_string_with_spaces_underscores_and_hyphens'
);
}); });
test('toSnakeCase(\'IAmListeningToFMWhileLoadingDifferentURLOnMyBrowserAndAlsoEditingSomeXMLAndHTML\') returns i_am_listening_to_fm_while_loading_different_url_on_my_browser_and_also_editing_some_xml_and_html', () => { test("toSnakeCase('IAmListeningToFMWhileLoadingDifferentURLOnMyBrowserAndAlsoEditingSomeXMLAndHTML') returns i_am_listening_to_fm_while_loading_different_url_on_my_browser_and_also_editing_some_xml_and_html", () => {
expect(toSnakeCase('IAmListeningToFMWhileLoadingDifferentURLOnMyBrowserAndAlsoEditingSomeXMLAndHTML')).toBe('i_am_listening_to_fm_while_loading_different_url_on_my_browser_and_also_editing_some_xml_and_html'); expect(
toSnakeCase('IAmListeningToFMWhileLoadingDifferentURLOnMyBrowserAndAlsoEditingSomeXMLAndHTML')
).toBe(
'i_am_listening_to_fm_while_loading_different_url_on_my_browser_and_also_editing_some_xml_and_html'
);
}); });
test('toSnakeCase() returns undefined', () => { test('toSnakeCase() returns undefined', () => {
expect(toSnakeCase()).toBe(undefined); expect(toSnakeCase()).toBe(undefined);
}); });
test('toSnakeCase([]) throws an error', () => { test('toSnakeCase([]) throws an error', () => {
expect(() => {toSnakeCase([]);}).toThrow(); expect(() => {
toSnakeCase([]);
}).toThrow();
}); });
test('toSnakeCase({}) throws an error', () => { test('toSnakeCase({}) throws an error', () => {
expect(() => {toSnakeCase({});}).toThrow(); expect(() => {
toSnakeCase({});
}).toThrow();
}); });
test('toSnakeCase(123) throws an error', () => { test('toSnakeCase(123) throws an error', () => {
expect(() => {toSnakeCase(123);}).toThrow(); expect(() => {
toSnakeCase(123);
}).toThrow();
}); });
let start = new Date().getTime(); let start = new Date().getTime();
toSnakeCase('IAmListeningToFMWhileLoadingDifferentURLOnMyBrowserAndAlsoEditingSomeXMLAndHTML'); toSnakeCase('IAmListeningToFMWhileLoadingDifferentURLOnMyBrowserAndAlsoEditingSomeXMLAndHTML');
let end = new Date().getTime(); let end = new Date().getTime();
test('toSnakeCase(IAmListeningToFMWhileLoadingDifferentURLOnMyBrowserAndAlsoEditingSomeXMLAndHTML) takes less than 2s to run', () => { test('toSnakeCase(IAmListeningToFMWhileLoadingDifferentURLOnMyBrowserAndAlsoEditingSomeXMLAndHTML) takes less than 2s to run', () => {
expect((end - start) < 2000).toBeTruthy(); expect(end - start < 2000).toBeTruthy();
}); });

View File

@ -5,10 +5,14 @@ test('transform is a Function', () => {
expect(transform).toBeInstanceOf(Function); expect(transform).toBeInstanceOf(Function);
}); });
test('Transforms an object', () => { test('Transforms an object', () => {
expect(transform( expect(
transform(
{ a: 1, b: 2, c: 1 }, { a: 1, b: 2, c: 1 },
(r, v, k) => { (r, v, k) => {
(r[v] || (r[v] = [])).push(k); (r[v] || (r[v] = [])).push(k);
return r; return r;
},{})).toEqual({ '1': ['a', 'c'], '2': ['b'] }); },
{}
)
).toEqual({ '1': ['a', 'c'], '2': ['b'] });
}); });

View File

@ -5,5 +5,10 @@ test('truthCheckCollection is a Function', () => {
expect(truthCheckCollection).toBeInstanceOf(Function); expect(truthCheckCollection).toBeInstanceOf(Function);
}); });
test('second argument is truthy on all elements of a collection', () => { test('second argument is truthy on all elements of a collection', () => {
expect(truthCheckCollection([{ user: 'Tinky-Winky', sex: 'male' }, { user: 'Dipsy', sex: 'male' }], 'sex')).toBeTruthy(); expect(
truthCheckCollection(
[{ user: 'Tinky-Winky', sex: 'male' }, { user: 'Dipsy', sex: 'male' }],
'sex'
)
).toBeTruthy();
}); });

View File

@ -7,4 +7,3 @@ test('unary is a Function', () => {
test('Discards arguments after the first one', () => { test('Discards arguments after the first one', () => {
expect(['6', '8', '10'].map(unary(parseInt))).toEqual([6, 8, 10]); expect(['6', '8', '10'].map(unary(parseInt))).toEqual([6, 8, 10]);
}); });

View File

@ -5,5 +5,7 @@ test('unescapeHTML is a Function', () => {
expect(unescapeHTML).toBeInstanceOf(Function); expect(unescapeHTML).toBeInstanceOf(Function);
}); });
test('Unescapes escaped HTML characters.', () => { test('Unescapes escaped HTML characters.', () => {
expect(unescapeHTML('&lt;a href=&quot;#&quot;&gt;Me &amp; you&lt;/a&gt;')).toBe('<a href="#">Me & you</a>'); expect(unescapeHTML('&lt;a href=&quot;#&quot;&gt;Me &amp; you&lt;/a&gt;')).toBe(
'<a href="#">Me & you</a>'
);
}); });

View File

@ -7,7 +7,7 @@ test('union is a Function', () => {
test('union([1, 2, 3], [4, 3, 2]) returns [1, 2, 3, 4]', () => { test('union([1, 2, 3], [4, 3, 2]) returns [1, 2, 3, 4]', () => {
expect(union([1, 2, 3], [4, 3, 2])).toEqual([1, 2, 3, 4]); expect(union([1, 2, 3], [4, 3, 2])).toEqual([1, 2, 3, 4]);
}); });
test('union(\'str\', \'asd\') returns [ \'s\', \'t\', \'r\', \'a\', \'d\' ]', () => { test("union('str', 'asd') returns [ 's', 't', 'r', 'a', 'd' ]", () => {
expect(union('str', 'asd')).toEqual(['s', 't', 'r', 'a', 'd']); expect(union('str', 'asd')).toEqual(['s', 't', 'r', 'a', 'd']);
}); });
test('union([[], {}], [1, 2, 3]) returns [[], {}, 1, 2, 3]', () => { test('union([[], {}], [1, 2, 3]) returns [[], {}, 1, 2, 3]', () => {
@ -17,26 +17,38 @@ test('union([], []) returns []', () => {
expect(union([], [])).toEqual([]); expect(union([], [])).toEqual([]);
}); });
test('union() throws an error', () => { test('union() throws an error', () => {
expect(() => {union(); }).toThrow(); expect(() => {
union();
}).toThrow();
}); });
test('union(true, \'str\') throws an error', () => { test("union(true, 'str') throws an error", () => {
expect(() => {union(true, 'str'); }).toThrow(); expect(() => {
union(true, 'str');
}).toThrow();
}); });
test('union(\'false\', true) throws an error', () => { test("union('false', true) throws an error", () => {
expect(() => {union('false', true); }).toThrow(); expect(() => {
union('false', true);
}).toThrow();
}); });
test('union((123, {}) throws an error', () => { test('union((123, {}) throws an error', () => {
expect(() => {union(123, {}); }).toThrow(); expect(() => {
union(123, {});
}).toThrow();
}); });
test('union([], {}) throws an error', () => { test('union([], {}) throws an error', () => {
expect(() => {union([], {}); }).toThrow(); expect(() => {
union([], {});
}).toThrow();
}); });
test('union(undefined, null) throws an error', () => { test('union(undefined, null) throws an error', () => {
expect(() => {union(undefined, null); }).toThrow(); expect(() => {
union(undefined, null);
}).toThrow();
}); });
let start = new Date().getTime(); let start = new Date().getTime();
union([1, 2, 3], [4, 3, 2]); union([1, 2, 3], [4, 3, 2]);
let end = new Date().getTime(); let end = new Date().getTime();
test('union([1, 2, 3], [4, 3, 2]) takes less than 2s to run', () => { test('union([1, 2, 3], [4, 3, 2]) takes less than 2s to run', () => {
expect((end - start) < 2000).toBeTruthy(); expect(end - start < 2000).toBeTruthy();
}); });

View File

@ -5,5 +5,7 @@ test('unionWith is a Function', () => {
expect(unionWith).toBeInstanceOf(Function); expect(unionWith).toBeInstanceOf(Function);
}); });
test('Produces the appropriate results', () => { test('Produces the appropriate results', () => {
expect(unionWith([1, 1.2, 1.5, 3, 0], [1.9, 3, 0, 3.9], (a, b) => Math.round(a) === Math.round(b))).toEqual([1, 1.2, 1.5, 3, 0, 3.9]); expect(
unionWith([1, 1.2, 1.5, 3, 0], [1.9, 3, 0, 3.9], (a, b) => Math.round(a) === Math.round(b))
).toEqual([1, 1.2, 1.5, 3, 0, 3.9]);
}); });

View File

@ -1,7 +1,6 @@
const expect = require('expect'); const expect = require('expect');
const uniqueElements = require('./uniqueElements.js'); const uniqueElements = require('./uniqueElements.js');
test('uniqueElements is a Function', () => { test('uniqueElements is a Function', () => {
expect(uniqueElements).toBeInstanceOf(Function); expect(uniqueElements).toBeInstanceOf(Function);
}); });
@ -11,8 +10,16 @@ test('uniqueElements([1, 2, 2, 3, 4, 4, 5]) returns [1,2,3,4,5]', () => {
test('uniqueElements([1, 23, 53]) returns [1, 23, 53]', () => { test('uniqueElements([1, 23, 53]) returns [1, 23, 53]', () => {
expect(uniqueElements([1, 23, 53])).toEqual([1, 23, 53]); expect(uniqueElements([1, 23, 53])).toEqual([1, 23, 53]);
}); });
test('uniqueElements([true, 0, 1, false, false, undefined, null, \'\']) returns [true, 0, 1, false, false, undefined, null, \'\']', () => { test("uniqueElements([true, 0, 1, false, false, undefined, null, '']) returns [true, 0, 1, false, false, undefined, null, '']", () => {
expect(uniqueElements([true, 0, 1, false, false, undefined, null, ''])).toEqual([true, 0, 1, false, undefined, null, '']); expect(uniqueElements([true, 0, 1, false, false, undefined, null, ''])).toEqual([
true,
0,
1,
false,
undefined,
null,
''
]);
}); });
test('uniqueElements() returns []', () => { test('uniqueElements() returns []', () => {
expect(uniqueElements()).toEqual([]); expect(uniqueElements()).toEqual([]);
@ -23,24 +30,32 @@ test('uniqueElements(null) returns []', () => {
test('uniqueElements(undefined) returns []', () => { test('uniqueElements(undefined) returns []', () => {
expect(uniqueElements(undefined)).toEqual([]); expect(uniqueElements(undefined)).toEqual([]);
}); });
test('uniqueElements(\'strt\') returns [\'s\', \'t\', \'r\']', () => { test("uniqueElements('strt') returns ['s', 't', 'r']", () => {
expect(uniqueElements('strt')).toEqual(['s', 't', 'r']); expect(uniqueElements('strt')).toEqual(['s', 't', 'r']);
}); });
test('uniqueElements(1, 1, 2543, 534, 5) throws an error', () => { test('uniqueElements(1, 1, 2543, 534, 5) throws an error', () => {
expect(() => {uniqueElements(1, 1, 2543, 534, 5); }).toThrow(); expect(() => {
uniqueElements(1, 1, 2543, 534, 5);
}).toThrow();
}); });
test('uniqueElements({}) throws an error', () => { test('uniqueElements({}) throws an error', () => {
expect(() => {uniqueElements({}); }).toThrow(); expect(() => {
uniqueElements({});
}).toThrow();
}); });
test('uniqueElements(true) throws an error', () => { test('uniqueElements(true) throws an error', () => {
expect(() => {uniqueElements(true); }).toThrow(); expect(() => {
uniqueElements(true);
}).toThrow();
}); });
test('uniqueElements(false) throws an error', () => { test('uniqueElements(false) throws an error', () => {
expect(() => {uniqueElements(false); }).toThrow(); expect(() => {
uniqueElements(false);
}).toThrow();
}); });
let start = new Date().getTime(); let start = new Date().getTime();
uniqueElements([true, 0, 1, false, false, undefined, null, '']); uniqueElements([true, 0, 1, false, false, undefined, null, '']);
let end = new Date().getTime(); let end = new Date().getTime();
test('uniqueElements([true, 0, 1, false, false, undefined, null]) takes less than 2s to run', () => { test('uniqueElements([true, 0, 1, false, false, undefined, null]) takes less than 2s to run', () => {
expect((end - start) < 2000).toBeTruthy(); expect(end - start < 2000).toBeTruthy();
}); });

View File

@ -6,27 +6,35 @@ test('uniqueElementsBy is a Function', () => {
}); });
test('uniqueElementsBy works for properties', () => { test('uniqueElementsBy works for properties', () => {
expect(uniqueElementsBy( expect(
uniqueElementsBy(
[ [
{ id: 0, value: 'a' }, { id: 0, value: 'a' },
{ id: 1, value: 'b' }, { id: 1, value: 'b' },
{ id: 2, value: 'c' }, { id: 2, value: 'c' },
{ id: 1, value: 'd' }, { id: 1, value: 'd' },
{ id: 0, value: 'e' }, { id: 0, value: 'e' }
], ],
(a, b) => a.id === b.id (a, b) => a.id === b.id
)).toEqual([ { id: 0, value: 'a' }, { id: 1, value: 'b' }, { id: 2, value: 'c' } ]); )
).toEqual([{ id: 0, value: 'a' }, { id: 1, value: 'b' }, { id: 2, value: 'c' }]);
}); });
test('uniqueElementsBy works for nested properties', () => { test('uniqueElementsBy works for nested properties', () => {
expect(uniqueElementsBy( expect(
uniqueElementsBy(
[ [
{ id: 0, value: 'a', n: { p: 0 } }, { id: 0, value: 'a', n: { p: 0 } },
{ id: 1, value: 'b', n: { p: 1 } }, { id: 1, value: 'b', n: { p: 1 } },
{ id: 2, value: 'c', n: { p: 2 } }, { id: 2, value: 'c', n: { p: 2 } },
{ id: 1, value: 'd', n: { p: 0 } }, { id: 1, value: 'd', n: { p: 0 } },
{ id: 0, value: 'e', n: {p: 1} }, { id: 0, value: 'e', n: { p: 1 } }
], ],
(a, b) => a.id === b.id (a, b) => a.id === b.id
)).toEqual([ { id: 0, value: 'a', n: {p: 0} }, { id: 1, value: 'b', n: {p: 1} }, { id: 2, value: 'c', n: {p: 2} } ]); )
).toEqual([
{ id: 0, value: 'a', n: { p: 0 } },
{ id: 1, value: 'b', n: { p: 1 } },
{ id: 2, value: 'c', n: { p: 2 } }
]);
}); });

View File

@ -6,27 +6,35 @@ test('uniqueElementsByRight is a Function', () => {
}); });
test('uniqueElementsByRight works for properties', () => { test('uniqueElementsByRight works for properties', () => {
expect(uniqueElementsByRight( expect(
uniqueElementsByRight(
[ [
{ id: 0, value: 'a' }, { id: 0, value: 'a' },
{ id: 1, value: 'b' }, { id: 1, value: 'b' },
{ id: 2, value: 'c' }, { id: 2, value: 'c' },
{ id: 1, value: 'd' }, { id: 1, value: 'd' },
{ id: 0, value: 'e' }, { id: 0, value: 'e' }
], ],
(a, b) => a.id === b.id (a, b) => a.id === b.id
)).toEqual([ { id: 0, value: 'e' }, { id: 1, value: 'd' }, { id: 2, value: 'c' } ]); )
).toEqual([{ id: 0, value: 'e' }, { id: 1, value: 'd' }, { id: 2, value: 'c' }]);
}); });
test('uniqueElementsByRight works for nested properties', () => { test('uniqueElementsByRight works for nested properties', () => {
expect(uniqueElementsByRight( expect(
uniqueElementsByRight(
[ [
{ id: 0, value: 'a', n: { p: 0 } }, { id: 0, value: 'a', n: { p: 0 } },
{ id: 1, value: 'b', n: { p: 1 } }, { id: 1, value: 'b', n: { p: 1 } },
{ id: 2, value: 'c', n: { p: 2 } }, { id: 2, value: 'c', n: { p: 2 } },
{ id: 1, value: 'd', n: { p: 0 } }, { id: 1, value: 'd', n: { p: 0 } },
{ id: 0, value: 'e', n: {p: 1} }, { id: 0, value: 'e', n: { p: 1 } }
], ],
(a, b) => a.id === b.id (a, b) => a.id === b.id
)).toEqual([ { id: 0, value: 'e', n: {p: 1} }, { id: 1, value: 'd', n: {p: 0} }, { id: 2, value: 'c', n: {p: 2} } ]); )
).toEqual([
{ id: 0, value: 'e', n: { p: 1 } },
{ id: 1, value: 'd', n: { p: 0 } },
{ id: 2, value: 'c', n: { p: 2 } }
]);
}); });

View File

@ -4,9 +4,9 @@ const unzip = require('./unzip.js');
test('unzip is a Function', () => { test('unzip is a Function', () => {
expect(unzip).toBeInstanceOf(Function); expect(unzip).toBeInstanceOf(Function);
}); });
test('unzip([[\'a\', 1, true], [\'b\', 2, false]]) equals [[\'a\',\'b\'], [1, 2], [true, false]]', () => { test("unzip([['a', 1, true], ['b', 2, false]]) equals [['a','b'], [1, 2], [true, false]]", () => {
expect(unzip([['a', 1, true], ['b', 2, false]])).toEqual([['a', 'b'], [1, 2], [true, false]]); expect(unzip([['a', 1, true], ['b', 2, false]])).toEqual([['a', 'b'], [1, 2], [true, false]]);
}); });
test('unzip([[\'a\', 1, true], [\'b\', 2]]) equals [[\'a\',\'b\'], [1, 2], [true]]', () => { test("unzip([['a', 1, true], ['b', 2]]) equals [['a','b'], [1, 2], [true]]", () => {
expect(unzip([['a', 1, true], ['b', 2]])).toEqual([['a', 'b'], [1, 2], [true]]); expect(unzip([['a', 1, true], ['b', 2]])).toEqual([['a', 'b'], [1, 2], [true]]);
}); });

View File

@ -5,5 +5,7 @@ test('unzipWith is a Function', () => {
expect(unzipWith).toBeInstanceOf(Function); expect(unzipWith).toBeInstanceOf(Function);
}); });
test('unzipWith([[1, 10, 100], [2, 20, 200]], (...args) => args.reduce((acc, v) => acc + v, 0)) equals [3, 30, 300]', () => { test('unzipWith([[1, 10, 100], [2, 20, 200]], (...args) => args.reduce((acc, v) => acc + v, 0)) equals [3, 30, 300]', () => {
expect(unzipWith([[1, 10, 100], [2, 20, 200]], (...args) => args.reduce((acc, v) => acc + v, 0))).toEqual([3, 30, 300]); expect(
unzipWith([[1, 10, 100], [2, 20, 200]], (...args) => args.reduce((acc, v) => acc + v, 0))
).toEqual([3, 30, 300]);
}); });

View File

@ -4,10 +4,7 @@ const when = require('./when.js');
test('when is a Function', () => { test('when is a Function', () => {
expect(when).toBeInstanceOf(Function); expect(when).toBeInstanceOf(Function);
}); });
const doubleEvenNumbers = when( const doubleEvenNumbers = when(x => x % 2 === 0, x => x * 2);
(x) => x % 2 === 0,
(x) => x * 2
);
test('Returns the proper result', () => { test('Returns the proper result', () => {
expect(doubleEvenNumbers(2)).toBe(4); expect(doubleEvenNumbers(2)).toBe(4);
}); });

View File

@ -10,24 +10,34 @@ test('without([2, 1, 2, 3], 1, 2) returns [3]', () => {
test('without([]) returns []', () => { test('without([]) returns []', () => {
expect(without([])).toEqual([]); expect(without([])).toEqual([]);
}); });
test('without([3, 1, true, \'3\', true], \'3\', true) returns [3, 1]', () => { test("without([3, 1, true, '3', true], '3', true) returns [3, 1]", () => {
expect(without([3, 1, true, '3', true], '3', true)).toEqual([3, 1]); expect(without([3, 1, true, '3', true], '3', true)).toEqual([3, 1]);
}); });
test('without(\'string\'.split(\'\'), \'s\', \'t\', \'g\') returns [\'r\', \'i\', \'n\']', () => { test("without('string'.split(''), 's', 't', 'g') returns ['r', 'i', 'n']", () => {
expect(without('string'.split(''), 's', 't', 'g')).toEqual(['r', 'i', 'n']); expect(without('string'.split(''), 's', 't', 'g')).toEqual(['r', 'i', 'n']);
}); });
test('without() throws an error', () => { test('without() throws an error', () => {
expect(() => { without(); }).toThrow(); expect(() => {
without();
}).toThrow();
}); });
test('without(null) throws an error', () => { test('without(null) throws an error', () => {
expect(() => { without(null); }).toThrow(); expect(() => {
without(null);
}).toThrow();
}); });
test('without(undefined) throws an error', () => { test('without(undefined) throws an error', () => {
expect(() => { without(undefined); }).toThrow(); expect(() => {
without(undefined);
}).toThrow();
}); });
test('without(123) throws an error', () => { test('without(123) throws an error', () => {
expect(() => { without(123); }).toThrow(); expect(() => {
without(123);
}).toThrow();
}); });
test('without({}) throws an error', () => { test('without({}) throws an error', () => {
expect(() => { without({}); }).toThrow(); expect(() => {
without({});
}).toThrow();
}); });

View File

@ -4,30 +4,42 @@ const words = require('./words.js');
test('words is a Function', () => { test('words is a Function', () => {
expect(words).toBeInstanceOf(Function); expect(words).toBeInstanceOf(Function);
}); });
test('words(\'I love javaScript!!\') returns [I, love, javaScript]', () => { test("words('I love javaScript!!') returns [I, love, javaScript]", () => {
expect(words('I love javaScript!!')).toEqual(["I", "love", "javaScript"]); expect(words('I love javaScript!!')).toEqual(['I', 'love', 'javaScript']);
}); });
test('words(\'python, javaScript & coffee\') returns [python, javaScript, coffee]', () => { test("words('python, javaScript & coffee') returns [python, javaScript, coffee]", () => {
expect(words('python, javaScript & coffee')).toEqual(["python", "javaScript", "coffee"]); expect(words('python, javaScript & coffee')).toEqual(['python', 'javaScript', 'coffee']);
}); });
test('words(I love javaScript!!) returns an array', () => { test('words(I love javaScript!!) returns an array', () => {
expect(Array.isArray(words('I love javaScript!!'))).toBeTruthy(); expect(Array.isArray(words('I love javaScript!!'))).toBeTruthy();
}); });
test('words() throws an error', () => { test('words() throws an error', () => {
expect(() => { words(); }).toThrow(); expect(() => {
words();
}).toThrow();
}); });
test('words(null) throws an error', () => { test('words(null) throws an error', () => {
expect(() => { words(null); }).toThrow(); expect(() => {
words(null);
}).toThrow();
}); });
test('words(undefined) throws an error', () => { test('words(undefined) throws an error', () => {
expect(() => { words(undefined); }).toThrow(); expect(() => {
words(undefined);
}).toThrow();
}); });
test('words({}) throws an error', () => { test('words({}) throws an error', () => {
expect(() => { words({}); }).toThrow(); expect(() => {
words({});
}).toThrow();
}); });
test('words([]) throws an error', () => { test('words([]) throws an error', () => {
expect(() => { words([]); }).toThrow(); expect(() => {
words([]);
}).toThrow();
}); });
test('words(1234) throws an error', () => { test('words(1234) throws an error', () => {
expect(() => { words(1234); }).toThrow(); expect(() => {
words(1234);
}).toThrow();
}); });

View File

@ -4,6 +4,6 @@ const xProd = require('./xProd.js');
test('xProd is a Function', () => { test('xProd is a Function', () => {
expect(xProd).toBeInstanceOf(Function); expect(xProd).toBeInstanceOf(Function);
}); });
test('xProd([1, 2], [\'a\', \'b\']) returns [[1, \'a\'], [1, \'b\'], [2, \'a\'], [2, \'b\']]', () => { test("xProd([1, 2], ['a', 'b']) returns [[1, 'a'], [1, 'b'], [2, 'a'], [2, 'b']]", () => {
expect(xProd([1, 2], ['a', 'b'])).toEqual([[1, 'a'], [1, 'b'], [2, 'a'], [2, 'b']]); expect(xProd([1, 2], ['a', 'b'])).toEqual([[1, 'a'], [1, 'b'], [2, 'a'], [2, 'b']]);
}); });

View File

@ -1,7 +1,6 @@
const expect = require('expect'); const expect = require('expect');
const zip = require('./zip.js'); const zip = require('./zip.js');
test('zip is a Function', () => { test('zip is a Function', () => {
expect(zip).toBeInstanceOf(Function); expect(zip).toBeInstanceOf(Function);
}); });
@ -24,8 +23,12 @@ test('zip([a], [1, 2], [true, false]) returns an Array', () => {
expect(Array.isArray(zip(['a'], [1, 2], [true, false]))).toBeTruthy(); expect(Array.isArray(zip(['a'], [1, 2], [true, false]))).toBeTruthy();
}); });
test('zip(null) throws an error', () => { test('zip(null) throws an error', () => {
expect(() => {zip(null);}).toThrow(); expect(() => {
zip(null);
}).toThrow();
}); });
test('zip(undefined) throws an error', () => { test('zip(undefined) throws an error', () => {
expect(() => {zip(undefined);}).toThrow(); expect(() => {
zip(undefined);
}).toThrow();
}); });

View File

@ -17,17 +17,27 @@ test('zipObject([a], string) returns { a: s }', () => {
expect(zipObject(['a'], 'string')).toEqual({ a: 's' }); expect(zipObject(['a'], 'string')).toEqual({ a: 's' });
}); });
test('zipObject() throws an error', () => { test('zipObject() throws an error', () => {
expect(() => {zipObject();}).toThrow(); expect(() => {
zipObject();
}).toThrow();
}); });
test('zipObject(([\'string\'], null) throws an error', () => { test("zipObject((['string'], null) throws an error", () => {
expect(() => {zipObject(['string'], null);}).toThrow(); expect(() => {
zipObject(['string'], null);
}).toThrow();
}); });
test('zipObject(null, [1]) throws an error', () => { test('zipObject(null, [1]) throws an error', () => {
expect(() => {zipObject(null, [1]);}).toThrow(); expect(() => {
zipObject(null, [1]);
}).toThrow();
}); });
test('zipObject(\'string\') throws an error', () => { test("zipObject('string') throws an error", () => {
expect(() => {zipObject('string');}).toThrow(); expect(() => {
zipObject('string');
}).toThrow();
}); });
test('zipObject(\'test\', \'string\') throws an error', () => { test("zipObject('test', 'string') throws an error", () => {
expect(() => {zipObject('test', 'string');}).toThrow(); expect(() => {
zipObject('test', 'string');
}).toThrow();
}); });