Test files linted
This commit is contained in:
@ -5,14 +5,14 @@ test('CSVToArray is a Function', () => {
|
||||
expect(CSVToArray).toBeInstanceOf(Function);
|
||||
});
|
||||
test('CSVToArray works with default delimiter', () => {
|
||||
expect(CSVToArray('a,b\nc,d')).toEqual([['a','b'],['c','d']]);
|
||||
expect(CSVToArray('a,b\nc,d')).toEqual([['a', 'b'], ['c', 'd']]);
|
||||
});
|
||||
test('CSVToArray works with custom delimiter', () => {
|
||||
expect(CSVToArray('a;b\nc;d', ';')).toEqual([['a','b'],['c','d']]);
|
||||
expect(CSVToArray('a;b\nc;d', ';')).toEqual([['a', 'b'], ['c', 'd']]);
|
||||
});
|
||||
test('CSVToArray omits the first row', () => {
|
||||
expect(CSVToArray('col1,col2\na,b\nc,d', ',', true)).toEqual([['a','b'],['c','d']]);
|
||||
expect(CSVToArray('col1,col2\na,b\nc,d', ',', true)).toEqual([['a', 'b'], ['c', 'd']]);
|
||||
});
|
||||
test('CSVToArray omits the first row and works with a custom delimiter', () => {
|
||||
expect(CSVToArray('col1;col2\na;b\nc;d', ';', true)).toEqual([['a','b'],['c','d']]);
|
||||
expect(CSVToArray('col1;col2\na;b\nc;d', ';', true)).toEqual([['a', 'b'], ['c', 'd']]);
|
||||
});
|
||||
|
||||
@ -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'
|
||||
);
|
||||
});
|
||||
|
||||
@ -5,26 +5,26 @@ test('all is a Function', () => {
|
||||
expect(all).toBeInstanceOf(Function);
|
||||
});
|
||||
test('Returns true for arrays with no falsey values', () => {
|
||||
expect(all([4,1,2,3])).toBeTruthy();
|
||||
expect(all([4, 1, 2, 3])).toBeTruthy();
|
||||
});
|
||||
test('Returns false for arrays with 0', () => {
|
||||
expect(all([0,1])).toBeFalsy();
|
||||
expect(all([0, 1])).toBeFalsy();
|
||||
});
|
||||
test('Returns false for arrays with NaN', () => {
|
||||
expect(all([NaN,1])).toBeFalsy();
|
||||
expect(all([NaN, 1])).toBeFalsy();
|
||||
});
|
||||
test('Returns false for arrays with undefined', () => {
|
||||
expect(all([undefined,1])).toBeFalsy();
|
||||
expect(all([undefined, 1])).toBeFalsy();
|
||||
});
|
||||
test('Returns false for arrays with null', () => {
|
||||
expect(all([null,1])).toBeFalsy();
|
||||
expect(all([null, 1])).toBeFalsy();
|
||||
});
|
||||
test('Returns false for arrays with empty strings', () => {
|
||||
expect(all(['',1])).toBeFalsy();
|
||||
expect(all(['', 1])).toBeFalsy();
|
||||
});
|
||||
test('Returns true with predicate function', () => {
|
||||
expect(all([4,1,2,3], x => x >= 1)).toBeTruthy();
|
||||
expect(all([4, 1, 2, 3], x => x >= 1)).toBeTruthy();
|
||||
});
|
||||
test('Returns false with a predicate function', () => {
|
||||
expect(all([0,1], x => x >= 1)).toBeFalsy();
|
||||
expect(all([0, 1], x => x >= 1)).toBeFalsy();
|
||||
});
|
||||
|
||||
@ -5,17 +5,17 @@ test('any is a Function', () => {
|
||||
expect(any).toBeInstanceOf(Function);
|
||||
});
|
||||
test('Returns true for arrays with at least one truthy value', () => {
|
||||
expect(any([0,1,2,3])).toBeTruthy();
|
||||
expect(any([0, 1, 2, 3])).toBeTruthy();
|
||||
});
|
||||
test('Returns false for arrays with no truthy values', () => {
|
||||
expect(any([0,0])).toBeFalsy();
|
||||
expect(any([0, 0])).toBeFalsy();
|
||||
});
|
||||
test('Returns false for arrays with no truthy values', () => {
|
||||
expect(any([NaN,0,undefined,null,''])).toBeFalsy();
|
||||
expect(any([NaN, 0, undefined, null, ''])).toBeFalsy();
|
||||
});
|
||||
test('Returns true with predicate function', () => {
|
||||
expect(any([4,1,0,3], x => x >= 1)).toBeTruthy();
|
||||
expect(any([4, 1, 0, 3], x => x >= 1)).toBeTruthy();
|
||||
});
|
||||
test('Returns false with a predicate function', () => {
|
||||
expect(any([0,1], x => x < 0)).toBeFalsy();
|
||||
expect(any([0, 1], x => x < 0)).toBeFalsy();
|
||||
});
|
||||
|
||||
@ -5,7 +5,7 @@ test('approximatelyEqual is a Function', () => {
|
||||
expect(approximatelyEqual).toBeInstanceOf(Function);
|
||||
});
|
||||
test('Works for PI / 2', () => {
|
||||
expect(approximatelyEqual(Math.PI / 2.0 , 1.5708)).toBeTruthy();
|
||||
expect(approximatelyEqual(Math.PI / 2.0, 1.5708)).toBeTruthy();
|
||||
});
|
||||
test('Works for 0.1 + 0.2 === 0.3', () => {
|
||||
expect(approximatelyEqual(0.1 + 0.2, 0.3)).toBeTruthy();
|
||||
|
||||
@ -5,8 +5,8 @@ test('arrayToCSV is a Function', () => {
|
||||
expect(arrayToCSV).toBeInstanceOf(Function);
|
||||
});
|
||||
test('arrayToCSV works with default delimiter', () => {
|
||||
expect(arrayToCSV([['a','b'],['c','d']])).toBe('"a","b"\n"c","d"');
|
||||
expect(arrayToCSV([['a', 'b'], ['c', 'd']])).toBe('"a","b"\n"c","d"');
|
||||
});
|
||||
test('arrayToCSV works with custom delimiter', () => {
|
||||
expect(arrayToCSV([['a','b'],['c','d']], ';')).toBe('"a";"b"\n"c";"d"');
|
||||
expect(arrayToCSV([['a', 'b'], ['c', 'd']], ';')).toBe('"a";"b"\n"c";"d"');
|
||||
});
|
||||
|
||||
@ -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);
|
||||
@ -29,7 +32,7 @@ test('average(String) returns NaN', () => {
|
||||
expect(isNaN(average('String'))).toBeTruthy();
|
||||
});
|
||||
test('average({ a: 123}) returns NaN', () => {
|
||||
expect(isNaN(average({ a: 123}))).toBeTruthy();
|
||||
expect(isNaN(average({ a: 123 }))).toBeTruthy();
|
||||
});
|
||||
test('average([undefined, 0, string]) returns NaN', () => {
|
||||
expect(isNaN(average([undefined, 0, 'string']))).toBeTruthy();
|
||||
@ -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;
|
||||
}
|
||||
};
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
const expect = require('expect');
|
||||
const Blob = class{
|
||||
const Blob = class {
|
||||
constructor(s) {
|
||||
return {
|
||||
size: Buffer.byteLength(s.toString())
|
||||
|
||||
@ -11,7 +11,7 @@ test('Works for arrays with one value', () => {
|
||||
expect(castArray([1])).toEqual([1]);
|
||||
});
|
||||
test('Works for arrays with multiple value', () => {
|
||||
expect(castArray([1,2,3])).toEqual( [1,2,3]);
|
||||
expect(castArray([1, 2, 3])).toEqual([1, 2, 3]);
|
||||
});
|
||||
test('Works for strings', () => {
|
||||
expect(castArray('test')).toEqual(['test']);
|
||||
|
||||
@ -5,7 +5,7 @@ test('chunk is a Function', () => {
|
||||
expect(chunk).toBeInstanceOf(Function);
|
||||
});
|
||||
test('chunk([1, 2, 3, 4, 5], 2) returns [[1,2],[3,4],[5]] ', () => {
|
||||
expect(chunk([1, 2, 3, 4, 5], 2)).toEqual([[1,2],[3,4],[5]]);
|
||||
expect(chunk([1, 2, 3, 4, 5], 2)).toEqual([[1, 2], [3, 4], [5]]);
|
||||
});
|
||||
test('chunk([]) returns []', () => {
|
||||
expect(chunk([])).toEqual([]);
|
||||
@ -14,23 +14,29 @@ test('chunk(123) returns []', () => {
|
||||
expect(chunk(123)).toEqual([]);
|
||||
});
|
||||
test('chunk({ a: 123}) returns []', () => {
|
||||
expect(chunk({ a: 123})).toEqual([]);
|
||||
expect(chunk({ a: 123 })).toEqual([]);
|
||||
});
|
||||
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', () => {
|
||||
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();
|
||||
});
|
||||
|
||||
@ -6,5 +6,5 @@ test('cleanObj is a Function', () => {
|
||||
});
|
||||
const testObj = { a: 1, b: 2, children: { a: 1, b: 2 } };
|
||||
test('Removes any properties except the ones specified from a JSON object', () => {
|
||||
expect(cleanObj(testObj, ['a'], 'children')).toEqual({ a: 1, children: { a: 1}});
|
||||
expect(cleanObj(testObj, ['a'], 'children')).toEqual({ a: 1, children: { a: 1 } });
|
||||
});
|
||||
|
||||
@ -12,7 +12,7 @@ test('When n is odd, times by 3 and add 1', () => {
|
||||
});
|
||||
test('Eventually reaches 1', () => {
|
||||
let n = 9;
|
||||
while(true) {
|
||||
while (true) {
|
||||
if (n === 1) {
|
||||
expect(n).toBe(1);
|
||||
break;
|
||||
|
||||
@ -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,8 +5,8 @@ test('countBy is a Function', () => {
|
||||
expect(countBy).toBeInstanceOf(Function);
|
||||
});
|
||||
test('Works for functions', () => {
|
||||
expect(countBy([6.1, 4.2, 6.3], Math.floor)).toEqual({4: 1, 6: 2});
|
||||
expect(countBy([6.1, 4.2, 6.3], Math.floor)).toEqual({ 4: 1, 6: 2 });
|
||||
});
|
||||
test('Works for property names', () => {
|
||||
expect(countBy(['one', 'two', 'three'], 'length')).toEqual({3: 2, 5: 1});
|
||||
expect(countBy(['one', 'two', 'three'], 'length')).toEqual({ 3: 2, 5: 1 });
|
||||
});
|
||||
|
||||
@ -6,4 +6,4 @@ test('countOccurrences is a Function', () => {
|
||||
});
|
||||
test('Counts the occurrences of a value in an array', () => {
|
||||
expect(countOccurrences([1, 1, 2, 1, 2, 3], 1)).toEqual(3);
|
||||
});
|
||||
});
|
||||
|
||||
@ -9,4 +9,4 @@ test('curries a Math.pow', () => {
|
||||
});
|
||||
test('curries a Math.min', () => {
|
||||
expect(curry(Math.min, 3)(10)(50)(2)).toBe(2);
|
||||
});
|
||||
});
|
||||
|
||||
@ -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,5 @@ test('deepFlatten is a Function', () => {
|
||||
expect(deepFlatten).toBeInstanceOf(Function);
|
||||
});
|
||||
test('Deep flattens an array', () => {
|
||||
expect(deepFlatten([1, [2], [[3], 4], 5])).toEqual( [1, 2, 3, 4, 5]);
|
||||
expect(deepFlatten([1, [2], [[3], 4], 5])).toEqual([1, 2, 3, 4, 5]);
|
||||
});
|
||||
|
||||
@ -5,8 +5,8 @@ test('differenceBy is a Function', () => {
|
||||
expect(differenceBy).toBeInstanceOf(Function);
|
||||
});
|
||||
test('Works using a native function and numbers', () => {
|
||||
expect(differenceBy([2.1, 1.2], [2.3, 3.4], Math.floor)).toEqual( [1.2]);
|
||||
expect(differenceBy([2.1, 1.2], [2.3, 3.4], Math.floor)).toEqual([1.2]);
|
||||
});
|
||||
test('Works with arrow function and objects', () => {
|
||||
expect(differenceBy([{ x: 2 }, { x: 1 }], [{ x: 1 }], v => v.x)).toEqual([ { x: 2 } ]);
|
||||
expect(differenceBy([{ x: 2 }, { x: 1 }], [{ x: 1 }], v => v.x)).toEqual([{ x: 2 }]);
|
||||
});
|
||||
|
||||
@ -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);
|
||||
});
|
||||
|
||||
@ -5,5 +5,5 @@ test('digitize is a Function', () => {
|
||||
expect(digitize).toBeInstanceOf(Function);
|
||||
});
|
||||
test('Converts a number to an array of digits', () => {
|
||||
expect(digitize(123)).toEqual([1, 2,3]);
|
||||
expect(digitize(123)).toEqual([1, 2, 3]);
|
||||
});
|
||||
|
||||
@ -5,7 +5,7 @@ test('drop is a Function', () => {
|
||||
expect(drop).toBeInstanceOf(Function);
|
||||
});
|
||||
test('Works without the last argument', () => {
|
||||
expect(drop([1, 2, 3])).toEqual([2,3]);
|
||||
expect(drop([1, 2, 3])).toEqual([2, 3]);
|
||||
});
|
||||
test('Removes appropriate element count as specified', () => {
|
||||
expect(drop([1, 2, 3], 2)).toEqual([3]);
|
||||
|
||||
@ -5,5 +5,5 @@ test('dropWhile is a Function', () => {
|
||||
expect(dropWhile).toBeInstanceOf(Function);
|
||||
});
|
||||
test('Removes elements in an array until the passed function returns true.', () => {
|
||||
expect(dropWhile([1, 2, 3, 4], n => n >= 3)).toEqual([3,4]);
|
||||
expect(dropWhile([1, 2, 3, 4], n => n >= 3)).toEqual([3, 4]);
|
||||
});
|
||||
|
||||
@ -5,9 +5,9 @@ test('elo is a Function', () => {
|
||||
expect(elo).toBeInstanceOf(Function);
|
||||
});
|
||||
test('Standard 1v1s', () => {
|
||||
expect(elo([1200, 1200])).toEqual([1216,1184]);
|
||||
expect(elo([1200, 1200])).toEqual([1216, 1184]);
|
||||
});
|
||||
test('Standard 1v1s' ,() => {
|
||||
test('Standard 1v1s', () => {
|
||||
expect(elo([1200, 1200], 64)).toEqual([1232, 1168]);
|
||||
});
|
||||
test('4 player FFA, all same rank', () => {
|
||||
|
||||
@ -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>'
|
||||
);
|
||||
});
|
||||
|
||||
@ -5,5 +5,5 @@ test('everyNth is a Function', () => {
|
||||
expect(everyNth).toBeInstanceOf(Function);
|
||||
});
|
||||
test('Returns every nth element in an array', () => {
|
||||
expect(everyNth([1, 2, 3, 4, 5, 6], 2)).toEqual([ 2, 4, 6 ]);
|
||||
expect(everyNth([1, 2, 3, 4, 5, 6], 2)).toEqual([2, 4, 6]);
|
||||
});
|
||||
|
||||
@ -5,6 +5,5 @@ test('filterNonUnique is a Function', () => {
|
||||
expect(filterNonUnique).toBeInstanceOf(Function);
|
||||
});
|
||||
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]);
|
||||
});
|
||||
|
||||
|
||||
@ -6,27 +6,31 @@ test('filterNonUniqueBy is a Function', () => {
|
||||
});
|
||||
|
||||
test('filterNonUniqueBy works for properties', () => {
|
||||
expect(filterNonUniqueBy(
|
||||
[
|
||||
{ id: 0, value: 'a' },
|
||||
{ id: 1, value: 'b' },
|
||||
{ id: 2, value: 'c' },
|
||||
{ id: 1, value: 'd' },
|
||||
{ id: 0, value: 'e' },
|
||||
],
|
||||
(a, b) => a.id === b.id
|
||||
)).toEqual([ { id: 2, value: 'c' } ]);
|
||||
expect(
|
||||
filterNonUniqueBy(
|
||||
[
|
||||
{ id: 0, value: 'a' },
|
||||
{ id: 1, value: 'b' },
|
||||
{ id: 2, value: 'c' },
|
||||
{ id: 1, value: 'd' },
|
||||
{ id: 0, value: 'e' }
|
||||
],
|
||||
(a, b) => a.id === b.id
|
||||
)
|
||||
).toEqual([{ id: 2, value: 'c' }]);
|
||||
});
|
||||
|
||||
test('filterNonUniqueBy works for nested properties', () => {
|
||||
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} },
|
||||
],
|
||||
(a, b) => a.id === b.id
|
||||
)).toEqual([ { id: 2, value: 'c', n: {p: 2} } ]);
|
||||
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 } }
|
||||
],
|
||||
(a, b) => a.id === b.id
|
||||
)
|
||||
).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(
|
||||
{
|
||||
barney: { age: 36, active: true },
|
||||
fred: { age: 40, active: false },
|
||||
pebbles: { age: 1, active: true }
|
||||
},
|
||||
o => o['active'])).toBe('barney');
|
||||
expect(
|
||||
findKey(
|
||||
{
|
||||
barney: { age: 36, active: true },
|
||||
fred: { age: 40, active: false },
|
||||
pebbles: { age: 1, active: true }
|
||||
},
|
||||
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(
|
||||
{
|
||||
barney: { age: 36, active: true },
|
||||
fred: { age: 40, active: false },
|
||||
pebbles: { age: 1, active: true }
|
||||
},
|
||||
o => o['active'])).toBe('pebbles');
|
||||
expect(
|
||||
findLastKey(
|
||||
{
|
||||
barney: { age: 36, active: true },
|
||||
fred: { age: 40, active: false },
|
||||
pebbles: { age: 1, active: true }
|
||||
},
|
||||
o => o['active']
|
||||
)
|
||||
).toBe('pebbles');
|
||||
});
|
||||
|
||||
@ -8,5 +8,5 @@ test('Flattens an object with the paths for keys', () => {
|
||||
expect(flattenObject({ a: { b: { c: 1 } }, d: 1 })).toEqual({ 'a.b.c': 1, d: 1 });
|
||||
});
|
||||
test('Works with arrays', () => {
|
||||
expect(flattenObject([0,1,[2,[1]],1])).toEqual({ 0: 0, 1: 1, 3: 1, '2.0': 2, '2.1.0': 1 });
|
||||
expect(flattenObject([0, 1, [2, [1]], 1])).toEqual({ 0: 0, 1: 1, 3: 1, '2.0': 2, '2.1.0': 1 });
|
||||
});
|
||||
|
||||
@ -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');
|
||||
});
|
||||
|
||||
@ -10,7 +10,7 @@ function Foo() {
|
||||
}
|
||||
Foo.prototype.c = () => 3;
|
||||
test('Returns own methods', () => {
|
||||
expect(functions(new Foo())).toEqual( ['a', 'b']);
|
||||
expect(functions(new Foo())).toEqual(['a', 'b']);
|
||||
});
|
||||
test('Returns own and inherited methods', () => {
|
||||
expect(functions(new Foo(), true)).toEqual(['a', 'b', 'c']);
|
||||
|
||||
@ -9,4 +9,4 @@ test('Calculates the greatest common divisor between two or more numbers/arrays'
|
||||
});
|
||||
test('Calculates the greatest common divisor between two or more numbers/arrays', () => {
|
||||
expect(gcd(...[12, 8, 32])).toEqual(4);
|
||||
});
|
||||
});
|
||||
|
||||
@ -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,8 +5,8 @@ test('groupBy is a Function', () => {
|
||||
expect(groupBy).toBeInstanceOf(Function);
|
||||
});
|
||||
test('Groups the elements of an array based on the given function', () => {
|
||||
expect(groupBy([6.1, 4.2, 6.3], Math.floor)).toEqual({4: [4.2], 6: [6.1, 6.3]});
|
||||
expect(groupBy([6.1, 4.2, 6.3], Math.floor)).toEqual({ 4: [4.2], 6: [6.1, 6.3] });
|
||||
});
|
||||
test('Groups the elements of an array based on the given function', () => {
|
||||
expect(groupBy(['one', 'two', 'three'], 'length')).toEqual({3: ['one', 'two'], 5: ['three']});
|
||||
});
|
||||
expect(groupBy(['one', 'two', 'three'], 'length')).toEqual({ 3: ['one', 'two'], 5: ['three'] });
|
||||
});
|
||||
|
||||
@ -3,4 +3,4 @@ const hasClass = require('./hasClass.js');
|
||||
|
||||
test('hasClass is a Function', () => {
|
||||
expect(hasClass).toBeInstanceOf(Function);
|
||||
});
|
||||
});
|
||||
|
||||
@ -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')
|
||||
);
|
||||
});
|
||||
|
||||
@ -5,29 +5,35 @@ test('head is a Function', () => {
|
||||
expect(head).toBeInstanceOf(Function);
|
||||
});
|
||||
test('head({ a: 1234}) returns undefined', () => {
|
||||
expect(head({ a: 1234}) === undefined).toBeTruthy();
|
||||
expect(head({ a: 1234 }) === undefined).toBeTruthy();
|
||||
});
|
||||
test('head([1, 2, 3]) returns 1', () => {
|
||||
expect(head([1, 2, 3])).toBe(1);
|
||||
});
|
||||
test('head({ 0: false}) returns false', () => {
|
||||
expect(head({ 0: false})).toBeFalsy();
|
||||
expect(head({ 0: false })).toBeFalsy();
|
||||
});
|
||||
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,9 +1,9 @@
|
||||
const httpPut = (url, data, callback, err = console.error) => {
|
||||
const request = new XMLHttpRequest();
|
||||
request.open("PUT", url, true);
|
||||
request.setRequestHeader('Content-type','application/json; charset=utf-8');
|
||||
request.onload = () => callback(request);
|
||||
request.onerror = () => err(request);
|
||||
request.send(data);
|
||||
const request = new XMLHttpRequest();
|
||||
request.open('PUT', url, true);
|
||||
request.setRequestHeader('Content-type', 'application/json; charset=utf-8');
|
||||
request.onload = () => callback(request);
|
||||
request.onerror = () => err(request);
|
||||
request.send(data);
|
||||
};
|
||||
module.exports = httpPut;
|
||||
|
||||
@ -5,7 +5,7 @@ test('indexOfAll is a Function', () => {
|
||||
expect(indexOfAll).toBeInstanceOf(Function);
|
||||
});
|
||||
test('Returns all indices of val in an array', () => {
|
||||
expect(indexOfAll([1, 2, 3, 1, 2, 3], 1)).toEqual([0,3]);
|
||||
expect(indexOfAll([1, 2, 3, 1, 2, 3], 1)).toEqual([0, 3]);
|
||||
});
|
||||
test('Returns all indices of val in an array', () => {
|
||||
expect(indexOfAll([1, 2, 3], 4)).toEqual([]);
|
||||
|
||||
@ -5,5 +5,5 @@ test('initialize2DArray is a Function', () => {
|
||||
expect(initialize2DArray).toBeInstanceOf(Function);
|
||||
});
|
||||
test('Initializes a 2D array of given width and height and value', () => {
|
||||
expect(initialize2DArray(2, 2, 0)).toEqual([[0,0], [0,0]]);
|
||||
expect(initialize2DArray(2, 2, 0)).toEqual([[0, 0], [0, 0]]);
|
||||
});
|
||||
|
||||
@ -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\' ] }', () => {
|
||||
expect(invertKeyValues({ a: 1, b: 2, c: 1 })).toEqual({ 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']
|
||||
});
|
||||
});
|
||||
|
||||
@ -1,2 +1,2 @@
|
||||
const isArray = val => Array.isArray(val);
|
||||
module.exports = isArray;
|
||||
module.exports = isArray;
|
||||
|
||||
@ -1,2 +1,2 @@
|
||||
const isArrayBuffer = val => val instanceof ArrayBuffer;
|
||||
module.exports = isArrayBuffer;
|
||||
module.exports = isArrayBuffer;
|
||||
|
||||
@ -8,7 +8,7 @@ test('Returns true for a string', () => {
|
||||
expect(isArrayLike('abc')).toBeTruthy();
|
||||
});
|
||||
test('Returns true for an array', () => {
|
||||
expect(isArrayLike([1,2,3])).toBeTruthy();
|
||||
expect(isArrayLike([1, 2, 3])).toBeTruthy();
|
||||
});
|
||||
test('Returns false for null', () => {
|
||||
expect(isArrayLike(null)).toBeFalsy();
|
||||
|
||||
@ -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();
|
||||
});
|
||||
|
||||
|
||||
@ -1,2 +1,2 @@
|
||||
const isMap = val => val instanceof Map;
|
||||
module.exports = isMap;
|
||||
module.exports = isMap;
|
||||
|
||||
@ -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({
|
||||
then: function() {
|
||||
return '';
|
||||
}
|
||||
})).toBeTruthy();
|
||||
expect(
|
||||
isPromiseLike({
|
||||
then: function() {
|
||||
return '';
|
||||
}
|
||||
})
|
||||
).toBeTruthy();
|
||||
});
|
||||
test('Returns false for an empty object', () => {
|
||||
expect(isPromiseLike({})).toBeFalsy();
|
||||
|
||||
@ -1,2 +1,2 @@
|
||||
const isRegExp = val => val instanceof RegExp;
|
||||
module.exports = isRegExp;
|
||||
module.exports = isRegExp;
|
||||
|
||||
@ -1,2 +1,2 @@
|
||||
const isSet = val => val instanceof Set;
|
||||
module.exports = isSet;
|
||||
module.exports = isSet;
|
||||
|
||||
@ -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;
|
||||
[...str].reduce(
|
||||
(matchIndex, char) =>
|
||||
char.toLowerCase() === (pattern[matchIndex] || '').toLowerCase()
|
||||
? matchIndex + 1
|
||||
: matchIndex,
|
||||
0
|
||||
) === pattern.length
|
||||
? true
|
||||
: false;
|
||||
module.exports = isSimilar;
|
||||
|
||||
@ -4,11 +4,11 @@ const isTravisCI = require('./isTravisCI.js');
|
||||
test('isTravisCI is a Function', () => {
|
||||
expect(isTravisCI).toBeInstanceOf(Function);
|
||||
});
|
||||
if(isTravisCI())
|
||||
if (isTravisCI())
|
||||
test('Running on Travis, correctly evaluates', () => {
|
||||
expect(isTravisCI()).toBeTruthy();
|
||||
});
|
||||
else
|
||||
test('Not running on Travis, correctly evaluates', () => {
|
||||
expect(isTravisCI()).toBeFalsy();
|
||||
});
|
||||
});
|
||||
|
||||
@ -1,2 +1,2 @@
|
||||
const isTypedArray = val => val instanceof TypedArray;
|
||||
module.exports = isTypedArray;
|
||||
module.exports = isTypedArray;
|
||||
|
||||
@ -7,9 +7,9 @@ test('isUpperCase is a Function', () => {
|
||||
test('ABC is all upper case', () => {
|
||||
expect(isUpperCase('ABC')).toBeTruthy();
|
||||
});
|
||||
test('abc is not all upper case', () => {
|
||||
test('abc is not all upper case', () => {
|
||||
expect(isUpperCase('abc')).toBeFalsy();
|
||||
});
|
||||
test('A3@$ is all uppercase', () => {
|
||||
test('A3@$ is all uppercase', () => {
|
||||
expect(isUpperCase('A3@$')).toBeTruthy();
|
||||
});
|
||||
|
||||
@ -1,2 +1,2 @@
|
||||
const isWeakMap = val => val instanceof WeakMap;
|
||||
module.exports = isWeakMap;
|
||||
module.exports = isWeakMap;
|
||||
|
||||
@ -1,2 +1,2 @@
|
||||
const isWeakSet = val => val instanceof WeakSet;
|
||||
module.exports = isWeakSet;
|
||||
module.exports = isWeakSet;
|
||||
|
||||
@ -12,4 +12,4 @@ test('Joins all elements of an array into a string and returns this string', ()
|
||||
});
|
||||
test('Joins all elements of an array into a string and returns this string', () => {
|
||||
expect(join(['pen', 'pineapple', 'apple', 'pen'])).toEqual('pen,pineapple,apple,pen');
|
||||
});
|
||||
});
|
||||
|
||||
@ -5,29 +5,35 @@ test('last is a Function', () => {
|
||||
expect(last).toBeInstanceOf(Function);
|
||||
});
|
||||
test('last({ a: 1234}) returns undefined', () => {
|
||||
expect(last({ a: 1234}) === undefined).toBeTruthy();
|
||||
expect(last({ a: 1234 }) === undefined).toBeTruthy();
|
||||
});
|
||||
test('last([1, 2, 3]) returns 3', () => {
|
||||
expect(last([1, 2, 3])).toBe(3);
|
||||
});
|
||||
test('last({ 0: false}) returns undefined', () => {
|
||||
expect(last({ 0: false})).toBe(undefined);
|
||||
expect(last({ 0: false })).toBe(undefined);
|
||||
});
|
||||
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,18 +1,25 @@
|
||||
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);
|
||||
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);
|
||||
}
|
||||
}
|
||||
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);
|
||||
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
|
||||
);
|
||||
}
|
||||
}
|
||||
return matrix[string2.length][string1.length];
|
||||
}
|
||||
return matrix[string2.length][string1.length];
|
||||
};
|
||||
module.exports = levenshteinDistance;
|
||||
|
||||
@ -7,7 +7,7 @@ test('lowercaseKeys is a Function', () => {
|
||||
const myObj = { Name: 'Adam', sUrnAME: 'Smith' };
|
||||
const myObjLower = lowercaseKeys(myObj);
|
||||
test('Lowercases object keys', () => {
|
||||
expect(myObjLower).toEqual( {name: 'Adam', surname: 'Smith'});
|
||||
expect(myObjLower).toEqual({ name: 'Adam', surname: 'Smith' });
|
||||
});
|
||||
test('Does not mutate original object', () => {
|
||||
expect(myObj).toEqual({ Name: 'Adam', sUrnAME: 'Smith' });
|
||||
|
||||
@ -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(
|
||||
{ greeting: 'hello' },
|
||||
{ greeting: 'hi' },
|
||||
(oV, sV) => isGreeting(oV) && isGreeting(sV)
|
||||
)).toBeTruthy();
|
||||
expect(
|
||||
matchesWith(
|
||||
{ greeting: 'hello' },
|
||||
{ greeting: 'hi' },
|
||||
(oV, sV) => isGreeting(oV) && isGreeting(sV)
|
||||
)
|
||||
).toBeTruthy();
|
||||
});
|
||||
|
||||
@ -13,5 +13,5 @@ test('Function works properly', () => {
|
||||
expect(square(3)).toBe(9);
|
||||
});
|
||||
test('Cache stores values', () => {
|
||||
expect(Array.from(square.cache)).toEqual([[2,4],[3,9]]);
|
||||
expect(Array.from(square.cache)).toEqual([[2, 4], [3, 9]]);
|
||||
});
|
||||
|
||||
@ -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]);
|
||||
});
|
||||
|
||||
@ -5,14 +5,14 @@ test('none is a Function', () => {
|
||||
expect(none).toBeInstanceOf(Function);
|
||||
});
|
||||
test('Returns true for arrays with no truthy values', () => {
|
||||
expect(none([0,undefined,NaN,null,''])).toBeTruthy();
|
||||
expect(none([0, undefined, NaN, null, ''])).toBeTruthy();
|
||||
});
|
||||
test('Returns false for arrays with at least one truthy value', () => {
|
||||
expect(none([0,1])).toBeFalsy();
|
||||
expect(none([0, 1])).toBeFalsy();
|
||||
});
|
||||
test('Returns true with a predicate function', () => {
|
||||
expect(none([4,1,0,3], x => x < 0)).toBeTruthy();
|
||||
expect(none([4, 1, 0, 3], x => x < 0)).toBeTruthy();
|
||||
});
|
||||
test('Returns false with predicate function', () => {
|
||||
expect(none([0,1,2], x => x === 1)).toBeFalsy();
|
||||
expect(none([0, 1, 2], x => x === 1)).toBeFalsy();
|
||||
});
|
||||
|
||||
@ -15,4 +15,3 @@ const last = nthArg(-1);
|
||||
test('Works for negative values', () => {
|
||||
expect(last(1, 2, 3, 4, 5)).toBe(5);
|
||||
});
|
||||
|
||||
|
||||
@ -4,6 +4,6 @@ const objectFromPairs = require('./objectFromPairs.js');
|
||||
test('objectFromPairs is a Function', () => {
|
||||
expect(objectFromPairs).toBeInstanceOf(Function);
|
||||
});
|
||||
test('Creates an object from the given key-value pairs.', () => {
|
||||
expect(objectFromPairs([['a', 1], ['b', 2]])).toEqual({a: 1, b: 2});
|
||||
test('Creates an object from the given key-value pairs.', () => {
|
||||
expect(objectFromPairs([['a', 1], ['b', 2]])).toEqual({ a: 1, b: 2 });
|
||||
});
|
||||
|
||||
@ -5,5 +5,5 @@ test('objectToPairs is a Function', () => {
|
||||
expect(objectToPairs).toBeInstanceOf(Function);
|
||||
});
|
||||
test('Creates an array of key-value pair arrays from an object.', () => {
|
||||
expect(objectToPairs({ a: 1, b: 2 })).toEqual([['a',1],['b', 2]]);
|
||||
expect(objectToPairs({ a: 1, b: 2 })).toEqual([['a', 1], ['b', 2]]);
|
||||
});
|
||||
|
||||
@ -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 });
|
||||
});
|
||||
|
||||
@ -5,5 +5,5 @@ test('omitBy is a Function', () => {
|
||||
expect(omitBy).toBeInstanceOf(Function);
|
||||
});
|
||||
test('Creates an object composed of the properties the given function returns falsey for', () => {
|
||||
expect(omitBy({ a: 1, b: '2', c: 3 }, x => typeof x === 'number')).toEqual( { b: '2' });
|
||||
expect(omitBy({ a: 1, b: '2', c: 3 }, x => typeof x === 'number')).toEqual({ b: '2' });
|
||||
});
|
||||
|
||||
@ -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 }
|
||||
]);
|
||||
});
|
||||
|
||||
@ -6,5 +6,5 @@ test('over is a Function', () => {
|
||||
});
|
||||
const minMax = over(Math.min, Math.max);
|
||||
test('Applies given functions over multiple arguments', () => {
|
||||
expect(minMax(1, 2, 3, 4, 5)).toEqual([1,5]);
|
||||
expect(minMax(1, 2, 3, 4, 5)).toEqual([1, 5]);
|
||||
});
|
||||
|
||||
@ -5,14 +5,14 @@ test('pad is a Function', () => {
|
||||
expect(pad).toBeInstanceOf(Function);
|
||||
});
|
||||
test('cat is padded on both sides', () => {
|
||||
expect(pad('cat',8)).toBe(' cat ');
|
||||
expect(pad('cat', 8)).toBe(' cat ');
|
||||
});
|
||||
test('length of string is 8', () => {
|
||||
expect(pad('cat',8).length).toBe(8);
|
||||
test('length of string is 8', () => {
|
||||
expect(pad('cat', 8).length).toBe(8);
|
||||
});
|
||||
test('pads 42 with "0"', () => {
|
||||
test('pads 42 with "0"', () => {
|
||||
expect(pad(String(42), 6, '0')).toBe('004200');
|
||||
});
|
||||
test('does not truncates if string exceeds length', () => {
|
||||
test('does not truncates if string exceeds length', () => {
|
||||
expect(pad('foobar', 3)).toBe('foobar');
|
||||
});
|
||||
|
||||
@ -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 });
|
||||
});
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user