Test cleanup and fixes [c-d]

This commit is contained in:
Angelos Chalaris
2018-06-18 16:34:04 +03:00
parent d29974ebc9
commit 105185c213
136 changed files with 805 additions and 484 deletions

View File

@ -5,5 +5,7 @@ const RGBToHex = require('./RGBToHex.js');
test('RGBToHex is a Function', () => {
expect(RGBToHex).toBeInstanceOf(Function);
});
t.equal(RGBToHex(255, 165, 1), 'ffa501', "Converts the values of RGB components to a color code.");
test('Converts the values of RGB components to a color code.', () => {
expect(RGBToHex(255, 165, 1)).toBe('ffa501')
});

View File

@ -1,9 +1,9 @@
const expect = require('expect');
const call = require('./call.js');
test('call is a Function', () => {
expect(call).toBeInstanceOf(Function);
});
t.looseEqual(call('map', x => x * 2)([1, 2, 3]), [2, 4, 6], 'Calls function on given object');
test('Calls function on given object', () => {
expect(call('map', x => x * 2)([1, 2, 3])).toBe([2, 4, 6]);
});

View File

@ -1,12 +1,18 @@
const expect = require('expect');
const capitalize = require('./capitalize.js');
test('capitalize is a Function', () => {
expect(capitalize).toBeInstanceOf(Function);
});
t.equal(capitalize('fooBar'), 'FooBar', "Capitalizes the first letter of a string");
t.equal(capitalize('fooBar', true), 'Foobar', "Capitalizes the first letter of a string");
t.equal(capitalize('#!#', true), '#!#', "Works with characters");
t.equal(capitalize('a', true), 'A', "Works with single character words");
test('Capitalizes the first letter of a string', () => {
expect(capitalize('fooBar')).toBe('FooBar');
});
test('Capitalizes the first letter of a string', () => {
expect(capitalize('fooBar', true)).toBe('FooBar');
});
test('Works with characters', () => {
expect(capitalize('#!#', true)).toBe('#!#');
});
test('"Works with single character words', () => {
expect(capitalize('a', true)).toBe('A');
});

View File

@ -1,11 +1,15 @@
const expect = require('expect');
const capitalizeEveryWord = require('./capitalizeEveryWord.js');
test('capitalizeEveryWord is a Function', () => {
expect(capitalizeEveryWord).toBeInstanceOf(Function);
});
t.equal(capitalizeEveryWord('hello world!'), 'Hello World!', "Capitalizes the first letter of every word in a string");
t.equal(capitalizeEveryWord('$# @!'), '$# @!', "Works with characters");
t.equal(capitalizeEveryWord('a'), 'A', "Works with one word string");
test('Capitalizes the first letter of every word in a string', () => {
expect(capitalizeEveryWord('hello world!'), 'Hello World!').toBe();
});
test('Works with characters', () => {
expect(capitalizeEveryWord('$# @!')).toBe('$# @!');
});
test('Works with one word string', () => {
expect(capitalizeEveryWord('a')).toBe('A');
});

View File

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

View File

@ -1,10 +1,11 @@
const expect = require('expect');
const chainAsync = require('./chainAsync.js');
test('chainAsync is a Function', () => {
expect(chainAsync).toBeInstanceOf(Function);
});
test('Calls all functions in an array', () => {
chainAsync([
next => {
next();
@ -15,8 +16,7 @@ const chainAsync = require('./chainAsync.js');
})();
},
next => {
expect(true).toBeTruthy();
}
]);
});

View File

@ -1,32 +1,36 @@
const expect = require('expect');
const chunk = require('./chunk.js');
test('chunk is a Function', () => {
expect(chunk).toBeInstanceOf(Function);
});
t.deepEqual(chunk([1, 2, 3, 4, 5], 2), [[1,2],[3,4],[5]], "chunk([1, 2, 3, 4, 5], 2) returns [[1,2],[3,4],[5]] ");
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]]);
});
test('chunk([]) returns []', () => {
expect(chunk([]), []).toEqual()
expect(chunk([])).toEqual([])
});
test('chunk(123) returns []', () => {
expect(chunk(123), []).toEqual()
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), [ 'st', 'ri', 'ng' ]).toEqual()
expect(chunk('string', 2)).toEqual( [ 'st', 'ri', 'ng' ])
});
test('chunk() throws an error', () => {
expect(chunk()).toThrow();
});
test('chunk(undefined) throws an error', () => {
expect(chunk(undefined)).toThrow();
});
test('chunk(null) throws an error', () => {
expect(chunk(null)).toThrow();
});
t.throws(() => chunk(), 'chunk() throws an error');
t.throws(() => chunk(undefined), 'chunk(undefined) throws an error');
t.throws(() => chunk(null), 'chunk(null) throws an error');
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();
});

View File

@ -1,9 +1,9 @@
const expect = require('expect');
const clampNumber = require('./clampNumber.js');
test('clampNumber is a Function', () => {
expect(clampNumber).toBeInstanceOf(Function);
});
t.equal(clampNumber(2, 3, 5), 3, "Clamps num within the inclusive range specified by the boundary values a and b");
test('Clamps num within the inclusive range specified by the boundary values a and b', () => {
expect(clampNumber(2, 3, 5)).toBe(3)
});

View File

@ -1,10 +1,10 @@
const expect = require('expect');
const cleanObj = require('./cleanObj.js');
test('cleanObj is a Function', () => {
expect(cleanObj).toBeInstanceOf(Function);
});
const testObj = { a: 1, b: 2, children: { a: 1, b: 2 } };
t.deepEqual(cleanObj(testObj, ['a'], 'children'), { a: 1, children : { a: 1}}, "Removes any properties except the ones specified from a JSON object");
test('Removes any properties except the ones specified from a JSON object', () => {
expect(cleanObj(testObj, ['a'], 'children')).toEqual({ a: 1, children : { a: 1}});
});

View File

