Test files linted
This commit is contained in:
@ -5,8 +5,14 @@ test('CSVToJSON is a Function', () => {
|
||||
expect(CSVToJSON).toBeInstanceOf(Function);
|
||||
});
|
||||
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', () => {
|
||||
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' }
|
||||
]);
|
||||
});
|
||||
|
||||
@ -5,8 +5,12 @@ test('JSONtoCSV is a Function', () => {
|
||||
expect(JSONtoCSV).toBeInstanceOf(Function);
|
||||
});
|
||||
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', () => {
|
||||
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"');
|
||||
});
|
||||
|
||||
@ -5,8 +5,12 @@ test('URLJoin is a Function', () => {
|
||||
expect(URLJoin).toBeInstanceOf(Function);
|
||||
});
|
||||
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', () => {
|
||||
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'
|
||||
);
|
||||
});
|
||||
|
||||
@ -8,5 +8,9 @@ test('Returns a value', () => {
|
||||
expect(attempt(() => 0)).toBe(0);
|
||||
});
|
||||
test('Returns an error', () => {
|
||||
expect(attempt(() => {throw new Error();})).toBeInstanceOf(Error);
|
||||
expect(
|
||||
attempt(() => {
|
||||
throw new Error();
|
||||
})
|
||||
).toBeInstanceOf(Error);
|
||||
});
|
||||
|
||||
@ -14,7 +14,10 @@ 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);
|
||||
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);
|
||||
@ -39,5 +42,5 @@ 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();
|
||||
expect(end - start < 2000).toBeTruthy();
|
||||
});
|
||||
|
||||
@ -5,5 +5,8 @@ test('bifurcate is a Function', () => {
|
||||
expect(bifurcate).toBeInstanceOf(Function);
|
||||
});
|
||||
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']
|
||||
]);
|
||||
});
|
||||
|
||||
@ -5,5 +5,8 @@ test('bifurcateBy is a Function', () => {
|
||||
expect(bifurcateBy).toBeInstanceOf(Function);
|
||||
});
|
||||
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']
|
||||
]);
|
||||
});
|
||||
|
||||
@ -6,7 +6,7 @@ test('bindAll is a Function', () => {
|
||||
});
|
||||
var view = {
|
||||
label: 'docs',
|
||||
'click': function() {
|
||||
click: function() {
|
||||
return 'clicked ' + this.label;
|
||||
}
|
||||
};
|
||||
|
||||
@ -20,17 +20,23 @@ test('chunk(string, 2) returns [ st, ri, ng ]', () => {
|
||||
expect(chunk('string', 2)).toEqual(['st', 'ri', 'ng']);
|
||||
});
|
||||
test('chunk() throws an error', () => {
|
||||
expect(() => {chunk();}).toThrow();
|
||||
expect(() => {
|
||||
chunk();
|
||||
}).toThrow();
|
||||
});
|
||||
test('chunk(undefined) throws an error', () => {
|
||||
expect(() => {chunk(undefined);}).toThrow();
|
||||
expect(() => {
|
||||
chunk(undefined);
|
||||
}).toThrow();
|
||||
});
|
||||
test('chunk(null) throws an error', () => {
|
||||
expect(() => {chunk(null);}).toThrow();
|
||||
expect(() => {
|
||||
chunk(null);
|
||||
}).toThrow();
|
||||
});
|
||||
let start = new Date().getTime();
|
||||
chunk('This is a string', 2);
|
||||
let end = new Date().getTime();
|
||||
test('chunk(This is a string, 2) takes less than 2s to run', () => {
|
||||
expect((end - start) < 2000).toBeTruthy();
|
||||
expect(end - start < 2000).toBeTruthy();
|
||||
});
|
||||
|
||||
@ -9,5 +9,10 @@ let p1 = Promise.resolve(1);
|
||||
let p2 = Promise.resolve(2);
|
||||
let p3 = new Promise(resolve => setTimeout(resolve, 2000, 3));
|
||||
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) {}
|
||||
);
|
||||
});
|
||||
|
||||
@ -5,5 +5,12 @@ test('compact is a Function', () => {
|
||||
expect(compact).toBeInstanceOf(Function);
|
||||
});
|
||||
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
|
||||
]);
|
||||
});
|
||||
|
||||
@ -6,7 +6,10 @@ test('compose is a Function', () => {
|
||||
});
|
||||
const add5 = x => x + 5;
|
||||
const multiply = (x, y) => x * y;
|
||||
const multiplyAndAdd5 = compose(add5, multiply);
|
||||
const multiplyAndAdd5 = compose(
|
||||
add5,
|
||||
multiply
|
||||
);
|
||||
test('Performs right-to-left function composition', () => {
|
||||
expect(multiplyAndAdd5(5, 2)).toBe(15);
|
||||
});
|
||||
|
||||
@ -6,15 +6,12 @@ test('converge is a Function', () => {
|
||||
});
|
||||
const average = converge((a, b) => a / b, [
|
||||
arr => arr.reduce((a, v) => a + v, 0),
|
||||
arr => arr.length,
|
||||
arr => arr.length
|
||||
]);
|
||||
test('Produces the average of the array', () => {
|
||||
expect(average([1, 2, 3, 4, 5, 6, 7])).toBe(4);
|
||||
});
|
||||
const strangeConcat = converge((a, b) => a + b, [
|
||||
x => x.toUpperCase(),
|
||||
x => x.toLowerCase()]
|
||||
);
|
||||
const strangeConcat = converge((a, b) => a + b, [x => x.toUpperCase(), x => x.toLowerCase()]);
|
||||
test('Produces the strange concatenation', () => {
|
||||
expect(strangeConcat('Yodel')).toBe('YODELyodel');
|
||||
});
|
||||
|
||||
@ -5,5 +5,7 @@ test('debounce is a Function', () => {
|
||||
expect(debounce).toBeInstanceOf(Function);
|
||||
});
|
||||
test('Works as expected', () => {
|
||||
debounce(() => { expect(true).toBeTruthy(); });
|
||||
debounce(() => {
|
||||
expect(true).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
||||
@ -6,7 +6,7 @@ test('deepClone is a Function', () => {
|
||||
});
|
||||
const a = { foo: 'bar', obj: { a: 1, b: 2 } };
|
||||
const b = deepClone(a);
|
||||
const c = [{foo: "bar"}];
|
||||
const c = [{ foo: 'bar' }];
|
||||
const d = deepClone(c);
|
||||
test('Shallow cloning works', () => {
|
||||
expect(a).not.toBe(b);
|
||||
|
||||
@ -5,5 +5,7 @@ test('differenceWith is a Function', () => {
|
||||
expect(differenceWith).toBeInstanceOf(Function);
|
||||
});
|
||||
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]);
|
||||
});
|
||||
|
||||
@ -1,32 +1,32 @@
|
||||
const expect = require("expect");
|
||||
const dig = require("./dig.js");
|
||||
const expect = require('expect');
|
||||
const dig = require('./dig.js');
|
||||
|
||||
const data = {
|
||||
level1: {
|
||||
level2: {
|
||||
level3: "some data",
|
||||
level3: 'some data',
|
||||
level3f: false,
|
||||
level3a: [1, 2, 3, 4]
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
test("dig is a Function", () => {
|
||||
test('dig is a Function', () => {
|
||||
expect(dig).toBeInstanceOf(Function);
|
||||
});
|
||||
|
||||
test("Dig target success", () => {
|
||||
expect(dig(data, "level3")).toEqual("some data");
|
||||
test('Dig target success', () => {
|
||||
expect(dig(data, 'level3')).toEqual('some data');
|
||||
});
|
||||
|
||||
test("Dig target with falsey value", () => {
|
||||
expect(dig(data, "level3f")).toEqual(false);
|
||||
test('Dig target with falsey value', () => {
|
||||
expect(dig(data, 'level3f')).toEqual(false);
|
||||
});
|
||||
|
||||
test("Dig target with array", () => {
|
||||
expect(dig(data, "level3a")).toEqual([1,2,3,4]);
|
||||
test('Dig target with array', () => {
|
||||
expect(dig(data, 'level3a')).toEqual([1, 2, 3, 4]);
|
||||
});
|
||||
|
||||
test("Unknown target return undefined", () => {
|
||||
expect(dig(data, "level4")).toEqual(undefined);
|
||||
test('Unknown target return undefined', () => {
|
||||
expect(dig(data, 'level4')).toEqual(undefined);
|
||||
});
|
||||
|
||||
@ -4,8 +4,10 @@ const equals = require('./equals.js');
|
||||
test('equals is a 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\' }', () => {
|
||||
expect(equals({ a: [2, {e: 3}], b: [4], c: 'foo' }, { a: [2, {e: 3}], b: [4], c: 'foo' })).toBeTruthy();
|
||||
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();
|
||||
});
|
||||
test('[1,2,3] is equal to [1,2,3]', () => {
|
||||
expect(equals([1, 2, 3], [1, 2, 3])).toBeTruthy();
|
||||
|
||||
@ -5,5 +5,7 @@ test('escapeHTML is a Function', () => {
|
||||
expect(escapeHTML).toBeInstanceOf(Function);
|
||||
});
|
||||
test('Escapes a string for use in HTML', () => {
|
||||
expect(escapeHTML('<a href="#">Me & you</a>')).toBe('<a href="#">Me & you</a>');
|
||||
expect(escapeHTML('<a href="#">Me & you</a>')).toBe(
|
||||
'<a href="#">Me & you</a>'
|
||||
);
|
||||
});
|
||||
|
||||
@ -7,4 +7,3 @@ test('filterNonUnique is a Function', () => {
|
||||
test('Filters out the non-unique values in an array', () => {
|
||||
expect(filterNonUnique([1, 2, 2, 3, 4, 4, 5])).toEqual([1, 3, 5]);
|
||||
});
|
||||
|
||||
|
||||
@ -6,27 +6,31 @@ test('filterNonUniqueBy is a Function', () => {
|
||||
});
|
||||
|
||||
test('filterNonUniqueBy works for properties', () => {
|
||||
expect(filterNonUniqueBy(
|
||||
expect(
|
||||
filterNonUniqueBy(
|
||||
[
|
||||
{ id: 0, value: 'a' },
|
||||
{ id: 1, value: 'b' },
|
||||
{ id: 2, value: 'c' },
|
||||
{ id: 1, value: 'd' },
|
||||
{ id: 0, value: 'e' },
|
||||
{ id: 0, value: 'e' }
|
||||
],
|
||||
(a, b) => a.id === b.id
|
||||
)).toEqual([ { id: 2, value: 'c' } ]);
|
||||
)
|
||||
).toEqual([{ id: 2, value: 'c' }]);
|
||||
});
|
||||
|
||||
test('filterNonUniqueBy works for nested properties', () => {
|
||||
expect(filterNonUniqueBy(
|
||||
expect(
|
||||
filterNonUniqueBy(
|
||||
[
|
||||
{ id: 0, value: 'a', n: { p: 0 } },
|
||||
{ id: 1, value: 'b', n: { p: 1 } },
|
||||
{ id: 2, value: 'c', n: { p: 2 } },
|
||||
{ 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
|
||||
)).toEqual([ { id: 2, value: 'c', n: {p: 2} } ]);
|
||||
)
|
||||
).toEqual([{ id: 2, value: 'c', n: { p: 2 } }]);
|
||||
});
|
||||
|
||||
@ -5,11 +5,14 @@ test('findKey is a Function', () => {
|
||||
expect(findKey).toBeInstanceOf(Function);
|
||||
});
|
||||
test('Returns the appropriate key', () => {
|
||||
expect(findKey(
|
||||
expect(
|
||||
findKey(
|
||||
{
|
||||
barney: { age: 36, active: true },
|
||||
fred: { age: 40, active: false },
|
||||
pebbles: { age: 1, active: true }
|
||||
},
|
||||
o => o['active'])).toBe('barney');
|
||||
o => o['active']
|
||||
)
|
||||
).toBe('barney');
|
||||
});
|
||||
|
||||
@ -5,11 +5,14 @@ test('findLastKey is a Function', () => {
|
||||
expect(findLastKey).toBeInstanceOf(Function);
|
||||
});
|
||||
test('eturns the appropriate key', () => {
|
||||
expect(findLastKey(
|
||||
expect(
|
||||
findLastKey(
|
||||
{
|
||||
barney: { age: 36, active: true },
|
||||
fred: { age: 40, active: false },
|
||||
pebbles: { age: 1, active: true }
|
||||
},
|
||||
o => o['active'])).toBe('pebbles');
|
||||
o => o['active']
|
||||
)
|
||||
).toBe('pebbles');
|
||||
});
|
||||
|
||||
@ -5,7 +5,7 @@ test('forEachRight is a Function', () => {
|
||||
expect(forEachRight).toBeInstanceOf(Function);
|
||||
});
|
||||
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', () => {
|
||||
expect(output).toBe('4321');
|
||||
});
|
||||
|
||||
@ -6,6 +6,6 @@ test('forOwn is a Function', () => {
|
||||
});
|
||||
let output = [];
|
||||
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]);
|
||||
});
|
||||
|
||||
@ -6,6 +6,6 @@ test('forOwnRight is a Function', () => {
|
||||
});
|
||||
let output = [];
|
||||
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']);
|
||||
});
|
||||
|
||||
@ -8,5 +8,7 @@ test('Returns the human readable format of the given number of milliseconds', ()
|
||||
expect(formatDuration(1001)).toBe('1 second, 1 millisecond');
|
||||
});
|
||||
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'
|
||||
);
|
||||
});
|
||||
|
||||
@ -8,7 +8,9 @@ test('Converts a string from camelcase', () => {
|
||||
expect(fromCamelCase('someDatabaseFieldName', ' ')).toBe('some database field name');
|
||||
});
|
||||
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', () => {
|
||||
expect(fromCamelCase('someJavascriptProperty', '_')).toBe('some_javascript_property');
|
||||
|
||||
@ -8,7 +8,9 @@ test('functionName is a Function', () => {
|
||||
test('Works for native functions', () => {
|
||||
expect(functionName(Math.max)).toBe('max');
|
||||
});
|
||||
function fun(x) {return x;}
|
||||
function fun(x) {
|
||||
return x;
|
||||
}
|
||||
test('Works for functions', () => {
|
||||
expect(functionName(fun)).toBe('fun');
|
||||
});
|
||||
|
||||
@ -5,5 +5,8 @@ test('getURLParameters is a Function', () => {
|
||||
expect(getURLParameters).toBeInstanceOf(Function);
|
||||
});
|
||||
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'
|
||||
});
|
||||
});
|
||||
|
||||
@ -5,5 +5,7 @@ test('hashNode is a Function', () => {
|
||||
expect(hashNode).toBeInstanceOf(Function);
|
||||
});
|
||||
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')
|
||||
);
|
||||
});
|
||||
|
||||
@ -17,17 +17,23 @@ test('head(String) returns S', () => {
|
||||
expect(head('String')).toBe('S');
|
||||
});
|
||||
test('head(null) throws an Error', () => {
|
||||
expect(() => { head(null); }).toThrow();
|
||||
expect(() => {
|
||||
head(null);
|
||||
}).toThrow();
|
||||
});
|
||||
test('head(undefined) throws an Error', () => {
|
||||
expect(() => { head(undefined); }).toThrow();
|
||||
expect(() => {
|
||||
head(undefined);
|
||||
}).toThrow();
|
||||
});
|
||||
test('head() throws an Error', () => {
|
||||
expect(() => { head(); }).toThrow();
|
||||
expect(() => {
|
||||
head();
|
||||
}).toThrow();
|
||||
});
|
||||
let start = new Date().getTime();
|
||||
head([1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 1122, 32124, 23232]);
|
||||
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', () => {
|
||||
expect((end - start) < 2000).toBeTruthy();
|
||||
expect(end - start < 2000).toBeTruthy();
|
||||
});
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
const httpDelete = (url, callback, err = console.error) => {
|
||||
const request = new XMLHttpRequest();
|
||||
request.open("DELETE", url, true);
|
||||
request.open('DELETE', url, true);
|
||||
request.onload = () => callback(request);
|
||||
request.onerror = () => err(request);
|
||||
request.send();
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
const httpPut = (url, data, callback, err = console.error) => {
|
||||
const request = new XMLHttpRequest();
|
||||
request.open("PUT", url, true);
|
||||
request.open('PUT', url, true);
|
||||
request.setRequestHeader('Content-type', 'application/json; charset=utf-8');
|
||||
request.onload = () => callback(request);
|
||||
request.onerror = () => err(request);
|
||||
|
||||
@ -5,5 +5,11 @@ test('intersectionWith is a Function', () => {
|
||||
expect(intersectionWith).toBeInstanceOf(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]);
|
||||
});
|
||||
|
||||
@ -4,9 +4,12 @@ const invertKeyValues = require('./invertKeyValues.js');
|
||||
test('invertKeyValues is a 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'] });
|
||||
});
|
||||
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' ] });
|
||||
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']
|
||||
});
|
||||
});
|
||||
|
||||
@ -7,4 +7,3 @@ test('isDivisible is a Function', () => {
|
||||
test('The number 6 is divisible by 3', () => {
|
||||
expect(isDivisible(6, 3)).toBeTruthy();
|
||||
});
|
||||
|
||||
|
||||
@ -10,4 +10,3 @@ test('passed value is a function', () => {
|
||||
test('passed value is not a function', () => {
|
||||
expect(isFunction('x')).toBeFalsy();
|
||||
});
|
||||
|
||||
|
||||
@ -16,4 +16,3 @@ test('isObject({ a:1 }) is a object', () => {
|
||||
test('isObject(true) is not a object', () => {
|
||||
expect(isObject(true)).toBeFalsy();
|
||||
});
|
||||
|
||||
|
||||
@ -19,7 +19,7 @@ test('isPrimitive(true) is primitive', () => {
|
||||
test('isPrimitive(50) is primitive', () => {
|
||||
expect(isPrimitive(50)).toBeTruthy();
|
||||
});
|
||||
test('isPrimitive(\'Hello\') is primitive', () => {
|
||||
test("isPrimitive('Hello') is primitive", () => {
|
||||
expect(isPrimitive('Hello')).toBeTruthy();
|
||||
});
|
||||
test('isPrimitive(false) is primitive', () => {
|
||||
@ -38,5 +38,5 @@ let start = new Date().getTime();
|
||||
isPrimitive({ a: 123 });
|
||||
let end = new Date().getTime();
|
||||
test('isPrimitive({ a: 123 }) takes less than 2s to run', () => {
|
||||
expect((end - start) < 2000).toBeTruthy();
|
||||
expect(end - start < 2000).toBeTruthy();
|
||||
});
|
||||
|
||||
@ -5,11 +5,13 @@ test('isPromiseLike is a Function', () => {
|
||||
expect(isPromiseLike).toBeInstanceOf(Function);
|
||||
});
|
||||
test('Returns true for a promise-like object', () => {
|
||||
expect(isPromiseLike({
|
||||
expect(
|
||||
isPromiseLike({
|
||||
then: function() {
|
||||
return '';
|
||||
}
|
||||
})).toBeTruthy();
|
||||
})
|
||||
).toBeTruthy();
|
||||
});
|
||||
test('Returns false for an empty object', () => {
|
||||
expect(isPromiseLike({})).toBeFalsy();
|
||||
|
||||
@ -1,5 +1,11 @@
|
||||
const isSimilar = (pattern, str) =>
|
||||
[...str].reduce(
|
||||
(matchIndex, char) => char.toLowerCase() === (pattern[matchIndex] || '').toLowerCase() ? matchIndex + 1 : matchIndex, 0
|
||||
) === pattern.length ? true : false;
|
||||
(matchIndex, char) =>
|
||||
char.toLowerCase() === (pattern[matchIndex] || '').toLowerCase()
|
||||
? matchIndex + 1
|
||||
: matchIndex,
|
||||
0
|
||||
) === pattern.length
|
||||
? true
|
||||
: false;
|
||||
module.exports = isSimilar;
|
||||
|
||||
@ -17,17 +17,23 @@ test('last(String) returns g', () => {
|
||||
expect(last('String')).toBe('g');
|
||||
});
|
||||
test('last(null) throws an Error', () => {
|
||||
expect(() => { last(null); }).toThrow();
|
||||
expect(() => {
|
||||
last(null);
|
||||
}).toThrow();
|
||||
});
|
||||
test('last(undefined) throws an Error', () => {
|
||||
expect(() => { last(undefined); }).toThrow();
|
||||
expect(() => {
|
||||
last(undefined);
|
||||
}).toThrow();
|
||||
});
|
||||
test('last() throws an Error', () => {
|
||||
expect(() => { last(); }).toThrow();
|
||||
expect(() => {
|
||||
last();
|
||||
}).toThrow();
|
||||
});
|
||||
let start = new Date().getTime();
|
||||
last([1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 1122, 32124, 23232]);
|
||||
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', () => {
|
||||
expect((end - start) < 2000).toBeTruthy();
|
||||
expect(end - start < 2000).toBeTruthy();
|
||||
});
|
||||
|
||||
@ -1,15 +1,22 @@
|
||||
const levenshteinDistance = (string1, string2) => {
|
||||
if (string1.length === 0) return string2.length;
|
||||
if (string2.length === 0) return string1.length;
|
||||
let matrix = Array(string2.length + 1).fill(0).map((x,i) => [i]);
|
||||
matrix[0] = Array(string1.length + 1).fill(0).map((x,i) => i);
|
||||
let matrix = Array(string2.length + 1)
|
||||
.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 j = 1; j <= string1.length; j++) {
|
||||
if (string2[i - 1] === string1[j - 1]) {
|
||||
matrix[i][j] = matrix[i - 1][j - 1];
|
||||
}
|
||||
else{
|
||||
matrix[i][j] = Math.min(matrix[i-1][j-1]+1, matrix[i][j-1]+1, matrix[i-1][j]+1);
|
||||
} else {
|
||||
matrix[i][j] = Math.min(
|
||||
matrix[i - 1][j - 1] + 1,
|
||||
matrix[i][j - 1] + 1,
|
||||
matrix[i - 1][j] + 1
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -5,8 +5,12 @@ test('matches is a Function', () => {
|
||||
expect(matches).toBeInstanceOf(Function);
|
||||
});
|
||||
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', () => {
|
||||
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();
|
||||
});
|
||||
|
||||
@ -6,9 +6,11 @@ test('matchesWith is a Function', () => {
|
||||
});
|
||||
const isGreeting = val => /^h(?:i|ello)$/.test(val);
|
||||
test('Returns true for two objects with similar values, based on the provided function', () => {
|
||||
expect(matchesWith(
|
||||
expect(
|
||||
matchesWith(
|
||||
{ greeting: 'hello' },
|
||||
{ greeting: 'hi' },
|
||||
(oV, sV) => isGreeting(oV) && isGreeting(sV)
|
||||
)).toBeTruthy();
|
||||
)
|
||||
).toBeTruthy();
|
||||
});
|
||||
|
||||
@ -14,5 +14,9 @@ const other = {
|
||||
c: 'foo'
|
||||
};
|
||||
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'
|
||||
});
|
||||
});
|
||||
|
||||
@ -8,5 +8,5 @@ test('Returns the n minimum elements from the provided array', () => {
|
||||
expect(minN([1, 2, 3])).toEqual([1]);
|
||||
});
|
||||
test('Returns the n minimum elements from the provided array', () => {
|
||||
expect(minN([1, 2, 3], 2), ).toEqual([1, 2]);
|
||||
expect(minN([1, 2, 3], 2)).toEqual([1, 2]);
|
||||
});
|
||||
|
||||
@ -15,4 +15,3 @@ const last = nthArg(-1);
|
||||
test('Works for negative values', () => {
|
||||
expect(last(1, 2, 3, 4, 5)).toBe(5);
|
||||
});
|
||||
|
||||
|
||||
@ -5,5 +5,5 @@ test('omit is a Function', () => {
|
||||
expect(omit).toBeInstanceOf(Function);
|
||||
});
|
||||
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 });
|
||||
});
|
||||
|
||||
@ -6,8 +6,16 @@ test('orderBy is a Function', () => {
|
||||
});
|
||||
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.', () => {
|
||||
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.', () => {
|
||||
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 }
|
||||
]);
|
||||
});
|
||||
|
||||
@ -5,6 +5,9 @@ test('partition is a Function', () => {
|
||||
expect(partition).toBeInstanceOf(Function);
|
||||
});
|
||||
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.', () => {
|
||||
expect(partition(users, o => o.active)).toEqual([[{ 'user': 'fred', 'age': 40, 'active': true }],[{ 'user': 'barney', 'age': 36, 'active': false }]]);
|
||||
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 }]
|
||||
]);
|
||||
});
|
||||
|
||||
@ -5,5 +5,12 @@ test('permutations is a Function', () => {
|
||||
expect(permutations).toBeInstanceOf(Function);
|
||||
});
|
||||
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]
|
||||
]);
|
||||
});
|
||||
|
||||
@ -5,5 +5,5 @@ test('pick is a Function', () => {
|
||||
expect(pick).toBeInstanceOf(Function);
|
||||
});
|
||||
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 });
|
||||
});
|
||||
|
||||
@ -5,5 +5,5 @@ test('pickBy is a Function', () => {
|
||||
expect(pickBy).toBeInstanceOf(Function);
|
||||
});
|
||||
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 });
|
||||
});
|
||||
|
||||
@ -5,11 +5,12 @@ test('pipeAsyncFunctions is a Function', () => {
|
||||
expect(pipeAsyncFunctions).toBeInstanceOf(Function);
|
||||
});
|
||||
test('pipeAsyncFunctions result should be 15', () => {
|
||||
expect(pipeAsyncFunctions(
|
||||
(x) => x + 1,
|
||||
(x) => new Promise((resolve) => setTimeout(() => resolve(x + 2), 0)),
|
||||
(x) => x + 3,
|
||||
async(x) => await x + 4,
|
||||
)
|
||||
(5)).resolves.toBe(15);
|
||||
expect(
|
||||
pipeAsyncFunctions(
|
||||
x => x + 1,
|
||||
x => new Promise(resolve => setTimeout(() => resolve(x + 2), 0)),
|
||||
x => x + 3,
|
||||
async x => (await x) + 4
|
||||
)(5)
|
||||
).resolves.toBe(15);
|
||||
});
|
||||
|
||||
@ -11,23 +11,33 @@ test('quickSort([-1, 0, -2]) returns [-2, -1, 0]', () => {
|
||||
expect(quickSort([-1, 0, -2])).toEqual([-2, -1, 0]);
|
||||
});
|
||||
test('quickSort() throws an error', () => {
|
||||
expect(() => { quickSort(); }).toThrow();
|
||||
expect(() => {
|
||||
quickSort();
|
||||
}).toThrow();
|
||||
});
|
||||
test('quickSort(123) throws an error', () => {
|
||||
expect(() => { quickSort(123); }).toThrow();
|
||||
expect(() => {
|
||||
quickSort(123);
|
||||
}).toThrow();
|
||||
});
|
||||
test('quickSort({ 234: string}) throws an error', () => {
|
||||
expect(() => { quickSort({ 234: string}); }).toThrow();
|
||||
expect(() => {
|
||||
quickSort({ 234: string });
|
||||
}).toThrow();
|
||||
});
|
||||
test('quickSort(null) throws an error', () => {
|
||||
expect(() => { quickSort(null); }).toThrow();
|
||||
expect(() => {
|
||||
quickSort(null);
|
||||
}).toThrow();
|
||||
});
|
||||
test('quickSort(undefined) throws an error', () => {
|
||||
expect(() => { quickSort(undefined); }).toThrow();
|
||||
expect(() => {
|
||||
quickSort(undefined);
|
||||
}).toThrow();
|
||||
});
|
||||
let start = new Date().getTime();
|
||||
quickSort([11, 1, 324, 23232, -1, 53, 2, 524, 32, 13, 156, 133, 62, 12, 4]);
|
||||
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', () => {
|
||||
expect((end - start) < 2000).toBeTruthy();
|
||||
expect(end - start < 2000).toBeTruthy();
|
||||
});
|
||||
|
||||
@ -11,5 +11,9 @@ test('The color code starts with "#"', () => {
|
||||
expect(randomHexColorCode().startsWith('#')).toBeTruthy();
|
||||
});
|
||||
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();
|
||||
});
|
||||
|
||||
@ -13,6 +13,6 @@ test('The returned array contains only integers', () => {
|
||||
test('The returned array has the proper length', () => {
|
||||
expect(arr.length).toBe(10);
|
||||
});
|
||||
test('The returned array\'s values lie between provided lowerLimit and upperLimit (both inclusive).', () => {
|
||||
expect(arr.every(x => (x >= lowerLimit) && (x <= upperLimit))).toBeTruthy();
|
||||
test("The returned array's values lie between provided lowerLimit and upperLimit (both inclusive).", () => {
|
||||
expect(arr.every(x => x >= lowerLimit && x <= upperLimit)).toBeTruthy();
|
||||
});
|
||||
|
||||
@ -11,5 +11,5 @@ test('The returned value is an integer', () => {
|
||||
});
|
||||
const numberForTest = randomIntegerInRange(lowerLimit, upperLimit);
|
||||
test('The returned value lies between provided lowerLimit and upperLimit (both inclusive).', () => {
|
||||
expect((numberForTest >= lowerLimit) && (numberForTest <= upperLimit)).toBeTruthy();
|
||||
expect(numberForTest >= lowerLimit && numberForTest <= upperLimit).toBeTruthy();
|
||||
});
|
||||
|
||||
@ -11,5 +11,5 @@ test('The returned value is a number', () => {
|
||||
});
|
||||
const numberForTest = randomNumberInRange(lowerLimit, upperLimit);
|
||||
test('The returned value lies between provided lowerLimit and upperLimit (both inclusive).', () => {
|
||||
expect((numberForTest >= lowerLimit) && (numberForTest <= upperLimit)).toBeTruthy();
|
||||
expect(numberForTest >= lowerLimit && numberForTest <= upperLimit).toBeTruthy();
|
||||
});
|
||||
|
||||
@ -5,5 +5,13 @@ test('reduceSuccessive is a Function', () => {
|
||||
expect(reduceSuccessive).toBeInstanceOf(Function);
|
||||
});
|
||||
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
|
||||
]);
|
||||
});
|
||||
|
||||
@ -11,8 +11,10 @@ test('Returns the maximum of an array', () => {
|
||||
expect(reduceWhich([1, 3, 2], (a, b) => b - a)).toBe(3);
|
||||
});
|
||||
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 }],
|
||||
(a, b) => a.age - b.age
|
||||
)).toEqual({name: "Lucy", age: 9});
|
||||
)
|
||||
).toEqual({ name: 'Lucy', age: 9 });
|
||||
});
|
||||
|
||||
@ -17,5 +17,7 @@ const data = [
|
||||
}
|
||||
];
|
||||
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' }
|
||||
]);
|
||||
});
|
||||
|
||||
@ -4,17 +4,11 @@ const reject = require('./reject.js');
|
||||
test('reject is a Function', () => {
|
||||
expect(reject).toBeInstanceOf(Function);
|
||||
});
|
||||
const noEvens = reject(
|
||||
(x) => x % 2 === 0,
|
||||
[1, 2, 3, 4, 5]
|
||||
);
|
||||
const noEvens = reject(x => x % 2 === 0, [1, 2, 3, 4, 5]);
|
||||
test('Works with numbers', () => {
|
||||
expect(noEvens).toEqual([1, 3, 5]);
|
||||
});
|
||||
const fourLettersOrLess = reject(
|
||||
(word) => word.length > 4,
|
||||
['Apple', 'Pear', 'Kiwi', 'Banana']
|
||||
);
|
||||
const fourLettersOrLess = reject(word => word.length > 4, ['Apple', 'Pear', 'Kiwi', 'Banana']);
|
||||
test('Works with strings', () => {
|
||||
expect(fourLettersOrLess).toEqual(['Pear', 'Kiwi']);
|
||||
});
|
||||
|
||||
@ -35,5 +35,5 @@ let start = new Date().getTime();
|
||||
round(123.3423345345345345344, 11);
|
||||
let end = new Date().getTime();
|
||||
test('round(123.3423345345345345344, 11) takes less than 2s to run', () => {
|
||||
expect((end - start) < 2000).toBeTruthy();
|
||||
expect(end - start < 2000).toBeTruthy();
|
||||
});
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
const expect = require('expect');
|
||||
const runPromisesInSeries = require('./runPromisesInSeries.js');
|
||||
|
||||
|
||||
test('runPromisesInSeries is a Function', () => {
|
||||
expect(runPromisesInSeries).toBeInstanceOf(Function);
|
||||
});
|
||||
|
||||
@ -5,5 +5,11 @@ test('splitLines is a Function', () => {
|
||||
expect(splitLines).toBeInstanceOf(Function);
|
||||
});
|
||||
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.',
|
||||
''
|
||||
]);
|
||||
});
|
||||
|
||||
@ -5,5 +5,7 @@ test('stripHTMLTags is a Function', () => {
|
||||
expect(stripHTMLTags).toBeInstanceOf(Function);
|
||||
});
|
||||
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'
|
||||
);
|
||||
});
|
||||
|
||||
@ -5,8 +5,11 @@ test('symmetricDifferenceWith is a Function', () => {
|
||||
expect(symmetricDifferenceWith).toBeInstanceOf(Function);
|
||||
});
|
||||
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.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]);
|
||||
});
|
||||
|
||||
@ -4,33 +4,45 @@ const toCamelCase = require('./toCamelCase.js');
|
||||
test('toCamelCase is a 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');
|
||||
});
|
||||
test('toCamelCase(\'Some label that needs to be camelized\') returns someLabelThatNeedsToBeCamelized', () => {
|
||||
expect(toCamelCase('Some label that needs to be camelized')).toBe('someLabelThatNeedsToBeCamelized');
|
||||
test("toCamelCase('Some label that needs to be camelized') returns 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');
|
||||
});
|
||||
test('toCamelCase(\'some-mixed_string with spaces_underscores-and-hyphens\') returns someMixedStringWithSpacesUnderscoresAndHyphens', () => {
|
||||
expect(toCamelCase('some-mixed_string with spaces_underscores-and-hyphens')).toBe('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'
|
||||
);
|
||||
});
|
||||
test('toCamelCase() throws a error', () => {
|
||||
expect(() => {toCamelCase(); }).toThrow();
|
||||
expect(() => {
|
||||
toCamelCase();
|
||||
}).toThrow();
|
||||
});
|
||||
test('toCamelCase([]) throws a error', () => {
|
||||
expect(() => {toCamelCase([]); }).toThrow();
|
||||
expect(() => {
|
||||
toCamelCase([]);
|
||||
}).toThrow();
|
||||
});
|
||||
test('toCamelCase({}) throws a error', () => {
|
||||
expect(() => {toCamelCase({}); }).toThrow();
|
||||
expect(() => {
|
||||
toCamelCase({});
|
||||
}).toThrow();
|
||||
});
|
||||
test('toCamelCase(123) throws a error', () => {
|
||||
expect(() => {toCamelCase(123); }).toThrow();
|
||||
expect(() => {
|
||||
toCamelCase(123);
|
||||
}).toThrow();
|
||||
});
|
||||
let start = new Date().getTime();
|
||||
toCamelCase('some-mixed_string with spaces_underscores-and-hyphens');
|
||||
let end = new Date().getTime();
|
||||
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();
|
||||
});
|
||||
|
||||
@ -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));
|
||||
});
|
||||
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)
|
||||
);
|
||||
});
|
||||
|
||||
@ -5,5 +5,5 @@ test('toDecimalMark is a Function', () => {
|
||||
expect(toDecimalMark).toBeInstanceOf(Function);
|
||||
});
|
||||
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');
|
||||
});
|
||||
|
||||
@ -4,33 +4,45 @@ const toKebabCase = require('./toKebabCase.js');
|
||||
test('toKebabCase is a Function', () => {
|
||||
expect(toKebabCase).toBeInstanceOf(Function);
|
||||
});
|
||||
test('toKebabCase(\'camelCase\') returns camel-case', () => {
|
||||
test("toKebabCase('camelCase') returns 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');
|
||||
});
|
||||
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');
|
||||
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'
|
||||
);
|
||||
});
|
||||
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');
|
||||
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'
|
||||
);
|
||||
});
|
||||
test('toKebabCase() returns undefined', () => {
|
||||
expect(toKebabCase()).toBe(undefined);
|
||||
});
|
||||
test('toKebabCase([]) throws an erro', () => {
|
||||
expect(() => { toKebabCase([]); }).toThrow();
|
||||
expect(() => {
|
||||
toKebabCase([]);
|
||||
}).toThrow();
|
||||
});
|
||||
test('toKebabCase({}) throws an erro', () => {
|
||||
expect(() => { toKebabCase({}); }).toThrow();
|
||||
expect(() => {
|
||||
toKebabCase({});
|
||||
}).toThrow();
|
||||
});
|
||||
test('toKebabCase(123) throws an erro', () => {
|
||||
expect(() => { toKebabCase(123); }).toThrow();
|
||||
expect(() => {
|
||||
toKebabCase(123);
|
||||
}).toThrow();
|
||||
});
|
||||
let start = new Date().getTime();
|
||||
toKebabCase('IAmListeningToFMWhileLoadingDifferentURLOnMyBrowserAndAlsoEditingSomeXMLAndHTML');
|
||||
let end = new Date().getTime();
|
||||
test('toKebabCase(IAmListeningToFMWhileLoadingDifferentURLOnMyBrowserAndAlsoEditingSomeXMLAndHTML) takes less than 2s to run', () => {
|
||||
expect((end - start) < 2000).toBeTruthy();
|
||||
expect(end - start < 2000).toBeTruthy();
|
||||
});
|
||||
|
||||
@ -10,7 +10,7 @@ test('Number(toSafeInteger(3.2)) is a number', () => {
|
||||
test('Converts a value to a safe integer', () => {
|
||||
expect(toSafeInteger(3.2)).toBe(3);
|
||||
});
|
||||
test('toSafeInteger(\'4.2\') returns 4', () => {
|
||||
test("toSafeInteger('4.2') returns 4", () => {
|
||||
expect(toSafeInteger('4.2')).toBe(4);
|
||||
});
|
||||
test('toSafeInteger(4.6) returns 5', () => {
|
||||
@ -22,7 +22,7 @@ test('toSafeInteger([]) returns 0', () => {
|
||||
test('isNaN(toSafeInteger([1.5, 3124])) is true', () => {
|
||||
expect(isNaN(toSafeInteger([1.5, 3124]))).toBeTruthy();
|
||||
});
|
||||
test('isNaN(toSafeInteger(\'string\')) is true', () => {
|
||||
test("isNaN(toSafeInteger('string')) is true", () => {
|
||||
expect(isNaN(toSafeInteger('string'))).toBeTruthy();
|
||||
});
|
||||
test('isNaN(toSafeInteger({})) is true', () => {
|
||||
@ -38,5 +38,5 @@ let start = new Date().getTime();
|
||||
toSafeInteger(3.2);
|
||||
let end = new Date().getTime();
|
||||
test('toSafeInteger(3.2) takes less than 2s to run', () => {
|
||||
expect((end - start) < 2000).toBeTruthy();
|
||||
expect(end - start < 2000).toBeTruthy();
|
||||
});
|
||||
|
||||
@ -4,33 +4,45 @@ const toSnakeCase = require('./toSnakeCase.js');
|
||||
test('toSnakeCase is a Function', () => {
|
||||
expect(toSnakeCase).toBeInstanceOf(Function);
|
||||
});
|
||||
test('toSnakeCase(\'camelCase\') returns camel_case', () => {
|
||||
test("toSnakeCase('camelCase') returns 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');
|
||||
});
|
||||
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');
|
||||
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'
|
||||
);
|
||||
});
|
||||
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');
|
||||
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'
|
||||
);
|
||||
});
|
||||
test('toSnakeCase() returns undefined', () => {
|
||||
expect(toSnakeCase()).toBe(undefined);
|
||||
});
|
||||
test('toSnakeCase([]) throws an error', () => {
|
||||
expect(() => {toSnakeCase([]);}).toThrow();
|
||||
expect(() => {
|
||||
toSnakeCase([]);
|
||||
}).toThrow();
|
||||
});
|
||||
test('toSnakeCase({}) throws an error', () => {
|
||||
expect(() => {toSnakeCase({});}).toThrow();
|
||||
expect(() => {
|
||||
toSnakeCase({});
|
||||
}).toThrow();
|
||||
});
|
||||
test('toSnakeCase(123) throws an error', () => {
|
||||
expect(() => {toSnakeCase(123);}).toThrow();
|
||||
expect(() => {
|
||||
toSnakeCase(123);
|
||||
}).toThrow();
|
||||
});
|
||||
let start = new Date().getTime();
|
||||
toSnakeCase('IAmListeningToFMWhileLoadingDifferentURLOnMyBrowserAndAlsoEditingSomeXMLAndHTML');
|
||||
let end = new Date().getTime();
|
||||
test('toSnakeCase(IAmListeningToFMWhileLoadingDifferentURLOnMyBrowserAndAlsoEditingSomeXMLAndHTML) takes less than 2s to run', () => {
|
||||
expect((end - start) < 2000).toBeTruthy();
|
||||
expect(end - start < 2000).toBeTruthy();
|
||||
});
|
||||
|
||||
@ -5,10 +5,14 @@ test('transform is a Function', () => {
|
||||
expect(transform).toBeInstanceOf(Function);
|
||||
});
|
||||
test('Transforms an object', () => {
|
||||
expect(transform(
|
||||
expect(
|
||||
transform(
|
||||
{ a: 1, b: 2, c: 1 },
|
||||
(r, v, k) => {
|
||||
(r[v] || (r[v] = [])).push(k);
|
||||
return r;
|
||||
},{})).toEqual({ '1': ['a', 'c'], '2': ['b'] });
|
||||
},
|
||||
{}
|
||||
)
|
||||
).toEqual({ '1': ['a', 'c'], '2': ['b'] });
|
||||
});
|
||||
|
||||
@ -5,5 +5,10 @@ test('truthCheckCollection is a Function', () => {
|
||||
expect(truthCheckCollection).toBeInstanceOf(Function);
|
||||
});
|
||||
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();
|
||||
});
|
||||
|
||||
@ -7,4 +7,3 @@ test('unary is a Function', () => {
|
||||
test('Discards arguments after the first one', () => {
|
||||
expect(['6', '8', '10'].map(unary(parseInt))).toEqual([6, 8, 10]);
|
||||
});
|
||||
|
||||
|
||||
@ -5,5 +5,7 @@ test('unescapeHTML is a Function', () => {
|
||||
expect(unescapeHTML).toBeInstanceOf(Function);
|
||||
});
|
||||
test('Unescapes escaped HTML characters.', () => {
|
||||
expect(unescapeHTML('<a href="#">Me & you</a>')).toBe('<a href="#">Me & you</a>');
|
||||
expect(unescapeHTML('<a href="#">Me & you</a>')).toBe(
|
||||
'<a href="#">Me & you</a>'
|
||||
);
|
||||
});
|
||||
|
||||
@ -7,7 +7,7 @@ test('union is a Function', () => {
|
||||
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]);
|
||||
});
|
||||
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']);
|
||||
});
|
||||
test('union([[], {}], [1, 2, 3]) returns [[], {}, 1, 2, 3]', () => {
|
||||
@ -17,26 +17,38 @@ test('union([], []) returns []', () => {
|
||||
expect(union([], [])).toEqual([]);
|
||||
});
|
||||
test('union() throws an error', () => {
|
||||
expect(() => {union(); }).toThrow();
|
||||
expect(() => {
|
||||
union();
|
||||
}).toThrow();
|
||||
});
|
||||
test('union(true, \'str\') throws an error', () => {
|
||||
expect(() => {union(true, 'str'); }).toThrow();
|
||||
test("union(true, 'str') throws an error", () => {
|
||||
expect(() => {
|
||||
union(true, 'str');
|
||||
}).toThrow();
|
||||
});
|
||||
test('union(\'false\', true) throws an error', () => {
|
||||
expect(() => {union('false', true); }).toThrow();
|
||||
test("union('false', true) throws an error", () => {
|
||||
expect(() => {
|
||||
union('false', true);
|
||||
}).toThrow();
|
||||
});
|
||||
test('union((123, {}) throws an error', () => {
|
||||
expect(() => {union(123, {}); }).toThrow();
|
||||
expect(() => {
|
||||
union(123, {});
|
||||
}).toThrow();
|
||||
});
|
||||
test('union([], {}) throws an error', () => {
|
||||
expect(() => {union([], {}); }).toThrow();
|
||||
expect(() => {
|
||||
union([], {});
|
||||
}).toThrow();
|
||||
});
|
||||
test('union(undefined, null) throws an error', () => {
|
||||
expect(() => {union(undefined, null); }).toThrow();
|
||||
expect(() => {
|
||||
union(undefined, null);
|
||||
}).toThrow();
|
||||
});
|
||||
let start = new Date().getTime();
|
||||
union([1, 2, 3], [4, 3, 2]);
|
||||
let end = new Date().getTime();
|
||||
test('union([1, 2, 3], [4, 3, 2]) takes less than 2s to run', () => {
|
||||
expect((end - start) < 2000).toBeTruthy();
|
||||
expect(end - start < 2000).toBeTruthy();
|
||||
});
|
||||
|
||||
@ -5,5 +5,7 @@ test('unionWith is a Function', () => {
|
||||
expect(unionWith).toBeInstanceOf(Function);
|
||||
});
|
||||
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]);
|
||||
});
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
const expect = require('expect');
|
||||
const uniqueElements = require('./uniqueElements.js');
|
||||
|
||||
|
||||
test('uniqueElements is a 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]', () => {
|
||||
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, \'\']', () => {
|
||||
expect(uniqueElements([true, 0, 1, false, false, undefined, null, ''])).toEqual([true, 0, 1, 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,
|
||||
''
|
||||
]);
|
||||
});
|
||||
test('uniqueElements() returns []', () => {
|
||||
expect(uniqueElements()).toEqual([]);
|
||||
@ -23,24 +30,32 @@ test('uniqueElements(null) returns []', () => {
|
||||
test('uniqueElements(undefined) returns []', () => {
|
||||
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']);
|
||||
});
|
||||
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', () => {
|
||||
expect(() => {uniqueElements({}); }).toThrow();
|
||||
expect(() => {
|
||||
uniqueElements({});
|
||||
}).toThrow();
|
||||
});
|
||||
test('uniqueElements(true) throws an error', () => {
|
||||
expect(() => {uniqueElements(true); }).toThrow();
|
||||
expect(() => {
|
||||
uniqueElements(true);
|
||||
}).toThrow();
|
||||
});
|
||||
test('uniqueElements(false) throws an error', () => {
|
||||
expect(() => {uniqueElements(false); }).toThrow();
|
||||
expect(() => {
|
||||
uniqueElements(false);
|
||||
}).toThrow();
|
||||
});
|
||||
let start = new Date().getTime();
|
||||
uniqueElements([true, 0, 1, false, false, undefined, null, '']);
|
||||
let end = new Date().getTime();
|
||||
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();
|
||||
});
|
||||
|
||||
@ -6,27 +6,35 @@ test('uniqueElementsBy is a Function', () => {
|
||||
});
|
||||
|
||||
test('uniqueElementsBy works for properties', () => {
|
||||
expect(uniqueElementsBy(
|
||||
expect(
|
||||
uniqueElementsBy(
|
||||
[
|
||||
{ id: 0, value: 'a' },
|
||||
{ id: 1, value: 'b' },
|
||||
{ id: 2, value: 'c' },
|
||||
{ id: 1, value: 'd' },
|
||||
{ id: 0, value: 'e' },
|
||||
{ id: 0, value: 'e' }
|
||||
],
|
||||
(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', () => {
|
||||
expect(uniqueElementsBy(
|
||||
expect(
|
||||
uniqueElementsBy(
|
||||
[
|
||||
{ id: 0, value: 'a', n: { p: 0 } },
|
||||
{ id: 1, value: 'b', n: { p: 1 } },
|
||||
{ id: 2, value: 'c', n: { p: 2 } },
|
||||
{ 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
|
||||
)).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 } }
|
||||
]);
|
||||
});
|
||||
|
||||
@ -6,27 +6,35 @@ test('uniqueElementsByRight is a Function', () => {
|
||||
});
|
||||
|
||||
test('uniqueElementsByRight works for properties', () => {
|
||||
expect(uniqueElementsByRight(
|
||||
expect(
|
||||
uniqueElementsByRight(
|
||||
[
|
||||
{ id: 0, value: 'a' },
|
||||
{ id: 1, value: 'b' },
|
||||
{ id: 2, value: 'c' },
|
||||
{ id: 1, value: 'd' },
|
||||
{ id: 0, value: 'e' },
|
||||
{ id: 0, value: 'e' }
|
||||
],
|
||||
(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', () => {
|
||||
expect(uniqueElementsByRight(
|
||||
expect(
|
||||
uniqueElementsByRight(
|
||||
[
|
||||
{ id: 0, value: 'a', n: { p: 0 } },
|
||||
{ id: 1, value: 'b', n: { p: 1 } },
|
||||
{ id: 2, value: 'c', n: { p: 2 } },
|
||||
{ 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
|
||||
)).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 } }
|
||||
]);
|
||||
});
|
||||
|
||||
@ -4,9 +4,9 @@ const unzip = require('./unzip.js');
|
||||
test('unzip is a 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]]);
|
||||
});
|
||||
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]]);
|
||||
});
|
||||
|
||||
@ -5,5 +5,7 @@ test('unzipWith is a 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]', () => {
|
||||
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]);
|
||||
});
|
||||
|
||||
@ -4,10 +4,7 @@ const when = require('./when.js');
|
||||
test('when is a Function', () => {
|
||||
expect(when).toBeInstanceOf(Function);
|
||||
});
|
||||
const doubleEvenNumbers = when(
|
||||
(x) => x % 2 === 0,
|
||||
(x) => x * 2
|
||||
);
|
||||
const doubleEvenNumbers = when(x => x % 2 === 0, x => x * 2);
|
||||
test('Returns the proper result', () => {
|
||||
expect(doubleEvenNumbers(2)).toBe(4);
|
||||
});
|
||||
|
||||
@ -10,24 +10,34 @@ test('without([2, 1, 2, 3], 1, 2) returns [3]', () => {
|
||||
test('without([]) returns []', () => {
|
||||
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]);
|
||||
});
|
||||
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']);
|
||||
});
|
||||
test('without() throws an error', () => {
|
||||
expect(() => { without(); }).toThrow();
|
||||
expect(() => {
|
||||
without();
|
||||
}).toThrow();
|
||||
});
|
||||
test('without(null) throws an error', () => {
|
||||
expect(() => { without(null); }).toThrow();
|
||||
expect(() => {
|
||||
without(null);
|
||||
}).toThrow();
|
||||
});
|
||||
test('without(undefined) throws an error', () => {
|
||||
expect(() => { without(undefined); }).toThrow();
|
||||
expect(() => {
|
||||
without(undefined);
|
||||
}).toThrow();
|
||||
});
|
||||
test('without(123) throws an error', () => {
|
||||
expect(() => { without(123); }).toThrow();
|
||||
expect(() => {
|
||||
without(123);
|
||||
}).toThrow();
|
||||
});
|
||||
test('without({}) throws an error', () => {
|
||||
expect(() => { without({}); }).toThrow();
|
||||
expect(() => {
|
||||
without({});
|
||||
}).toThrow();
|
||||
});
|
||||
|
||||
@ -4,30 +4,42 @@ const words = require('./words.js');
|
||||
test('words is a Function', () => {
|
||||
expect(words).toBeInstanceOf(Function);
|
||||
});
|
||||
test('words(\'I love javaScript!!\') returns [I, love, javaScript]', () => {
|
||||
expect(words('I love javaScript!!')).toEqual(["I", "love", "javaScript"]);
|
||||
test("words('I love javaScript!!') returns [I, love, javaScript]", () => {
|
||||
expect(words('I love javaScript!!')).toEqual(['I', 'love', 'javaScript']);
|
||||
});
|
||||
test('words(\'python, javaScript & coffee\') returns [python, javaScript, coffee]', () => {
|
||||
expect(words('python, javaScript & coffee')).toEqual(["python", "javaScript", "coffee"]);
|
||||
test("words('python, javaScript & coffee') returns [python, javaScript, coffee]", () => {
|
||||
expect(words('python, javaScript & coffee')).toEqual(['python', 'javaScript', 'coffee']);
|
||||
});
|
||||
test('words(I love javaScript!!) returns an array', () => {
|
||||
expect(Array.isArray(words('I love javaScript!!'))).toBeTruthy();
|
||||
});
|
||||
test('words() throws an error', () => {
|
||||
expect(() => { words(); }).toThrow();
|
||||
expect(() => {
|
||||
words();
|
||||
}).toThrow();
|
||||
});
|
||||
test('words(null) throws an error', () => {
|
||||
expect(() => { words(null); }).toThrow();
|
||||
expect(() => {
|
||||
words(null);
|
||||
}).toThrow();
|
||||
});
|
||||
test('words(undefined) throws an error', () => {
|
||||
expect(() => { words(undefined); }).toThrow();
|
||||
expect(() => {
|
||||
words(undefined);
|
||||
}).toThrow();
|
||||
});
|
||||
test('words({}) throws an error', () => {
|
||||
expect(() => { words({}); }).toThrow();
|
||||
expect(() => {
|
||||
words({});
|
||||
}).toThrow();
|
||||
});
|
||||
test('words([]) throws an error', () => {
|
||||
expect(() => { words([]); }).toThrow();
|
||||
expect(() => {
|
||||
words([]);
|
||||
}).toThrow();
|
||||
});
|
||||
test('words(1234) throws an error', () => {
|
||||
expect(() => { words(1234); }).toThrow();
|
||||
expect(() => {
|
||||
words(1234);
|
||||
}).toThrow();
|
||||
});
|
||||
|
||||
@ -4,6 +4,6 @@ const xProd = require('./xProd.js');
|
||||
test('xProd is a 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']]);
|
||||
});
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
const expect = require('expect');
|
||||
const zip = require('./zip.js');
|
||||
|
||||
|
||||
test('zip is a 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();
|
||||
});
|
||||
test('zip(null) throws an error', () => {
|
||||
expect(() => {zip(null);}).toThrow();
|
||||
expect(() => {
|
||||
zip(null);
|
||||
}).toThrow();
|
||||
});
|
||||
test('zip(undefined) throws an error', () => {
|
||||
expect(() => {zip(undefined);}).toThrow();
|
||||
expect(() => {
|
||||
zip(undefined);
|
||||
}).toThrow();
|
||||
});
|
||||
|
||||
@ -17,17 +17,27 @@ test('zipObject([a], string) returns { a: s }', () => {
|
||||
expect(zipObject(['a'], 'string')).toEqual({ a: 's' });
|
||||
});
|
||||
test('zipObject() throws an error', () => {
|
||||
expect(() => {zipObject();}).toThrow();
|
||||
expect(() => {
|
||||
zipObject();
|
||||
}).toThrow();
|
||||
});
|
||||
test('zipObject(([\'string\'], null) throws an error', () => {
|
||||
expect(() => {zipObject(['string'], null);}).toThrow();
|
||||
test("zipObject((['string'], null) throws an error", () => {
|
||||
expect(() => {
|
||||
zipObject(['string'], null);
|
||||
}).toThrow();
|
||||
});
|
||||
test('zipObject(null, [1]) throws an error', () => {
|
||||
expect(() => {zipObject(null, [1]);}).toThrow();
|
||||
expect(() => {
|
||||
zipObject(null, [1]);
|
||||
}).toThrow();
|
||||
});
|
||||
test('zipObject(\'string\') throws an error', () => {
|
||||
expect(() => {zipObject('string');}).toThrow();
|
||||
test("zipObject('string') throws an error", () => {
|
||||
expect(() => {
|
||||
zipObject('string');
|
||||
}).toThrow();
|
||||
});
|
||||
test('zipObject(\'test\', \'string\') throws an error', () => {
|
||||
expect(() => {zipObject('test', 'string');}).toThrow();
|
||||
test("zipObject('test', 'string') throws an error", () => {
|
||||
expect(() => {
|
||||
zipObject('test', 'string');
|
||||
}).toThrow();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user