Test cleanup and fixes [q-r]
This commit is contained in:
@ -1,11 +1,9 @@
|
|||||||
const expect = require('expect');
|
const expect = require('expect');
|
||||||
const RGBToHex = require('./RGBToHex.js');
|
const RGBToHex = require('./RGBToHex.js');
|
||||||
|
|
||||||
|
test('RGBToHex is a Function', () => {
|
||||||
test('RGBToHex is a Function', () => {
|
|
||||||
expect(RGBToHex).toBeInstanceOf(Function);
|
expect(RGBToHex).toBeInstanceOf(Function);
|
||||||
});
|
});
|
||||||
test('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')
|
expect(RGBToHex(255, 165, 1)).toBe('ffa501');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -1,28 +1,33 @@
|
|||||||
const expect = require('expect');
|
const expect = require('expect');
|
||||||
const quickSort = require('./quickSort.js');
|
const quickSort = require('./quickSort.js');
|
||||||
|
|
||||||
|
test('quickSort is a Function', () => {
|
||||||
test('quickSort is a Function', () => {
|
|
||||||
expect(quickSort).toBeInstanceOf(Function);
|
expect(quickSort).toBeInstanceOf(Function);
|
||||||
});
|
});
|
||||||
test('quickSort([5, 6, 4, 3, 1, 2]) returns [1, 2, 3, 4, 5, 6]', () => {
|
test('quickSort([5, 6, 4, 3, 1, 2]) returns [1, 2, 3, 4, 5, 6]', () => {
|
||||||
expect(quickSort([5, 6, 4, 3, 1, 2]), [1, 2, 3, 4, 5, 6]).toEqual()
|
expect(quickSort([5, 6, 4, 3, 1, 2])).toEqual([1, 2, 3, 4, 5, 6]);
|
||||||
});
|
});
|
||||||
test('quickSort([-1, 0, -2]) returns [-2, -1, 0]', () => {
|
test('quickSort([-1, 0, -2]) returns [-2, -1, 0]', () => {
|
||||||
expect(quickSort([-1, 0, -2]), [-2, -1, 0]).toEqual()
|
expect(quickSort([-1, 0, -2])).toEqual([-2, -1, 0]);
|
||||||
});
|
});
|
||||||
t.throws(() => quickSort(), 'quickSort() throws an error');
|
test('quickSort() throws an error', () => {
|
||||||
t.throws(() => quickSort(123), 'quickSort(123) throws an error');
|
expect(quickSort()).toThrow();
|
||||||
t.throws(() => quickSort({ 234: string}), 'quickSort({ 234: string}) throws an error');
|
});
|
||||||
t.throws(() => quickSort(null), 'quickSort(null) throws an error');
|
test('quickSort(123) throws an error', () => {
|
||||||
t.throws(() => quickSort(undefined), 'quickSort(undefined) throws an error');
|
expect(quickSort(123)).toThrow();
|
||||||
|
});
|
||||||
let start = new Date().getTime();
|
test('quickSort({ 234: string}) throws an error', () => {
|
||||||
quickSort([11, 1, 324, 23232, -1, 53, 2, 524, 32, 13, 156, 133, 62, 12, 4]);
|
expect(quickSort({ 234: string})).toThrow();
|
||||||
let end = new Date().getTime();
|
});
|
||||||
test('quickSort([11, 1, 324, 23232, -1, 53, 2, 524, 32, 13, 156, 133, 62, 12, 4]) takes less than 2s to run', () => {
|
test('quickSort(null) throws an error', () => {
|
||||||
|
expect(quickSort(null)).toThrow();
|
||||||
|
});
|
||||||
|
test('quickSort(undefined) throws an error', () => {
|
||||||
|
expect(quickSort(undefined)).toThrow();
|
||||||
|
});
|
||||||
|
let start = new Date().getTime();
|
||||||
|
quickSort([11, 1, 324, 23232, -1, 53, 2, 524, 32, 13, 156, 133, 62, 12, 4]);
|
||||||
|
let end = new Date().getTime();
|
||||||
|
test('quickSort([11, 1, 324, 23232, -1, 53, 2, 524, 32, 13, 156, 133, 62, 12, 4]) takes less than 2s to run', () => {
|
||||||
expect((end - start) < 2000).toBeTruthy();
|
expect((end - start) < 2000).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1,12 +1,9 @@
|
|||||||
const expect = require('expect');
|
const expect = require('expect');
|
||||||
const radsToDegrees = require('./radsToDegrees.js');
|
const radsToDegrees = require('./radsToDegrees.js');
|
||||||
|
|
||||||
|
test('radsToDegrees is a Function', () => {
|
||||||
test('radsToDegrees is a Function', () => {
|
|
||||||
expect(radsToDegrees).toBeInstanceOf(Function);
|
expect(radsToDegrees).toBeInstanceOf(Function);
|
||||||
});
|
});
|
||||||
test('Returns the appropriate value', () => {
|
test('Returns the appropriate value', () => {
|
||||||
expect(radsToDegrees(Math.PI / 2), 90).toBe()
|
expect(radsToDegrees(Math.PI / 2)).toBe(90);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1,16 +1,15 @@
|
|||||||
const expect = require('expect');
|
const expect = require('expect');
|
||||||
const randomHexColorCode = require('./randomHexColorCode.js');
|
const randomHexColorCode = require('./randomHexColorCode.js');
|
||||||
|
|
||||||
|
test('randomHexColorCode is a Function', () => {
|
||||||
test('randomHexColorCode is a Function', () => {
|
|
||||||
expect(randomHexColorCode).toBeInstanceOf(Function);
|
expect(randomHexColorCode).toBeInstanceOf(Function);
|
||||||
});
|
});
|
||||||
t.equal(randomHexColorCode().length, 7);
|
test('randomHexColorCode has to proper length', () => {
|
||||||
test('The color code starts with "#"', () => {
|
expect(randomHexColorCode().length).toBe(7);
|
||||||
|
})
|
||||||
|
test('The color code starts with "#"', () => {
|
||||||
expect(randomHexColorCode().startsWith('#')).toBeTruthy();
|
expect(randomHexColorCode().startsWith('#')).toBeTruthy();
|
||||||
});
|
});
|
||||||
test('The color code contains only valid hex-digits', () => {
|
test('The color code contains only valid hex-digits', () => {
|
||||||
expect(randomHexColorCode().slice(1).match(/[^0123456789abcdef]/i) === null).toBeTruthy();
|
expect(randomHexColorCode().slice(1).match(/[^0123456789abcdef]/i) === null).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1,21 +1,18 @@
|
|||||||
const expect = require('expect');
|
const expect = require('expect');
|
||||||
const randomIntArrayInRange = require('./randomIntArrayInRange.js');
|
const randomIntArrayInRange = require('./randomIntArrayInRange.js');
|
||||||
|
|
||||||
|
test('randomIntArrayInRange is a Function', () => {
|
||||||
test('randomIntArrayInRange is a Function', () => {
|
|
||||||
expect(randomIntArrayInRange).toBeInstanceOf(Function);
|
expect(randomIntArrayInRange).toBeInstanceOf(Function);
|
||||||
});
|
});
|
||||||
const lowerLimit = Math.floor(Math.random() * 20);
|
const lowerLimit = Math.floor(Math.random() * 20);
|
||||||
const upperLimit = Math.floor(lowerLimit + Math.random() * 10);
|
const upperLimit = Math.floor(lowerLimit + Math.random() * 10);
|
||||||
const arr = randomIntArrayInRange(lowerLimit,upperLimit, 10);
|
const arr = randomIntArrayInRange(lowerLimit,upperLimit, 10);
|
||||||
test('The returned array contains only integers', () => {
|
test('The returned array contains only integers', () => {
|
||||||
expect(arr.every(x => typeof x === 'number')).toBeTruthy();
|
expect(arr.every(x => typeof x === 'number')).toBeTruthy();
|
||||||
});
|
});
|
||||||
test('The returned array has the proper length', () => {
|
test('The returned array has the proper length', () => {
|
||||||
expect(arr.length, 10).toBe()
|
expect(arr.length).toBe(10);
|
||||||
});
|
});
|
||||||
test('The returned array\'s values lie between provided lowerLimit and upperLimit (both inclusive).', () => {
|
test('The returned array\'s values lie between provided lowerLimit and upperLimit (both inclusive).', () => {
|
||||||
expect(arr.every(x => (x >= lowerLimit) && (x <= upperLimit))).toBeTruthy();
|
expect(arr.every(x => (x >= lowerLimit) && (x <= upperLimit))).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1,18 +1,15 @@
|
|||||||
const expect = require('expect');
|
const expect = require('expect');
|
||||||
const randomIntegerInRange = require('./randomIntegerInRange.js');
|
const randomIntegerInRange = require('./randomIntegerInRange.js');
|
||||||
|
|
||||||
|
test('randomIntegerInRange is a Function', () => {
|
||||||
test('randomIntegerInRange is a Function', () => {
|
|
||||||
expect(randomIntegerInRange).toBeInstanceOf(Function);
|
expect(randomIntegerInRange).toBeInstanceOf(Function);
|
||||||
});
|
});
|
||||||
const lowerLimit = Math.floor(Math.random() * 20);
|
const lowerLimit = Math.floor(Math.random() * 20);
|
||||||
const upperLimit = Math.floor(lowerLimit + Math.random() * 10);
|
const upperLimit = Math.floor(lowerLimit + Math.random() * 10);
|
||||||
test('The returned value is an integer', () => {
|
test('The returned value is an integer', () => {
|
||||||
expect(Number.isInteger(randomIntegerInRange(lowerLimit,upperLimit))).toBeTruthy();
|
expect(Number.isInteger(randomIntegerInRange(lowerLimit,upperLimit))).toBeTruthy();
|
||||||
});
|
});
|
||||||
const numberForTest = randomIntegerInRange(lowerLimit,upperLimit);
|
const numberForTest = randomIntegerInRange(lowerLimit,upperLimit);
|
||||||
test('The returned value lies between provided lowerLimit and upperLimit (both inclusive).', () => {
|
test('The returned value lies between provided lowerLimit and upperLimit (both inclusive).', () => {
|
||||||
expect((numberForTest >= lowerLimit) && (numberForTest <= upperLimit)).toBeTruthy();
|
expect((numberForTest >= lowerLimit) && (numberForTest <= upperLimit)).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1,18 +1,15 @@
|
|||||||
const expect = require('expect');
|
const expect = require('expect');
|
||||||
const randomNumberInRange = require('./randomNumberInRange.js');
|
const randomNumberInRange = require('./randomNumberInRange.js');
|
||||||
|
|
||||||
|
test('randomNumberInRange is a Function', () => {
|
||||||
test('randomNumberInRange is a Function', () => {
|
|
||||||
expect(randomNumberInRange).toBeInstanceOf(Function);
|
expect(randomNumberInRange).toBeInstanceOf(Function);
|
||||||
});
|
});
|
||||||
const lowerLimit = Math.floor(Math.random() * 20);
|
const lowerLimit = Math.floor(Math.random() * 20);
|
||||||
const upperLimit = Math.floor(lowerLimit + Math.random() * 10);
|
const upperLimit = Math.floor(lowerLimit + Math.random() * 10);
|
||||||
test('The returned value is a number', () => {
|
test('The returned value is a number', () => {
|
||||||
expect(typeof randomNumberInRange(lowerLimit,upperLimit) === 'number').toBeTruthy();
|
expect(typeof randomNumberInRange(lowerLimit,upperLimit) === 'number').toBeTruthy();
|
||||||
});
|
});
|
||||||
const numberForTest = randomNumberInRange(lowerLimit,upperLimit);
|
const numberForTest = randomNumberInRange(lowerLimit,upperLimit);
|
||||||
test('The returned value lies between provided lowerLimit and upperLimit (both inclusive).', () => {
|
test('The returned value lies between provided lowerLimit and upperLimit (both inclusive).', () => {
|
||||||
expect((numberForTest >= lowerLimit) && (numberForTest <= upperLimit)).toBeTruthy();
|
expect((numberForTest >= lowerLimit) && (numberForTest <= upperLimit)).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1,10 +1,6 @@
|
|||||||
const expect = require('expect');
|
const expect = require('expect');
|
||||||
const readFileLines = require('./readFileLines.js');
|
const readFileLines = require('./readFileLines.js');
|
||||||
|
|
||||||
|
test('readFileLines is a Function', () => {
|
||||||
test('readFileLines is a Function', () => {
|
|
||||||
expect(readFileLines).toBeInstanceOf(Function);
|
expect(readFileLines).toBeInstanceOf(Function);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1,18 +1,15 @@
|
|||||||
const expect = require('expect');
|
const expect = require('expect');
|
||||||
const rearg = require('./rearg.js');
|
const rearg = require('./rearg.js');
|
||||||
|
|
||||||
|
test('rearg is a Function', () => {
|
||||||
test('rearg is a Function', () => {
|
|
||||||
expect(rearg).toBeInstanceOf(Function);
|
expect(rearg).toBeInstanceOf(Function);
|
||||||
});
|
});
|
||||||
var rearged = rearg(
|
var rearged = rearg(
|
||||||
function(a, b, c) {
|
function(a, b, c) {
|
||||||
return [a, b, c];
|
return [a, b, c];
|
||||||
},
|
},
|
||||||
[2, 0, 1]
|
[2, 0, 1]
|
||||||
);
|
);
|
||||||
test('Reorders arguments in invoked function', () => {
|
test('Reorders arguments in invoked function', () => {
|
||||||
expect(rearged('b', 'c', 'a'), ['a', 'b', 'c']).toEqual()
|
expect(rearged('b', 'c', 'a')).toEqual(['a', 'b', 'c']);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1,8 +1,6 @@
|
|||||||
const expect = require('expect');
|
const expect = require('expect');
|
||||||
const recordAnimationFrames = require('./recordAnimationFrames.js');
|
const recordAnimationFrames = require('./recordAnimationFrames.js');
|
||||||
|
|
||||||
|
test('recordAnimationFrames is a Function', () => {
|
||||||
test('recordAnimationFrames is a Function', () => {
|
|
||||||
expect(recordAnimationFrames).toBeInstanceOf(Function);
|
expect(recordAnimationFrames).toBeInstanceOf(Function);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -1,10 +1,6 @@
|
|||||||
const expect = require('expect');
|
const expect = require('expect');
|
||||||
const redirect = require('./redirect.js');
|
const redirect = require('./redirect.js');
|
||||||
|
|
||||||
|
test('redirect is a Function', () => {
|
||||||
test('redirect is a Function', () => {
|
|
||||||
expect(redirect).toBeInstanceOf(Function);
|
expect(redirect).toBeInstanceOf(Function);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1,12 +1,9 @@
|
|||||||
const expect = require('expect');
|
const expect = require('expect');
|
||||||
const reduceSuccessive = require('./reduceSuccessive.js');
|
const reduceSuccessive = require('./reduceSuccessive.js');
|
||||||
|
|
||||||
|
test('reduceSuccessive is a Function', () => {
|
||||||
test('reduceSuccessive is a Function', () => {
|
|
||||||
expect(reduceSuccessive).toBeInstanceOf(Function);
|
expect(reduceSuccessive).toBeInstanceOf(Function);
|
||||||
});
|
});
|
||||||
test('Returns the array of successively reduced values', () => {
|
test('Returns the array of successively reduced values', () => {
|
||||||
expect(reduceSuccessive([1, 2, 3, 4, 5, 6], (acc, val) => acc + val, 0), [0, 1, 3, 6, 10, 15, 21]).toEqual()
|
expect(reduceSuccessive([1, 2, 3, 4, 5, 6], (acc, val) => acc + val, 0)).toEqual([0, 1, 3, 6, 10, 15, 21]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1,19 +1,18 @@
|
|||||||
const expect = require('expect');
|
const expect = require('expect');
|
||||||
const reduceWhich = require('./reduceWhich.js');
|
const reduceWhich = require('./reduceWhich.js');
|
||||||
|
|
||||||
|
test('reduceWhich is a Function', () => {
|
||||||
test('reduceWhich is a Function', () => {
|
|
||||||
expect(reduceWhich).toBeInstanceOf(Function);
|
expect(reduceWhich).toBeInstanceOf(Function);
|
||||||
});
|
});
|
||||||
test('Returns the minimum of an array', () => {
|
test('Returns the minimum of an array', () => {
|
||||||
expect(reduceWhich([1, 3, 2]), 1).toBe()
|
expect(reduceWhich([1, 3, 2])).toBe(1);
|
||||||
});
|
});
|
||||||
test('Returns the maximum of an array', () => {
|
test('Returns the maximum of an array', () => {
|
||||||
expect(reduceWhich([1, 3, 2], (a, b) => b - a), 3).toBe()
|
expect(reduceWhich([1, 3, 2], (a, b) => b - a)).toBe(3);
|
||||||
});
|
});
|
||||||
t.deepEqual(reduceWhich(
|
test('Returns the object with the minimum specified value in an array', () => {
|
||||||
|
expect(reduceWhich(
|
||||||
[{ name: 'Tom', age: 12 }, { name: 'Jack', age: 18 }, { name: 'Lucy', age: 9 }],
|
[{ name: 'Tom', age: 12 }, { name: 'Jack', age: 18 }, { name: 'Lucy', age: 9 }],
|
||||||
(a, b) => a.age - b.age
|
(a, b) => a.age - b.age
|
||||||
), {name: "Lucy", age: 9}, 'Returns the object with the minimum specified value in an array');
|
)).toEqual({name: "Lucy", age: 9});
|
||||||
|
});
|
||||||
|
|
||||||
|
|||||||
@ -1,23 +1,21 @@
|
|||||||
const expect = require('expect');
|
const expect = require('expect');
|
||||||
const reducedFilter = require('./reducedFilter.js');
|
const reducedFilter = require('./reducedFilter.js');
|
||||||
|
|
||||||
|
test('reducedFilter is a Function', () => {
|
||||||
test('reducedFilter is a Function', () => {
|
|
||||||
expect(reducedFilter).toBeInstanceOf(Function);
|
expect(reducedFilter).toBeInstanceOf(Function);
|
||||||
});
|
});
|
||||||
const data = [
|
const data = [
|
||||||
{
|
{
|
||||||
id: 1,
|
id: 1,
|
||||||
name: 'john',
|
name: 'john',
|
||||||
age: 24
|
age: 24
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 2,
|
id: 2,
|
||||||
name: 'mike',
|
name: 'mike',
|
||||||
age: 50
|
age: 50
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
test('Filter an array of objects based on a condition while also filtering out unspecified keys.', () => {
|
test('Filter an array of objects based on a condition while also filtering out unspecified keys.', () => {
|
||||||
expect(reducedFilter(data, ['id', 'name'], item => item.age > 24), [{ id: 2).toEqual(name: 'mike'}])
|
expect(reducedFilter(data, ['id', 'name'], item => item.age > 24)).toEqual([{ id: 2, name: 'mike'}])
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -1,24 +1,20 @@
|
|||||||
const expect = require('expect');
|
const expect = require('expect');
|
||||||
const reject = require('./reject.js');
|
const reject = require('./reject.js');
|
||||||
|
|
||||||
|
test('reject is a Function', () => {
|
||||||
test('reject is a Function', () => {
|
|
||||||
expect(reject).toBeInstanceOf(Function);
|
expect(reject).toBeInstanceOf(Function);
|
||||||
});
|
});
|
||||||
|
const noEvens = reject(
|
||||||
const noEvens = reject(
|
(x) => x % 2 === 0,
|
||||||
(x) => x % 2 === 0,
|
[1, 2, 3, 4, 5]
|
||||||
[1, 2, 3, 4, 5]
|
);
|
||||||
);
|
test('Works with numbers', () => {
|
||||||
|
expect(noEvens).toEqual([1, 3, 5]);
|
||||||
t.deepEqual(noEvens, [1, 3, 5]);
|
});
|
||||||
|
const fourLettersOrLess = reject(
|
||||||
const fourLettersOrLess = reject(
|
(word) => word.length > 4,
|
||||||
(word) => word.length > 4,
|
['Apple', 'Pear', 'Kiwi', 'Banana']
|
||||||
['Apple', 'Pear', 'Kiwi', 'Banana']
|
);
|
||||||
);
|
test('Works with strings', () => {
|
||||||
|
expect(fourLettersOrLess).toEqual(['Pear', 'Kiwi']);
|
||||||
t.deepEqual(fourLettersOrLess, ['Pear', 'Kiwi']);
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1,12 +1,9 @@
|
|||||||
const expect = require('expect');
|
const expect = require('expect');
|
||||||
const remove = require('./remove.js');
|
const remove = require('./remove.js');
|
||||||
|
|
||||||
|
test('remove is a Function', () => {
|
||||||
test('remove is a Function', () => {
|
|
||||||
expect(remove).toBeInstanceOf(Function);
|
expect(remove).toBeInstanceOf(Function);
|
||||||
});
|
});
|
||||||
test('Removes elements from an array for which the given function returns false', () => {
|
test('Removes elements from an array for which the given function returns false', () => {
|
||||||
expect(remove([1, 2, 3, 4], n => n % 2 === 0), [2).toEqual(4])
|
expect(remove([1, 2, 3, 4], n => n % 2 === 0)).toEqual([2, 4]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1,12 +1,9 @@
|
|||||||
const expect = require('expect');
|
const expect = require('expect');
|
||||||
const removeNonASCII = require('./removeNonASCII.js');
|
const removeNonASCII = require('./removeNonASCII.js');
|
||||||
|
|
||||||
|
test('removeNonASCII is a Function', () => {
|
||||||
test('removeNonASCII is a Function', () => {
|
|
||||||
expect(removeNonASCII).toBeInstanceOf(Function);
|
expect(removeNonASCII).toBeInstanceOf(Function);
|
||||||
});
|
});
|
||||||
test('Removes non-ASCII characters', () => {
|
test('Removes non-ASCII characters', () => {
|
||||||
expect(removeNonASCII('äÄçÇéÉêlorem-ipsumöÖÐþúÚ'), 'lorem-ipsum').toBe()
|
expect(removeNonASCII('äÄçÇéÉêlorem-ipsumöÖÐþúÚ')).toBe('lorem-ipsum');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1,8 +1,6 @@
|
|||||||
const expect = require('expect');
|
const expect = require('expect');
|
||||||
const removeVowels = require('./removeVowels.js');
|
const removeVowels = require('./removeVowels.js');
|
||||||
|
|
||||||
|
test('removeVowels is a Function', () => {
|
||||||
test('removeVowels is a Function', () => {
|
|
||||||
expect(removeVowels).toBeInstanceOf(Function);
|
expect(removeVowels).toBeInstanceOf(Function);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -1,15 +1,11 @@
|
|||||||
const expect = require('expect');
|
const expect = require('expect');
|
||||||
const renameKeys = require('./renameKeys.js');
|
const renameKeys = require('./renameKeys.js');
|
||||||
|
|
||||||
|
test('renameKeys is a Function', () => {
|
||||||
test('renameKeys is a Function', () => {
|
|
||||||
expect(renameKeys).toBeInstanceOf(Function);
|
expect(renameKeys).toBeInstanceOf(Function);
|
||||||
});
|
});
|
||||||
|
const obj = { name: 'Bobo', job: 'Front-End Master', shoeSize: 100 };
|
||||||
const obj = { name: 'Bobo', job: 'Front-End Master', shoeSize: 100 };
|
const renamedObj = renameKeys({ name: 'firstName', job: 'passion' }, obj);
|
||||||
const renamedObj = renameKeys({ name: 'firstName', job: 'passion' }, obj);
|
test('renameKeys is a Function', () => {
|
||||||
|
expect(renamedObj).toEqual({ firstName: 'Bobo', passion: 'Front-End Master', shoeSize: 100 });
|
||||||
t.deepEqual(renamedObj, { firstName: 'Bobo', passion: 'Front-End Master', shoeSize: 100
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1,11 +1,9 @@
|
|||||||
const expect = require('expect');
|
const expect = require('expect');
|
||||||
const reverseString = require('./reverseString.js');
|
const reverseString = require('./reverseString.js');
|
||||||
|
|
||||||
|
test('reverseString is a Function', () => {
|
||||||
test('reverseString is a Function', () => {
|
|
||||||
expect(reverseString).toBeInstanceOf(Function);
|
expect(reverseString).toBeInstanceOf(Function);
|
||||||
});
|
});
|
||||||
test('Reverses a string.', () => {
|
test('Reverses a string.', () => {
|
||||||
expect(reverseString('foobar')).toBe('raboof')
|
expect(reverseString('foobar')).toBe('raboof');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -1,23 +1,22 @@
|
|||||||
const expect = require('expect');
|
const expect = require('expect');
|
||||||
const round = require('./round.js');
|
const round = require('./round.js');
|
||||||
|
|
||||||
|
test('round is a Function', () => {
|
||||||
test('round is a Function', () => {
|
|
||||||
expect(round).toBeInstanceOf(Function);
|
expect(round).toBeInstanceOf(Function);
|
||||||
});
|
});
|
||||||
test('round(1.005, 2) returns 1.01', () => {
|
test('round(1.005, 2) returns 1.01', () => {
|
||||||
expect(round(1.005, 2)).toBe(1.01)
|
expect(round(1.005, 2)).toBe(1.01);
|
||||||
});
|
});
|
||||||
test('round(123.3423345345345345344, 11) returns 123.34233453453', () => {
|
test('round(123.3423345345345345344, 11) returns 123.34233453453', () => {
|
||||||
expect(round(123.3423345345345345344, 11)).toBe(123.34233453453)
|
expect(round(123.3423345345345345344, 11)).toBe(123.34233453453);
|
||||||
});
|
});
|
||||||
test('round(3.342, 11) returns 3.342', () => {
|
test('round(3.342, 11) returns 3.342', () => {
|
||||||
expect(round(3.342, 11)).toBe(3.342)
|
expect(round(3.342, 11)).toBe(3.342);
|
||||||
});
|
});
|
||||||
test('round(1.005) returns 1', () => {
|
test('round(1.005) returns 1', () => {
|
||||||
expect(round(1.005)).toBe(1)
|
expect(round(1.005)).toBe(1);
|
||||||
});
|
});
|
||||||
test('round([1.005, 2]) returns NaN', () => {
|
test('round([1.005, 2]) returns NaN', () => {
|
||||||
expect(isNaN(round([1.005, 2]))).toBeTruthy();
|
expect(isNaN(round([1.005, 2]))).toBeTruthy();
|
||||||
});
|
});
|
||||||
test('round(string) returns NaN', () => {
|
test('round(string) returns NaN', () => {
|
||||||
@ -32,12 +31,9 @@ const round = require('./round.js');
|
|||||||
test('round({a: 132}, 413) returns NaN', () => {
|
test('round({a: 132}, 413) returns NaN', () => {
|
||||||
expect(isNaN(round({a: 132}, 413))).toBeTruthy();
|
expect(isNaN(round({a: 132}, 413))).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
let start = new Date().getTime();
|
||||||
let start = new Date().getTime();
|
round(123.3423345345345345344, 11);
|
||||||
round(123.3423345345345345344, 11);
|
let end = new Date().getTime();
|
||||||
let end = new Date().getTime();
|
test('round(123.3423345345345345344, 11) takes less than 2s to run', () => {
|
||||||
test('round(123.3423345345345345344, 11) takes less than 2s to run', () => {
|
|
||||||
expect((end - start) < 2000).toBeTruthy();
|
expect((end - start) < 2000).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1,10 +1,6 @@
|
|||||||
const expect = require('expect');
|
const expect = require('expect');
|
||||||
const runAsync = require('./runAsync.js');
|
const runAsync = require('./runAsync.js');
|
||||||
|
|
||||||
|
test('runAsync is a Function', () => {
|
||||||
test('runAsync is a Function', () => {
|
|
||||||
expect(runAsync).toBeInstanceOf(Function);
|
expect(runAsync).toBeInstanceOf(Function);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -2,10 +2,10 @@ const expect = require('expect');
|
|||||||
const runPromisesInSeries = require('./runPromisesInSeries.js');
|
const runPromisesInSeries = require('./runPromisesInSeries.js');
|
||||||
|
|
||||||
|
|
||||||
test('runPromisesInSeries is a Function', () => {
|
test('runPromisesInSeries is a Function', () => {
|
||||||
expect(runPromisesInSeries).toBeInstanceOf(Function);
|
expect(runPromisesInSeries).toBeInstanceOf(Function);
|
||||||
});
|
});
|
||||||
const delay = d => new Promise(r => setTimeout(r, d));
|
const delay = d => new Promise(r => setTimeout(r, d));
|
||||||
runPromisesInSeries([() => delay(100), () => delay(200).then(() =>
|
test('Runs promises in series', () => {
|
||||||
|
runPromisesInSeries([() => delay(100), () => delay(200).then(() => expect(true).toBeTruthy()));
|
||||||
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user