@ -1,11 +1,10 @@
const expect = require('expect');
const cloneRegExp = require('./cloneRegExp.js');
test('cloneRegExp is a Function', () => {
expect(cloneRegExp).toBeInstanceOf(Function);
});
const rgTest = /./g;
t.notEqual(cloneRegExp(rgTest), rgTest, 'Clones regular expressions properly');
test('Clones regular expressions properly', () => {
expect(cloneRegExp(rgTest).not.toEqual(rgTest);
});

View File

@ -1,9 +1,9 @@
const expect = require('expect');
const coalesce = require('./coalesce.js');
test('coalesce is a Function', () => {
expect(coalesce).toBeInstanceOf(Function);
});
t.deepEqual(coalesce(null, undefined, '', NaN, 'Waldo'), '', "Returns the first non-null/undefined argument");
test('Returns the first non-null/undefined argument', () => {
expect(coalesce(null, undefined, '', NaN, 'Waldo')).toEqual('')
});

View File

@ -1,10 +1,10 @@
const expect = require('expect');
const coalesceFactory = require('./coalesceFactory.js');
test('coalesceFactory is a Function', () => {
expect(coalesceFactory).toBeInstanceOf(Function);
});
const customCoalesce = coalesceFactory(_ => ![null, undefined, '', NaN].includes(_));
t.deepEqual(customCoalesce(undefined, null, NaN, '', 'Waldo'), 'Waldo', "Returns a customized coalesce function");
test('Returns a customized coalesce function', () => {
expect(customCoalesce(undefined, null, NaN, '', 'Waldo')).toEqual('Waldo')
});

View File

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

View File

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

View File

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

View File

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

View File

@ -1,12 +1,12 @@
const expect = require('expect');
const compose = require('./compose.js');
test('compose is a Function', () => {
expect(compose).toBeInstanceOf(Function);
});
const add5 = x => x + 5;
const multiply = (x, y) => x * y;
const multiplyAndAdd5 = compose(add5, multiply);
t.equal(multiplyAndAdd5(5, 2), 15, "Performs right-to-left function composition");
test('Performs right-to-left function composition', () => {
expect(multiplyAndAdd5(5, 2)).toBe(15);
});

View File

@ -1,13 +1,12 @@
const expect = require('expect');
const composeRight = require('./composeRight.js');
test('composeRight is a Function', () => {
expect(composeRight).toBeInstanceOf(Function);
});
const add = (x, y) => x + y;
const square = x => x * x;
const addAndSquare = composeRight(add, square);
t.equal(addAndSquare(1, 2), 9, "Performs left-to-right function composition");
test('Performs left-to-right function composition', () => {
expect(addAndSquare(1, 2)).toBe(9);
});

View File

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

View File

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

View File

@ -1,15 +1,12 @@
const expect = require('expect');
const countBy = require('./countBy.js');
test('countBy is a Function', () => {
expect(countBy).toBeInstanceOf(Function);
});
test('Works for functions', () => {
expect(countBy([6.1, 4.2, 6.3], Math.floor), {4: 1, 6: 2}).toEqual()
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'), {3: 2, 5: 1}).toEqual()
expect(countBy(['one', 'two', 'three'], 'length')).toEqual({3: 2, 5: 1});
});

View File

@ -1,9 +1,9 @@
const expect = require('expect');
const countOccurrences = require('./countOccurrences.js');
test('countOccurrences is a Function', () => {
expect(countOccurrences).toBeInstanceOf(Function);
});
t.deepEqual(countOccurrences([1, 1, 2, 1, 2, 3], 1), 3, "Counts the occurrences of a value in an array");
test('Counts the occurrences of a value in an array', () => {
expect(countOccurrences([1, 1, 2, 1, 2, 3], 1)).toEqual(3);
});

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,10 +1,12 @@
const expect = require('expect');
const curry = require('./curry.js');
test('curry is a Function', () => {
expect(curry).toBeInstanceOf(Function);
});
t.equal(curry(Math.pow)(2)(10), 1024, "curries a Math.pow");
t.equal(curry(Math.min, 3)(10)(50)(2), 2, "curries a Math.min");
test('curries a Math.pow', () => {
expect(curry(Math.pow)(2)(10)).toBe(1024);
});
test('curries a Math.min', () => {
expect(curry(Math.min, 3)(10)(50)(2)).toBe(2);
});

View File

@ -1,10 +1,9 @@
const expect = require('expect');
const debounce = require('./debounce.js');
test('debounce is a Function', () => {
expect(debounce).toBeInstanceOf(Function);
});
debounce(() => {
test('Works as expected', () => {
debounce(() => { expect(true).toBeTruthy(); });
});

View File

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

View File

@ -1,7 +1,6 @@
const expect = require('expect');
const deepClone = require('./deepClone.js');
test('deepClone is a Function', () => {
expect(deepClone).toBeInstanceOf(Function);
});
@ -9,9 +8,15 @@ const deepClone = require('./deepClone.js');
const b = deepClone(a);
const c = [{foo: "bar"}];
const d = deepClone(c);
t.notEqual(a, b, 'Shallow cloning works');
t.notEqual(a.obj, b.obj, 'Deep cloning works');
t.notEqual(c, d, "Array shallow cloning works");
t.notEqual(c[0], d[0], "Array deep cloning works");
test('Shallow cloning works', () => {
expect(a).not.toEqual(b);
});
test('Deep cloning works', () => {
expect(a.obj).not.toEqual(b.obj);
});
test('Array shallow cloning works', () => {
expect(c).not.toEqual(d);
});
test('Array deep cloning works', () => {
expect(c[0]).not.toEqual(d[0]);
});

View File

@ -1,9 +1,9 @@
const expect = require('expect');
const deepFlatten = require('./deepFlatten.js');
test('deepFlatten is a Function', () => {
expect(deepFlatten).toBeInstanceOf(Function);
});
t.deepEqual(deepFlatten([1, [2], [[3], 4], 5]), [1, 2, 3, 4, 5], "Deep flattens an array");
test('Deep flattens an array', () => {
expect(deepFlatten([1, [2], [[3], 4], 5])).toEqual( [1, 2, 3, 4, 5]);
});

View File

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

View File

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

View File

@ -1,13 +1,10 @@
const expect = require('expect');
const degreesToRads = require('./degreesToRads.js');
const approxeq = (v1,v2, diff = 0.001) => Math.abs(v1 - v2) < diff;
// const approxeq = (v1,v2, diff = 0.001) => Math.abs(v1 - v2) < diff;
test('degreesToRads is a Function', () => {
expect(degreesToRads).toBeInstanceOf(Function);
});
test('Returns the appropriate value', () => {
expect(approxeq(degreesToRads(90.0), Math.PI / 2)).toBeTruthy();
expect(degreesToRads(90.0)).toBeCloseTo(Math.PI / 2, 3);
});

View File

@ -1,18 +1,15 @@
const expect = require('expect');
const delay = require('./delay.js');
test('delay is a Function', () => {
expect(delay).toBeInstanceOf(Function);
});
test('Works as expecting, passing arguments properly', () => {
delay(
function(text) {
test('Works as expecting, passing arguments properly', () => {
expect(text, 'test').toBe()
});
expect(text).toBe('test');
},
1000,
'test'
);
});

View File

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

View File

@ -1,9 +1,9 @@
const expect = require('expect');
const difference = require('./difference.js');
test('difference is a Function', () => {
expect(difference).toBeInstanceOf(Function);
});
t.deepEqual(difference([1, 2, 3], [1, 2, 4]), [3], "Returns the difference between two arrays");
test('Returns the difference between two arrays', () => {
expect(difference([1, 2, 3], [1, 2, 4])).toEqual([3])
});

View File

@ -1,15 +1,12 @@
const expect = require('expect');
const differenceBy = require('./differenceBy.js');
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), [1.2]).toEqual()
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), [ { x: 2 } ]).toEqual()
expect(differenceBy([{ x: 2 }, { x: 1 }], [{ x: 1 }], v => v.x)).toEqual([ { x: 2 } ]);
});

View File

@ -1,9 +1,9 @@
const expect = require('expect');
const differenceWith = require('./differenceWith.js');
test('differenceWith is a Function', () => {
expect(differenceWith).toBeInstanceOf(Function);
});
t.deepEqual(differenceWith([1, 1.2, 1.5, 3, 0], [1.9, 3, 0], (a, b) => Math.round(a) === Math.round(b)), [1, 1.2], "Filters out all values from an array");
test('Filters out all values from an array', () => {
expect(differenceWith([1, 1.2, 1.5, 3, 0], [1.9, 3, 0], (a, b) => Math.round(a) === Math.round(b))).toEqual([1, 1.2]);
});

View File

@ -1,9 +1,9 @@
const expect = require('expect');
const digitize = require('./digitize.js');
test('digitize is a Function', () => {
expect(digitize).toBeInstanceOf(Function);
});
t.deepEqual(digitize(123), [1, 2, 3], "Converts a number to an array of digits");
test('Converts a number to an array of digits', () => {
expect(digitize(123)).toEqual([1, 2,3])
});

View File

@ -1,12 +1,9 @@
const expect = require('expect');
const distance = require('./distance.js');
test('distance is a Function', () => {
expect(distance).toBeInstanceOf(Function);
});
test('Calculates the distance between two points', () => {
expect(distance(1, 1, 2, 3), 2.23606797749979).toBe()
expect(distance(1, 1, 2, 3)).toBeCloseTo(2.23606797749979, 5);
});

View File

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

View File

@ -1,11 +1,15 @@
const expect = require('expect');
const dropRight = require('./dropRight.js');
test('dropRight is a Function', () => {
expect(dropRight).toBeInstanceOf(Function);
});
t.deepEqual(dropRight([1, 2, 3]), [1,2], "Returns a new array with n elements removed from the right");
t.deepEqual(dropRight([1, 2, 3], 2), [1], "Returns a new array with n elements removed from the right");
t.deepEqual(dropRight([1, 2, 3], 42), [], "Returns a new array with n elements removed from the right");
test('Returns a new array with n elements removed from the right', () => {
expect(dropRight([1, 2, 3])).toEqual([1, 2])
});
test('Returns a new array with n elements removed from the right', () => {
expect(dropRight([1, 2, 3], 2)).toEqual([1]);
});
test('Returns a new array with n elements removed from the right', () => {
expect(dropRight([1, 2, 3], 42)).toEqual([]);
});

View File

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

View File

@ -1,12 +1,9 @@
const expect = require('expect');
const dropWhile = require('./dropWhile.js');
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), [3,4]).toEqual()
expect(dropWhile([1, 2, 3, 4], n => n >= 3)).toEqual([3,4])
});

View File

@ -5,7 +5,11 @@ const elo = require('./elo.js');
test('elo is a Function', () => {
expect(elo).toBeInstanceOf(Function);
});
t.deepEqual(elo([1200, 1200]), [1216, 1184], "Standard 1v1s");
test('Standard 1v1s', () => {
expect(elo([1200, 1200]), [1216).toEqual(1184])
});
t.deepEqual(elo([1200, 1200], 64), [1232, 1168]), "Standard 1v1s";
t.deepEqual(elo([1200, 1200, 1200, 1200]).map(Math.round), [1246, 1215, 1185, 1154], "4 player FFA, all same rank");
test('4 player FFA, all same rank', () => {
expect(elo([1200, 1200, 1200, 1200]).map(Math.round), [1246, 1215, 1185).toEqual(1154])
});

View File

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

View File

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

View File

@ -5,5 +5,7 @@ const escapeRegExp = require('./escapeRegExp.js');
test('escapeRegExp is a Function', () => {
expect(escapeRegExp).toBeInstanceOf(Function);
});
t.equal(escapeRegExp('(test)'), '\\(test\\)', "Escapes a string to use in a regular expression");
test('Escapes a string to use in a regular expression', () => {
expect(escapeRegExp('(test)')).toBe('\\(test\\)')
});

View File

@ -5,5 +5,7 @@ const everyNth = require('./everyNth.js');
test('everyNth is a Function', () => {
expect(everyNth).toBeInstanceOf(Function);
});
t.deepEqual(everyNth([1, 2, 3, 4, 5, 6], 2), [ 2, 4, 6 ], "Returns every nth element in an array");
test('Returns every nth element in an array', () => {
expect(everyNth([1, 2, 3, 4, 5, 6], 2), [ 2, 4).toEqual(6 ])
});

View File

@ -5,6 +5,10 @@ const extendHex = require('./extendHex.js');
test('extendHex is a Function', () => {
expect(extendHex).toBeInstanceOf(Function);
});
t.equal(extendHex('#03f'), '#0033ff', "Extends a 3-digit color code to a 6-digit color code");
t.equal(extendHex('05a'), '#0055aa', "Extends a 3-digit color code to a 6-digit color code");
test('Extends a 3-digit color code to a 6-digit color code', () => {
expect(extendHex('#03f')).toBe('#0033ff')
});
test('Extends a 3-digit color code to a 6-digit color code', () => {
expect(extendHex('05a')).toBe('#0055aa')
});

View File

@ -5,9 +5,19 @@ const factorial = require('./factorial.js');
test('factorial is a Function', () => {
expect(factorial).toBeInstanceOf(Function);
});
t.equal(factorial(6), 720, "Calculates the factorial of 720");
t.equal(factorial(0), 1, "Calculates the factorial of 0");
t.equal(factorial(1), 1, "Calculates the factorial of 1");
t.equal(factorial(4), 24, "Calculates the factorial of 4");
t.equal(factorial(10), 3628800, "Calculates the factorial of 10");
test('Calculates the factorial of 720', () => {
expect(factorial(6)).toBe(720)
});
test('Calculates the factorial of 0', () => {
expect(factorial(0)).toBe(1)
});
test('Calculates the factorial of 1', () => {
expect(factorial(1)).toBe(1)
});
test('Calculates the factorial of 4', () => {
expect(factorial(4)).toBe(24)
});
test('Calculates the factorial of 10', () => {
expect(factorial(10)).toBe(3628800)
});

View File

@ -5,5 +5,7 @@ const fibonacci = require('./fibonacci.js');
test('fibonacci is a Function', () => {
expect(fibonacci).toBeInstanceOf(Function);
});
t.deepEqual(fibonacci(6), [0, 1, 1, 2, 3, 5], "Generates an array, containing the Fibonacci sequence");
test('Generates an array, containing the Fibonacci sequence', () => {
expect(fibonacci(6), [0, 1, 1, 2, 3).toEqual(5])
});

View File

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

View File

@ -5,6 +5,10 @@ const flatten = require('./flatten.js');
test('flatten is a Function', () => {
expect(flatten).toBeInstanceOf(Function);
});
t.deepEqual(flatten([1, [2], 3, 4]), [1, 2, 3, 4], "Flattens an array");
t.deepEqual(flatten([1, [2, [3, [4, 5], 6], 7], 8], 2), [1, 2, 3, [4, 5], 6, 7, 8], "Flattens an array");
test('Flattens an array', () => {
expect(flatten([1, [2], 3, 4]), [1, 2, 3).toEqual(4])
});
test('Flattens an array', () => {
expect(flatten([1, [2, [3, [4, 5], 6], 7], 8], 2), [1, 2, 3, [4, 5], 6, 7).toEqual(8])
});

View File

@ -5,6 +5,10 @@ const formatDuration = require('./formatDuration.js');
test('formatDuration is a Function', () => {
expect(formatDuration).toBeInstanceOf(Function);
});
t.equal(formatDuration(1001), '1 second, 1 millisecond', "Returns the human readable format of the given number of milliseconds");
t.equal(formatDuration(34325055574), '397 days, 6 hours, 44 minutes, 15 seconds, 574 milliseconds', "Returns the human readable format of the given number of milliseconds");
test('Returns the human readable format of the given number of milliseconds', () => {
expect(formatDuration(1001), '1 second).toBe(1 millisecond')
});
test('Returns the human readable format of the given number of milliseconds', () => {
expect(formatDuration(34325055574), '397 days, 6 hours, 44 minutes, 15 seconds).toBe(574 milliseconds')
});

View File

@ -5,7 +5,13 @@ const fromCamelCase = require('./fromCamelCase.js');
test('fromCamelCase is a Function', () => {
expect(fromCamelCase).toBeInstanceOf(Function);
});
t.equal(fromCamelCase('someDatabaseFieldName', ' '), 'some database field name', "Converts a string from camelcase");
t.equal(fromCamelCase('someLabelThatNeedsToBeCamelized', '-'), 'some-label-that-needs-to-be-camelized', "Converts a string from camelcase");
t.equal(fromCamelCase('someJavascriptProperty', '_'), 'some_javascript_property', "Converts a string from camelcase");
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')
});
test('Converts a string from camelcase', () => {
expect(fromCamelCase('someJavascriptProperty', '_')).toBe('some_javascript_property')
});

View File

@ -5,6 +5,10 @@ const gcd = require('./gcd.js');
test('gcd is a Function', () => {
expect(gcd).toBeInstanceOf(Function);
});
t.equal(gcd(8, 36), 4, "Calculates the greatest common divisor between two or more numbers/arrays");
t.deepEqual(gcd(...[12, 8, 32]), 4, "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(8, 36)).toBe(4)
});
test('Calculates the greatest common divisor between two or more numbers/arrays', () => {
expect(gcd(...[12, 8, 32])).toEqual(4)
});

View File

@ -5,7 +5,13 @@ const geometricProgression = require('./geometricProgression.js');
test('geometricProgression is a Function', () => {
expect(geometricProgression).toBeInstanceOf(Function);
});
t.deepEqual(geometricProgression(256), [1, 2, 4, 8, 16, 32, 64, 128, 256], "Initializes an array containing the numbers in the specified range");
t.deepEqual(geometricProgression(256, 3), [3, 6, 12, 24, 48, 96, 192], "Initializes an array containing the numbers in the specified range");
t.deepEqual(geometricProgression(256, 1, 4), [1, 4, 16, 64, 256], "Initializes an array containing the numbers in the specified range");
test('Initializes an array containing the numbers in the specified range', () => {
expect(geometricProgression(256), [1, 2, 4, 8, 16, 32, 64, 128).toEqual(256])
});
test('Initializes an array containing the numbers in the specified range', () => {
expect(geometricProgression(256, 3), [3, 6, 12, 24, 48, 96).toEqual(192])
});
test('Initializes an array containing the numbers in the specified range', () => {
expect(geometricProgression(256, 1, 4), [1, 4, 16, 64).toEqual(256])
});

View File

@ -6,6 +6,8 @@ const get = require('./get.js');
expect(get).toBeInstanceOf(Function);
});
const obj = { selector: { to: { val: 'val to get' } } };
t.deepEqual(get(obj, 'selector.to.val'), ['val to get'], "Retrieve a property indicated by the selector from an object.");
test('Retrieve a property indicated by the selector from an object.', () => {
expect(get(obj, 'selector.to.val')).toEqual(['val to get'])
});

View File

@ -5,5 +5,7 @@ const getDaysDiffBetweenDates = require('./getDaysDiffBetweenDates.js');
test('getDaysDiffBetweenDates is a Function', () => {
expect(getDaysDiffBetweenDates).toBeInstanceOf(Function);
});
t.equal(getDaysDiffBetweenDates(new Date('2017-12-13'), new Date('2017-12-22')), 9, "Returns the difference in days between two dates");
test('Returns the difference in days between two dates', () => {
expect(getDaysDiffBetweenDates(new Date('2017-12-13'), new Date('2017-12-22'))).toBe(9)
});

View File

@ -5,5 +5,7 @@ const getType = require('./getType.js');
test('getType is a Function', () => {
expect(getType).toBeInstanceOf(Function);
});
t.equal(getType(new Set([1, 2, 3])), 'set', "Returns the native type of a value");
test('Returns the native type of a value', () => {
expect(getType(new Set([1, 2, 3]))).toBe('set')
});

View File

@ -5,6 +5,10 @@ const groupBy = require('./groupBy.js');
test('groupBy is a Function', () => {
expect(groupBy).toBeInstanceOf(Function);
});
t.deepEqual(groupBy([6.1, 4.2, 6.3], Math.floor), {4: [4.2], 6: [6.1, 6.3]}, "Groups the elements of an array based on the given function");
t.deepEqual(groupBy(['one', 'two', 'three'], 'length'), {3: ['one', 'two'], 5: ['three']}, "Groups the elements of an array based on the given function");
test('Groups the elements of an array based on the given function', () => {
expect(groupBy([6.1, 4.2, 6.3], Math.floor), {4: [4.2], 6: [6.1).toEqual(6.3]})
});
test('Groups the elements of an array based on the given function', () => {
expect(groupBy(['one', 'two', 'three'], 'length'), {3: ['one', 'two']).toEqual(5: ['three']})
});

View File

@ -5,5 +5,7 @@ const hammingDistance = require('./hammingDistance.js');
test('hammingDistance is a Function', () => {
expect(hammingDistance).toBeInstanceOf(Function);
});
t.equal(hammingDistance(2, 3), 1, "retuns hamming disance between 2 values");
test('retuns hamming disance between 2 values', () => {
expect(hammingDistance(2, 3)).toBe(1)
});

View File

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

View File

@ -5,7 +5,13 @@ const hexToRGB = require('./hexToRGB.js');
test('hexToRGB is a Function', () => {
expect(hexToRGB).toBeInstanceOf(Function);
});
t.equal(hexToRGB('#27ae60ff'), 'rgba(39, 174, 96, 255)', "Converts a color code to a rgb() or rgba() string");
t.equal(hexToRGB('27ae60'), 'rgb(39, 174, 96)', "Converts a color code to a rgb() or rgba() string");
t.equal(hexToRGB('#fff'), 'rgb(255, 255, 255)', "Converts a color code to a rgb() or rgba() string");
test('Converts a color code to a rgb() or rgba() string', () => {
expect(hexToRGB('#27ae60ff'), 'rgba(39, 174, 96).toBe(255)')
});
test('Converts a color code to a rgb() or rgba() string', () => {
expect(hexToRGB('27ae60'), 'rgb(39, 174).toBe(96)')
});
test('Converts a color code to a rgb() or rgba() string', () => {
expect(hexToRGB('#fff'), 'rgb(255, 255).toBe(255)')
});

View File

@ -5,8 +5,16 @@ const inRange = require('./inRange.js');
test('inRange is a Function', () => {
expect(inRange).toBeInstanceOf(Function);
});
t.equal(inRange(3, 2, 5), true, "The given number falls within the given range");
t.equal(inRange(3, 4), true, "The given number falls within the given range");
t.equal(inRange(2, 3, 5), false, "The given number does not falls within the given range");
t.equal(inRange(3, 2), false, "The given number does not falls within the given range");
test('The given number falls within the given range', () => {
expect(inRange(3, 2, 5)).toBe(true)
});
test('The given number falls within the given range', () => {
expect(inRange(3, 4)).toBe(true)
});
test('The given number does not falls within the given range', () => {
expect(inRange(2, 3, 5)).toBe(false)
});
test('The given number does not falls within the given range', () => {
expect(inRange(3, 2)).toBe(false)
});

View File

@ -5,6 +5,10 @@ const indexOfAll = require('./indexOfAll.js');
test('indexOfAll is a Function', () => {
expect(indexOfAll).toBeInstanceOf(Function);
});
t.deepEqual(indexOfAll([1, 2, 3, 1, 2, 3], 1), [0,3], "Returns all indices of val in an array");
t.deepEqual(indexOfAll([1, 2, 3], 4), [], "Returns all indices of val in an array");
test('Returns all indices of val in an array', () => {
expect(indexOfAll([1, 2, 3, 1, 2, 3], 1), [0).toEqual(3])
});
test('Returns all indices of val in an array', () => {
expect(indexOfAll([1, 2, 3], 4)).toEqual([])
});

View File

@ -5,5 +5,7 @@ const initial = require('./initial.js');
test('initial is a Function', () => {
expect(initial).toBeInstanceOf(Function);
});
t.deepEqual(initial([1, 2, 3]), [1, 2], "Returns all the elements of an array except the last one");
test('Returns all the elements of an array except the last one', () => {
expect(initial([1, 2, 3]), [1).toEqual(2])
});

View File

@ -5,5 +5,7 @@ const initialize2DArray = require('./initialize2DArray.js');
test('initialize2DArray is a Function', () => {
expect(initialize2DArray).toBeInstanceOf(Function);
});
t.deepEqual(initialize2DArray(2, 2, 0), [[0,0], [0,0]], "Initializes a 2D array of given width and height and value");
test('Initializes a 2D array of given width and height and value', () => {
expect(initialize2DArray(2, 2, 0), [[0,0], [0).toEqual(0]])
});

View File

@ -5,5 +5,7 @@ const initializeArrayWithRange = require('./initializeArrayWithRange.js');
test('initializeArrayWithRange is a Function', () => {
expect(initializeArrayWithRange).toBeInstanceOf(Function);
});
t.deepEqual(initializeArrayWithRange(5), [0, 1, 2, 3, 4, 5], "Initializes an array containing the numbers in the specified range");
test('Initializes an array containing the numbers in the specified range', () => {
expect(initializeArrayWithRange(5), [0, 1, 2, 3, 4).toEqual(5])
});

View File

@ -5,5 +5,7 @@ const initializeArrayWithValues = require('./initializeArrayWithValues.js');
test('initializeArrayWithValues is a Function', () => {
expect(initializeArrayWithValues).toBeInstanceOf(Function);
});
t.deepEqual(initializeArrayWithValues(5, 2), [2, 2, 2, 2, 2], "Initializes and fills an array with the specified values");
test('Initializes and fills an array with the specified values', () => {
expect(initializeArrayWithValues(5, 2), [2, 2, 2, 2).toEqual(2])
});

View File

@ -5,5 +5,7 @@ const intersection = require('./intersection.js');
test('intersection is a Function', () => {
expect(intersection).toBeInstanceOf(Function);
});
t.deepEqual(intersection([1, 2, 3], [4, 3, 2]), [2, 3], "Returns a list of elements that exist in both arrays");
test('Returns a list of elements that exist in both arrays', () => {
expect(intersection([1, 2, 3], [4, 3, 2]), [2).toEqual(3])
});

View File

@ -5,6 +5,10 @@ const invertKeyValues = require('./invertKeyValues.js');
test('invertKeyValues is a Function', () => {
expect(invertKeyValues).toBeInstanceOf(Function);
});
t.deepEqual(invertKeyValues({ a: 1, b: 2, c: 1 }), { 1: [ 'a', 'c' ], 2: [ 'b' ] }, "invertKeyValues({ a: 1, b: 2, c: 1 }) returns { 1: [ 'a', 'c' ], 2: [ 'b' ] }");
t.deepEqual(invertKeyValues({ a: 1, b: 2, c: 1 }, value => 'group' + value), { group1: [ 'a', 'c' ], group2: [ 'b' ] }, "invertKeyValues({ a: 1, b: 2, c: 1 }, value => 'group' + value) returns { group1: [ 'a', 'c' ], group2: [ 'b' ] }");
test('invertKeyValues({ a: 1, b: 2, c: 1 }) returns { 1: [ 'a', 'c' ], 2: [ 'b' ] }', () => {
expect(invertKeyValues({ a: 1, b: 2, c: 1 }), { 1: [ 'a', 'c' ]).toEqual(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), { group1: [ 'a', 'c' ]).toEqual(group2: [ 'b' ] })
});

View File

@ -7,5 +7,7 @@ const isAbsoluteURL = require('./isAbsoluteURL.js');
});
t.equal(isAbsoluteURL('https:
t.equal(isAbsoluteURL('ftp:
t.equal(isAbsoluteURL('/foo/bar'), false, "Given string is not an absolute URL");
test('Given string is not an absolute URL', () => {
expect(isAbsoluteURL('/foo/bar')).toBe(false)
});

View File

@ -5,6 +5,10 @@ const isArray = require('./isArray.js');
test('isArray is a Function', () => {
expect(isArray).toBeInstanceOf(Function);
});
t.equal(isArray([1]), true, "passed value is an array");
t.equal(isArray('array'), false, "passed value is not an array");
test('passed value is an array', () => {
expect(isArray([1])).toBe(true)
});
test('passed value is not an array', () => {
expect(isArray('array')).toBe(false)
});

View File

@ -5,6 +5,10 @@ const isBoolean = require('./isBoolean.js');
test('isBoolean is a Function', () => {
expect(isBoolean).toBeInstanceOf(Function);
});
t.equal(isBoolean(null), false, "passed value is not a boolean");
t.equal(isBoolean(false), true, "passed value is not a boolean");
test('passed value is not a boolean', () => {
expect(isBoolean(null)).toBe(false)
});
test('passed value is not a boolean', () => {
expect(isBoolean(false)).toBe(true)
});

View File

@ -5,6 +5,10 @@ const isFunction = require('./isFunction.js');
test('isFunction is a Function', () => {
expect(isFunction).toBeInstanceOf(Function);
});
t.equal(isFunction(x => x), true, "passed value is a function");
t.equal(isFunction('x'), false, "passed value is not a function");
test('passed value is a function', () => {
expect(isFunction(x => x)).toBe(true)
});
test('passed value is not a function', () => {
expect(isFunction('x')).toBe(false)
});

View File

@ -5,7 +5,13 @@ const isLowerCase = require('./isLowerCase.js');
test('isLowerCase is a Function', () => {
expect(isLowerCase).toBeInstanceOf(Function);
});
t.equal(isLowerCase('abc'), true, "passed string is a lowercase");
t.equal(isLowerCase('a3@$'), true, "passed string is a lowercase");
t.equal(isLowerCase('A3@$'), false, "passed value is not a lowercase");
test('passed string is a lowercase', () => {
expect(isLowerCase('abc')).toBe(true)
});
test('passed string is a lowercase', () => {
expect(isLowerCase('a3@$')).toBe(true)
});
test('passed value is not a lowercase', () => {
expect(isLowerCase('A3@$')).toBe(false)
});

View File

@ -5,6 +5,10 @@ const isNull = require('./isNull.js');
test('isNull is a Function', () => {
expect(isNull).toBeInstanceOf(Function);
});
t.equal(isNull(null), true, "passed argument is a null");
t.equal(isNull(NaN), false, "passed argument is a null");
test('passed argument is a null', () => {
expect(isNull(null)).toBe(true)
});
test('passed argument is a null', () => {
expect(isNull(NaN)).toBe(false)
});

View File

@ -5,6 +5,10 @@ const isNumber = require('./isNumber.js');
test('isNumber is a Function', () => {
expect(isNumber).toBeInstanceOf(Function);
});
t.equal(isNumber(1), true, "passed argument is a number");
t.equal(isNumber('1'), false, "passed argument is not a number");
test('passed argument is a number', () => {
expect(isNumber(1)).toBe(true)
});
test('passed argument is not a number', () => {
expect(isNumber('1')).toBe(false)
});

View File

@ -5,5 +5,7 @@ const isPrime = require('./isPrime.js');
test('isPrime is a Function', () => {
expect(isPrime).toBeInstanceOf(Function);
});
t.equal(isPrime(11), true, "passed number is a prime");
test('passed number is a prime', () => {
expect(isPrime(11)).toBe(true)
});

View File

@ -5,16 +5,36 @@ const isPrimitive = require('./isPrimitive.js');
test('isPrimitive is a Function', () => {
expect(isPrimitive).toBeInstanceOf(Function);
});
t.true(isPrimitive(null), "isPrimitive(null) is primitive");
t.true(isPrimitive(undefined), "isPrimitive(undefined) is primitive");
t.true(isPrimitive('string'), "isPrimitive(string) is primitive");
t.true(isPrimitive(true), "isPrimitive(true) is primitive");
t.true(isPrimitive(50), "isPrimitive(50) is primitive");
t.true(isPrimitive('Hello'), "isPrimitive('Hello') is primitive");
t.true(isPrimitive(false), "isPrimitive(false) is primitive");
t.true(isPrimitive(Symbol()), "isPrimitive(Symbol()) is primitive");
t.false(isPrimitive([1, 2, 3]), "isPrimitive([1, 2, 3]) is not primitive");
t.false(isPrimitive({ a: 123 }), "isPrimitive({ a: 123 }) is not primitive");
test('isPrimitive(null) is primitive', () => {
expect(isPrimitive(null)).toBeTruthy()
});
test('isPrimitive(undefined) is primitive', () => {
expect(isPrimitive(undefined)).toBeTruthy()
});
test('isPrimitive(string) is primitive', () => {
expect(isPrimitive('string')).toBeTruthy()
});
test('isPrimitive(true) is primitive', () => {
expect(isPrimitive(true)).toBeTruthy()
});
test('isPrimitive(50) is primitive', () => {
expect(isPrimitive(50)).toBeTruthy()
});
test('isPrimitive('Hello') is primitive', () => {
expect(isPrimitive('Hello')).toBeTruthy()
});
test('isPrimitive(false) is primitive', () => {
expect(isPrimitive(false)).toBeTruthy()
});
test('isPrimitive(Symbol()) is primitive', () => {
expect(isPrimitive(Symbol())).toBeTruthy()
});
test('isPrimitive([1, 2, 3]) is not primitive', () => {
expect(isPrimitive([1, 2, 3])).toBeFalsy()
});
test('isPrimitive({ a: 123 }) is not primitive', () => {
expect(isPrimitive({ a: 123 })).toBeFalsy()
});
let start = new Date().getTime();
isPrimitive({ a: 123

View File

@ -5,5 +5,7 @@ const isSymbol = require('./isSymbol.js');
test('isSymbol is a Function', () => {
expect(isSymbol).toBeInstanceOf(Function);
});
t.equal(isSymbol(Symbol('x')), true, "Checks if the given argument is a symbol");
test('Checks if the given argument is a symbol', () => {
expect(isSymbol(Symbol('x'))).toBe(true)
});

View File

@ -5,7 +5,13 @@ const join = require('./join.js');
test('join is a Function', () => {
expect(join).toBeInstanceOf(Function);
});
t.deepEqual(join(['pen', 'pineapple', 'apple', 'pen'], ',', '&'), "pen,pineapple,apple&pen", "Joins all elements of an array into a string and returns this string");
t.deepEqual(join(['pen', 'pineapple', 'apple', 'pen'], ','), "pen,pineapple,apple,pen", "Joins all elements of an array into a string and returns this string");
t.deepEqual(join(['pen', 'pineapple', 'apple', 'pen']), "pen,pineapple,apple,pen", "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'], ',', '&'), "pen,pineapple).toEqual(apple&pen")
});
test('Joins all elements of an array into a string and returns this string', () => {
expect(join(['pen', 'pineapple', 'apple', 'pen'], ','), "pen,pineapple,apple).toEqual(pen")
});
test('Joins all elements of an array into a string and returns this string', () => {
expect(join(['pen', 'pineapple', 'apple', 'pen']), "pen,pineapple,apple).toEqual(pen")
});

View File

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

View File

@ -5,6 +5,10 @@ const lcm = require('./lcm.js');
test('lcm is a Function', () => {
expect(lcm).toBeInstanceOf(Function);
});
t.equal(lcm(12, 7), 84, "Returns the least common multiple of two or more numbers.");
t.equal(lcm(...[1, 3, 4, 5]), 60, "Returns the least common multiple of two or more numbers.");
test('Returns the least common multiple of two or more numbers.', () => {
expect(lcm(12, 7)).toBe(84)
});
test('Returns the least common multiple of two or more numbers.', () => {
expect(lcm(...[1, 3, 4, 5])).toBe(60)
});

View File

@ -5,5 +5,7 @@ const longestItem = require('./longestItem.js');
test('longestItem is a Function', () => {
expect(longestItem).toBeInstanceOf(Function);
});
t.deepEqual(longestItem('this', 'is', 'a', 'testcase'), 'testcase', "Returns the longest object");
test('Returns the longest object', () => {
expect(longestItem('this', 'is', 'a', 'testcase')).toEqual('testcase')
});

View File

@ -5,7 +5,13 @@ const luhnCheck = require('./luhnCheck.js');
test('luhnCheck is a Function', () => {
expect(luhnCheck).toBeInstanceOf(Function);
});
t.equal(luhnCheck(6011329933655299), false, "validates identification number");
t.equal(luhnCheck('4485275742308327'), true, "validates identification number");
t.equal(luhnCheck(123456789), false, "validates identification number");
test('validates identification number', () => {
expect(luhnCheck(6011329933655299)).toBe(false)
});
test('validates identification number', () => {
expect(luhnCheck('4485275742308327')).toBe(true)
});
test('validates identification number', () => {
expect(luhnCheck(123456789)).toBe(false)
});

View File

@ -5,7 +5,9 @@ const mapObject = require('./mapObject.js');
test('mapObject is a Function', () => {
expect(mapObject).toBeInstanceOf(Function);
});
t.deepEqual(mapObject([1, 2, 3], a => a * a), { 1: 1, 2: 4, 3: 9 }, "mapObject([1, 2, 3], a => a * a) returns { 1: 1, 2: 4, 3: 9 }");
test('mapObject([1, 2, 3], a => a * a) returns { 1: 1, 2: 4, 3: 9 }', () => {
expect(mapObject([1, 2, 3], a => a * a), { 1: 1, 2: 4).toEqual(3: 9 })
});
test('mapObject([1, 2, 3, 4], (a, b) => b - a) returns { 1: -1, 2: -1, 3: -1, 4: -1 }', () => {
expect(mapObject([1, 2, 3, 4], (a, b) => b - a), { 1: -1, 2: -1, 3: -1, 4: -1 }).toEqual()
});

View File

@ -5,7 +5,13 @@ const mask = require('./mask.js');
test('mask is a Function', () => {
expect(mask).toBeInstanceOf(Function);
});
t.equal(mask(1234567890), '******7890', "Replaces all but the last num of characters with the specified mask character");
t.equal(mask(1234567890, 3), '*******890', "Replaces all but the last num of characters with the specified mask character");
t.equal(mask(1234567890, -4, '$'), '$$$$567890', "Replaces all but the last num of characters with the specified mask character");
test('Replaces all but the last num of characters with the specified mask character', () => {
expect(mask(1234567890)).toBe('******7890')
});
test('Replaces all but the last num of characters with the specified mask character', () => {
expect(mask(1234567890, 3)).toBe('*******890')
});
test('Replaces all but the last num of characters with the specified mask character', () => {
expect(mask(1234567890, -4, '$')).toBe('$$$$567890')
});

View File

@ -5,6 +5,10 @@ const maxN = require('./maxN.js');
test('maxN is a Function', () => {
expect(maxN).toBeInstanceOf(Function);
});
t.deepEqual(maxN([1, 2, 3]), [3], "Returns the n maximum elements from the provided array");
t.deepEqual(maxN([1, 2, 3], 2), [3, 2], "Returns the n maximum elements from the provided array");
test('Returns the n maximum elements from the provided array', () => {
expect(maxN([1, 2, 3])).toEqual([3])
});
test('Returns the n maximum elements from the provided array', () => {
expect(maxN([1, 2, 3], 2), [3).toEqual(2])
});

View File

@ -5,6 +5,10 @@ const median = require('./median.js');
test('median is a Function', () => {
expect(median).toBeInstanceOf(Function);
});
t.equal(median([5, 6, 50, 1, -5]), 5, "Returns the median of an array of numbers");
t.equal(median([1, 2, 3]), 2, "Returns the median of an array of numbers");
test('Returns the median of an array of numbers', () => {
expect(median([5, 6, 50, 1, -5])).toBe(5)
});
test('Returns the median of an array of numbers', () => {
expect(median([1, 2, 3])).toBe(2)
});

View File

@ -5,6 +5,10 @@ const minN = require('./minN.js');
test('minN is a Function', () => {
expect(minN).toBeInstanceOf(Function);
});
t.deepEqual(minN([1, 2, 3]), [1], "Returns the n minimum elements from the provided array");
t.deepEqual(minN([1, 2, 3], 2), [1, 2], "Returns the n minimum elements from the provided array");
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), [1).toEqual(2])
});

View File

@ -5,6 +5,8 @@ const negate = require('./negate.js');
test('negate is a Function', () => {
expect(negate).toBeInstanceOf(Function);
});
t.deepEqual([1, 2, 3, 4, 5, 6].filter(negate(n => n % 2 === 0)), [1, 3, 5], "Negates a predicate function");
test('Negates a predicate function', () => {
expect([1, 2, 3, 4, 5, 6].filter(negate(n => n % 2 === 0)), [1, 3).toEqual(5])
});

View File

@ -5,6 +5,10 @@ const nthElement = require('./nthElement.js');
test('nthElement is a Function', () => {
expect(nthElement).toBeInstanceOf(Function);
});
t.equal(nthElement(['a', 'b', 'c'], 1), 'b', "Returns the nth element of an array.");
t.equal(nthElement(['a', 'b', 'c'], -3), 'a', "Returns the nth element of an array.");
test('Returns the nth element of an array.', () => {
expect(nthElement(['a', 'b', 'c'], 1)).toBe('b')
});
test('Returns the nth element of an array.', () => {
expect(nthElement(['a', 'b', 'c'], -3)).toBe('a')
});

View File

@ -5,5 +5,7 @@ const objectFromPairs = require('./objectFromPairs.js');
test('objectFromPairs is a Function', () => {
expect(objectFromPairs).toBeInstanceOf(Function);
});
t.deepEqual(objectFromPairs([['a', 1], ['b', 2]]), {a: 1, b: 2}, "Creates an object from the given key-value pairs.");
test('Creates an object from the given key-value pairs.', () => {
expect(objectFromPairs([['a', 1], ['b', 2]]), {a: 1).toEqual(b: 2})
});

View File

@ -5,5 +5,7 @@ const objectToPairs = require('./objectToPairs.js');
test('objectToPairs is a Function', () => {
expect(objectToPairs).toBeInstanceOf(Function);
});
t.deepEqual(objectToPairs({ a: 1, b: 2 }), [['a',1],['b',2]], "Creates an array of key-value pair arrays from an object.");
test('Creates an array of key-value pair arrays from an object.', () => {
expect(objectToPairs({ a: 1, b: 2 }), [['a',1],['b').toEqual(2]])
});

View File

@ -6,6 +6,10 @@ const orderBy = require('./orderBy.js');
expect(orderBy).toBeInstanceOf(Function);
});
const users = [{ name: 'fred', age: 48 }, { name: 'barney', age: 36 }, { name: 'fred', age: 40 }];
t.deepEqual(orderBy(users, ['name', 'age'], ['asc', 'desc']), [{name: 'barney', age: 36}, {name: 'fred', age: 48}, {name: 'fred', age: 40}], "Returns a sorted array of objects ordered by properties and orders.");
t.deepEqual(orderBy(users, ['name', 'age']), [{name: 'barney', age: 36}, {name: 'fred', age: 40}, {name: 'fred', age: 48}], "Returns a sorted array of objects ordered by properties and orders.");
test('Returns a sorted array of objects ordered by properties and orders.', () => {
expect(orderBy(users, ['name', 'age'], ['asc', 'desc']), [{name: 'barney', age: 36}, {name: 'fred', age: 48}, {name: 'fred').toEqual(age: 40}])
});
test('Returns a sorted array of objects ordered by properties and orders.', () => {
expect(orderBy(users, ['name', 'age']), [{name: 'barney', age: 36}, {name: 'fred', age: 40}, {name: 'fred').toEqual(age: 48}])
});

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