Test cleanup and fixes [i-l]

This commit is contained in:
Angelos Chalaris
2018-06-18 17:31:56 +03:00
parent f67e121ed8
commit 82f0d6bc52
59 changed files with 358 additions and 452 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,11 +1,9 @@
const expect = require('expect');
const initialize2DArray = require('./initialize2DArray.js');
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), [[0,0], [0).toEqual(0]])
expect(initialize2DArray(2, 2, 0)).toEqual([[0,0], [0,0]]);
});

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,12 +1,9 @@
const expect = require('expect');
const intersectionBy = require('./intersectionBy.js');
test('intersectionBy is a Function', () => {
expect(intersectionBy).toBeInstanceOf(Function);
});
test('Returns a list of elements that exist in both arrays, after applying the provided function to each array element of both', () => {
expect(intersectionBy([2.1, 1.2], [2.3, 3.4], Math.floor), [2.1]).toEqual()
expect(intersectionBy([2.1, 1.2], [2.3, 3.4], Math.floor)).toEqual([2.1]);
});

View File

@ -1,12 +1,9 @@
const expect = require('expect');
const intersectionWith = require('./intersectionWith.js');
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)), [1.5, 3, 0]).toEqual()
expect(intersectionWith([1, 1.2, 1.5, 3, 0], [1.9, 3, 0, 3.9], (a, b) => Math.round(a) === Math.round(b))).toEqual([1.5, 3, 0]);
});

View File

@ -1,14 +1,12 @@
const expect = require('expect');
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 }), { 1: [ 'a', 'c' ]).toEqual(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), { group1: [ 'a', 'c' ]).toEqual(group2: [ 'b' ] })
expect(invertKeyValues({ a: 1, b: 2, c: 1 }, value => 'group' + value)).toEqual( { group1: [ 'a', 'c' ], group2: [ 'b' ] });
});

View File

@ -1,25 +1,54 @@
const expect = require('expect');
const is = require('./is.js');
test('is is a Function', () => {
expect(is).toBeInstanceOf(Function);
});
t.true(is(Array, [1]), `Works for arrays with data`);
t.true(is(Array, []), `Works for empty arrays`);
t.false(is(Array, {}), `Works for arrays, not objects`);
t.true(is(Object, {}), `Works for objects`);
t.true(is(Map, new Map()), `Works for maps`);
t.true(is(RegExp, /./g), `Works for regular expressions`);
t.true(is(Set, new Set()), `Works for sets`);
t.true(is(WeakMap, new WeakMap()), `Works for weak maps`);
t.true(is(WeakSet, new WeakSet()), `Works for weak sets`);
t.true(is(String, ''), `Works for strings - returns true for primitive`);
t.true(is(String, new String('')), `Works for strings - returns true when using constructor`);
t.true(is(Number, 1), `Works for numbers - returns true for primitive`);
t.true(is(Number, new Number('10')), `Works for numbers - returns true when using constructor`);
t.true(is(Boolean, false), `Works for booleans - returns true for primitive`);
t.true(is(Boolean, new Boolean(false)), `Works for booleans - returns true when using constructor`);
t.true(is(Function, () => null), `Works for functions`);
test('Works for arrays with data', () => {
expect(is(Array, [1])).toBeTruthy();
});
test('Works for empty arrays', () => {
expect(is(Array, [])).toBeTruthy()
});
test('Works for arrays, not objects', () => {
expect(is(Array, {})).toBeFalsy();
});
test('Works for objects', () => {
expect(is(Object, {})).toBeTruthy();
});
test('Works for maps', () => {
expect(is(Map, new Map())).toBeTruthy();
});
test('Works for regular expressions', () => {
expect(is(RegExp, /./g)).toBeTruthy();
});
test('Works for sets', () => {
expect(is(Set, new Set())).toBeTruthy();
});
test('Works for weak maps', () => {
expect(is(WeakMap, new WeakMap())).toBeTruthy();
});
test('Works for weak sets', () => {
expect(is(WeakSet, new WeakSet())).toBeTruthy();
});
test('Works for strings - returns true for primitive', () => {
expect(is(String, '')).toBeTruthy();
});
test('Works for strings - returns true when using constructor', () => {
expect(is(String, new String(''))).toBeTruthy();
});
test('Works for numbers - returns true for primitive', () => {
expect(is(Number, 1)).toBeTruthy();
});
test('Works for numbers - returns true when using constructor', () => {
expect(is(Number, new Number('10'))).toBeTruthy()
});
test('Works for booleans - returns true for primitive', () => {
expect(is(Boolean, false)).toBeTruthy()
});
test('Works for booleans - returns true when using constructor', () => {
expect(is(Boolean, new Boolean(false))).toBeTruthy();
});
test('Works for functions', () => {
expect(is(Function, () => null)).toBeTruthy();
});

View File

@ -1,13 +1,15 @@
const expect = require('expect');
const isAbsoluteURL = require('./isAbsoluteURL.js');
test('isAbsoluteURL is a Function', () => {
expect(isAbsoluteURL).toBeInstanceOf(Function);
});
t.equal(isAbsoluteURL('https:
t.equal(isAbsoluteURL('ftp:
test('Given string is not an absolute URL', () => {
expect(isAbsoluteURL('/foo/bar')).toBe(false)
test('Given string is an absolute URL', () => {
expect(isAbsoluteURL('https://google.com')).toBeTruthy();
});
test('Given string is an absolute URL', () => {
expect(isAbsoluteURL('ftp://www.myserver.net')).toBeTruthy();
});
test('Given string is not an absolute URL', () => {
expect(isAbsoluteURL('/foo/bar')).toBeFalsy();
});

View File

@ -1,7 +1,6 @@
const expect = require('expect');
const isAnagram = require('./isAnagram.js');
test('isAnagram is a Function', () => {
expect(isAnagram).toBeInstanceOf(Function);
});
@ -17,5 +16,3 @@ const isAnagram = require('./isAnagram.js');
test('Ignores special characters', () => {
expect(isAnagram('Regera Dowdy', 'E. G. Deadworry')).toBeTruthy();
});

View File

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

View File

@ -1,14 +1,12 @@
const expect = require('expect');
const isArray = require('./isArray.js');
test('isArray is a Function', () => {
expect(isArray).toBeInstanceOf(Function);
});
test('passed value is an array', () => {
expect(isArray([1])).toBe(true)
expect(isArray([1])).toBeTruthy()
});
test('passed value is not an array', () => {
expect(isArray('array')).toBe(false)
expect(isArray('array')).toBeFalsy();
});

View File

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

View File

@ -1,18 +1,15 @@
const expect = require('expect');
const isArrayLike = require('./isArrayLike.js');
test('isArrayLike is a Function', () => {
expect(isArrayLike).toBeInstanceOf(Function);
});
test('Returns true for a string', () => {
expect(isArrayLike('abc'), true).toBe()
expect(isArrayLike('abc')).toBeTruthy()
});
test('Returns true for an array', () => {
expect(isArrayLike([1,2,3]), true).toBe()
expect(isArrayLike([1,2,3])).toBeTruthy();
});
test('Returns false for null', () => {
expect(isArrayLike(null), false).toBe()
expect(isArrayLike(null)).toBeFalsy();
});

View File

@ -1,14 +1,12 @@
const expect = require('expect');
const isBoolean = require('./isBoolean.js');
test('isBoolean is a Function', () => {
expect(isBoolean).toBeInstanceOf(Function);
});
test('passed value is not a boolean', () => {
expect(isBoolean(null)).toBe(false)
expect(isBoolean(null)).toBeFalsy();
});
test('passed value is not a boolean', () => {
expect(isBoolean(false)).toBe(true)
expect(isBoolean(false)).toBeTruthy();
});

View File

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

View File

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

View File

@ -1,11 +1,10 @@
const expect = require('expect');
const isDivisible = require('./isDivisible.js');
test('isDivisible is a Function', () => {
expect(isDivisible).toBeInstanceOf(Function);
});
test('The number 6 is divisible by 3', () => {
expect(isDivisible(6, 3), true).toBe()
expect(isDivisible(6, 3)).toBeTruthy();
});

View File

@ -1,39 +1,36 @@
const expect = require('expect');
const isEmpty = require('./isEmpty.js');
test('isEmpty is a Function', () => {
expect(isEmpty).toBeInstanceOf(Function);
});
test('Returns true for empty Map', () => {
expect(isEmpty(new Map()), true).toBe()
expect(isEmpty(new Map())).toBeTruthy();
});
test('Returns true for empty Set', () => {
expect(isEmpty(new Set()), true).toBe()
expect(isEmpty(new Set())).toBeTruthy();
});
test('Returns true for empty array', () => {
expect(isEmpty([]), true).toBe()
expect(isEmpty([])).toBeTruthy();
});
test('Returns true for empty object', () => {
expect(isEmpty({}), true).toBe()
expect(isEmpty({})).toBeTruthy();
});
test('Returns true for empty string', () => {
expect(isEmpty(''), true).toBe()
expect(isEmpty('')).toBeTruthy();
});
test('Returns false for non-empty array', () => {
expect(isEmpty([1, 2]), false).toBe()
expect(isEmpty([1, 2])).toBeFalsy();
});
test('Returns false for non-empty object', () => {
expect(isEmpty({ a: 1, b: 2 }), false).toBe()
expect(isEmpty({ a: 1, b: 2 })).toBeFalsy();
});
test('Returns false for non-empty string', () => {
expect(isEmpty('text'), false).toBe()
expect(isEmpty('text')).toBeFalsy();
});
test('Returns true - type is not considered a collection', () => {
expect(isEmpty(123), true).toBe()
expect(isEmpty(123)).toBeTruthy();
});
test('Returns true - type is not considered a collection', () => {
expect(isEmpty(true), true).toBe()
expect(isEmpty(true)).toBeTruthy();
});

View File

@ -1,14 +1,12 @@
const expect = require('expect');
const isEven = require('./isEven.js');
test('isEven is a Function', () => {
expect(isEven).toBeInstanceOf(Function);
});
test('4 is even number', () => {
expect(isEven(4), true).toBe()
expect(isEven(4)).toBeTruthy();
});
test('5 is not an even number', () => {
expect(isEven(5), false).toBeFalsy();
expect(isEven(5)).toBeFalsy();
});

View File

@ -1,14 +1,13 @@
const expect = require('expect');
const isFunction = require('./isFunction.js');
test('isFunction is a Function', () => {
expect(isFunction).toBeInstanceOf(Function);
});
test('passed value is a function', () => {
expect(isFunction(x => x)).toBe(true)
expect(isFunction(x => x)).toBeTruthy();
});
test('passed value is not a function', () => {
expect(isFunction('x')).toBe(false)
expect(isFunction('x')).toBeFalsy();
});

View File

@ -1,17 +1,15 @@
const expect = require('expect');
const isLowerCase = require('./isLowerCase.js');
test('isLowerCase is a Function', () => {
expect(isLowerCase).toBeInstanceOf(Function);
});
test('passed string is a lowercase', () => {
expect(isLowerCase('abc')).toBe(true)
expect(isLowerCase('abc')).toBeTruthy();
});
test('passed string is a lowercase', () => {
expect(isLowerCase('a3@$')).toBe(true)
expect(isLowerCase('a3@$')).toBeTruthy();
});
test('passed value is not a lowercase', () => {
expect(isLowerCase('A3@$')).toBe(false)
expect(isLowerCase('A3@$')).toBeFalsy();
});

View File

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

View File

@ -1,18 +1,15 @@
const expect = require('expect');
const isNil = require('./isNil.js');
test('isNil is a Function', () => {
expect(isNil).toBeInstanceOf(Function);
});
test('Returns true for null', () => {
expect(isNil(null), true).toBe()
expect(isNil(null)).toBeTruthy();
});
test('Returns true for undefined', () => {
expect(isNil(undefined), true).toBe()
expect(isNil(undefined)).toBeTruthy();
});
test('Returns false for an empty string', () => {
expect(isNil(''), false).toBe()
expect(isNil('')).toBeFalsy();
});

View File

@ -1,14 +1,12 @@
const expect = require('expect');
const isNull = require('./isNull.js');
test('isNull is a Function', () => {
expect(isNull).toBeInstanceOf(Function);
});
test('passed argument is a null', () => {
expect(isNull(null)).toBe(true)
expect(isNull(null)).toBeTruthy();
});
test('passed argument is a null', () => {
expect(isNull(NaN)).toBe(false)
expect(isNull(NaN)).toBeFalsy();
});

View File

@ -1,14 +1,12 @@
const expect = require('expect');
const isNumber = require('./isNumber.js');
test('isNumber is a Function', () => {
expect(isNumber).toBeInstanceOf(Function);
});
test('passed argument is a number', () => {
expect(isNumber(1)).toBe(true)
expect(isNumber(1)).toBeTruthy();
});
test('passed argument is not a number', () => {
expect(isNumber('1')).toBe(false)
expect(isNumber('1')).toBeFalsy();
});

View File

@ -1,11 +1,9 @@
const expect = require('expect');
const isObject = require('./isObject.js');
test('isObject is a Function', () => {
expect(isObject).toBeInstanceOf(Function);
});
test('isObject([1, 2, 3, 4]) is a object', () => {
expect(isObject([1, 2, 3, 4])).toBeTruthy();
});
@ -19,4 +17,3 @@ const isObject = require('./isObject.js');
expect(isObject(true)).toBeFalsy();
});

View File

@ -1,21 +1,18 @@
const expect = require('expect');
const isObjectLike = require('./isObjectLike.js');
test('isObjectLike is a Function', () => {
expect(isObjectLike).toBeInstanceOf(Function);
});
test('Returns true for an object', () => {
expect(isObjectLike({}), true).toBe()
expect(isObjectLike({})).toBeTruthy();
});
test('Returns true for an array', () => {
expect(isObjectLike([1, 2, 3]), true).toBe()
expect(isObjectLike([1, 2, 3])).toBeTruthy();
});
test('Returns false for a function', () => {
expect(isObjectLike(x => x), false).toBe()
expect(isObjectLike(x => x)).toBeFalsy();
});
test('Returns false for null', () => {
expect(isObjectLike(null), false).toBe()
expect(isObjectLike(null)).toBeFalsy();
});

View File

@ -1,15 +1,12 @@
const expect = require('expect');
const isPlainObject = require('./isPlainObject.js');
test('isPlainObject is a Function', () => {
expect(isPlainObject).toBeInstanceOf(Function);
});
test('Returns true for a plain object', () => {
expect(isPlainObject({ a: 1 }), true).toBe()
expect(isPlainObject({ a: 1 })).toBeTruthy();
});
test('Returns false for a Map (example of non-plain object)', () => {
expect(isPlainObject(new Map()), false).toBe()
expect(isPlainObject(new Map())).toBeFalsy();
});

View File

@ -1,11 +1,9 @@
const expect = require('expect');
const isPrime = require('./isPrime.js');
test('isPrime is a Function', () => {
expect(isPrime).toBeInstanceOf(Function);
});
test('passed number is a prime', () => {
expect(isPrime(11)).toBe(true)
expect(isPrime(11)).toBeTruthy();
});

View File

@ -1,45 +1,42 @@
const expect = require('expect');
const isPrimitive = require('./isPrimitive.js');
test('isPrimitive is a Function', () => {
expect(isPrimitive).toBeInstanceOf(Function);
});
test('isPrimitive(null) is primitive', () => {
expect(isPrimitive(null)).toBeTruthy()
expect(isPrimitive(null)).toBeTruthy();
});
test('isPrimitive(undefined) is primitive', () => {
expect(isPrimitive(undefined)).toBeTruthy()
expect(isPrimitive(undefined)).toBeTruthy();
});
test('isPrimitive(string) is primitive', () => {
expect(isPrimitive('string')).toBeTruthy()
expect(isPrimitive('string')).toBeTruthy();
});
test('isPrimitive(true) is primitive', () => {
expect(isPrimitive(true)).toBeTruthy()
expect(isPrimitive(true)).toBeTruthy();
});
test('isPrimitive(50) is primitive', () => {
expect(isPrimitive(50)).toBeTruthy()
expect(isPrimitive(50)).toBeTruthy();
});
test('isPrimitive('Hello') is primitive', () => {
expect(isPrimitive('Hello')).toBeTruthy()
expect(isPrimitive('Hello')).toBeTruthy();
});
test('isPrimitive(false) is primitive', () => {
expect(isPrimitive(false)).toBeTruthy()
expect(isPrimitive(false)).toBeTruthy();
});
test('isPrimitive(Symbol()) is primitive', () => {
expect(isPrimitive(Symbol())).toBeTruthy()
expect(isPrimitive(Symbol())).toBeTruthy();
});
test('isPrimitive([1, 2, 3]) is not primitive', () => {
expect(isPrimitive([1, 2, 3])).toBeFalsy()
expect(isPrimitive([1, 2, 3])).toBeFalsy();
});
test('isPrimitive({ a: 123 }) is not primitive', () => {
expect(isPrimitive({ a: 123 })).toBeFalsy()
expect(isPrimitive({ a: 123 })).toBeFalsy();
});
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();
});

View File

@ -1,20 +1,16 @@
const expect = require('expect');
const isPromiseLike = require('./isPromiseLike.js');
test('isPromiseLike is a Function', () => {
expect(isPromiseLike).toBeInstanceOf(Function);
});
t.equal(isPromiseLike({
test('Returns true for a promise-like object', () => {
expect(isPromiseLike({
then: function() {
return '';
}
}), true, 'Returns true for a promise-like object');
test('Returns false for null', () => {
expect(isPromiseLike(null), false).toBe()
})).toBeTruthy();
});
test('Returns false for an empty object', () => {
expect(isPromiseLike({}), false).toBe()
expect(isPromiseLike({})).toBeFalsy();
});

View File

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

View File

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

View File

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

View File

@ -1,42 +1,39 @@
const expect = require('expect');
const isSorted = require('./isSorted.js');
test('isSorted is a Function', () => {
expect(isSorted).toBeInstanceOf(Function);
});
test('Array is sorted in ascending order', () => {
expect(isSorted([0, 1, 2]), 1).toBe()
expect(isSorted([0, 1, 2])).toBe(1);
});
test('Array is sorted in ascending order', () => {
expect(isSorted([0, 1, 2, 2]), 1).toBe()
expect(isSorted([0, 1, 2, 2])).toBe(1);
});
test('Array is sorted in ascending order', () => {
expect(isSorted([-4, -3, -2]), 1).toBe()
expect(isSorted([-4, -3, -2])).toBe(1);
});
test('Array is sorted in ascending order', () => {
expect(isSorted([0, 0, 1, 2]), 1).toBe()
expect(isSorted([0, 0, 1, 2])).toBe(1);
});
test('Array is sorted in descending order', () => {
expect(isSorted([2, 1, 0]), -1).toBe()
expect(isSorted([2, 1, 0])).toBe(-1);
});
test('Array is sorted in descending order', () => {
expect(isSorted([2, 2, 1, 0]), -1).toBe()
expect(isSorted([2, 2, 1, 0])).toBe(-1);
});
test('Array is sorted in descending order', () => {
expect(isSorted([-2, -3, -4]), -1).toBe()
expect(isSorted([-2, -3, -4])).toBe(-1);
});
test('Array is sorted in descending order', () => {
expect(isSorted([2, 1, 0, 0]), -1).toBe()
expect(isSorted([2, 1, 0, 0])).toBe(-1);
});
test('Array is empty', () => {
expect(isSorted([]), undefined).toBe()
expect(isSorted([])).toBe(undefined);
});
test('Array is not sorted, direction changed in array', () => {
expect(isSorted([1]), 0).toBe()
expect(isSorted([1])).toBe(0);
});
test('Array is not sorted, direction changed in array', () => {
expect(isSorted([1, 2, 1]), 0).toBe()
expect(isSorted([1, 2, 1])).toBe(0);
});

View File

@ -1,23 +1,21 @@
const expect = require('expect');
const isString = require('./isString.js');
test('isString is a Function', () => {
expect(isString).toBeInstanceOf(Function);
});
test('foo is a string', () => {
expect(isString('foo'), true).toBe()
expect(isString('foo')).toBeTruthy();
});
test('"10" is a string', () => {
expect(isString('10'), true).toBe()
expect(isString('10')).toBeTruthy();
});
test('Empty string is a string', () => {
expect(isString(''), true).toBe()
expect(isString('')).toBeTruthy();
});
test('10 is not a string', () => {
expect(isString(10), false).toBe()
expect(isString(10)).toBeFalsy();
});
test('true is not string', () => {
expect(isString(true), false).toBe()
expect(isString(true)).toBeFalsy();
});

View File

@ -1,11 +1,9 @@
const expect = require('expect');
const isSymbol = require('./isSymbol.js');
test('isSymbol is a Function', () => {
expect(isSymbol).toBeInstanceOf(Function);
});
test('Checks if the given argument is a symbol', () => {
expect(isSymbol(Symbol('x'))).toBe(true)
expect(isSymbol(Symbol('x'))).toBeTruthy();
});

View File

@ -1,7 +1,6 @@
const expect = require('expect');
const isTravisCI = require('./isTravisCI.js');
test('isTravisCI is a Function', () => {
expect(isTravisCI).toBeInstanceOf(Function);
});
@ -13,5 +12,3 @@ const isTravisCI = require('./isTravisCI.js');
test('Not running on Travis, correctly evaluates', () => {
expect(isTravisCI()).toBeFalsy();
});

View File

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

View File

@ -1,12 +1,9 @@
const expect = require('expect');
const isUndefined = require('./isUndefined.js');
test('isUndefined is a Function', () => {
expect(isUndefined).toBeInstanceOf(Function);
});
test('Returns true for undefined', () => {
expect(isUndefined(undefined)).toBeTruthy();
});

View File

@ -1,17 +1,15 @@
const expect = require('expect');
const isUpperCase = require('./isUpperCase.js');
test('isUpperCase is a Function', () => {
expect(isUpperCase).toBeInstanceOf(Function);
});
test('ABC is all upper case', () => {
expect(isUpperCase('ABC'), true).toBe()
expect(isUpperCase('ABC')).toBeTruthy();
});
test('abc is not all upper case', () => {
expect(isUpperCase('abc'), false).toBe()
expect(isUpperCase('abc')).toBeFalsy();
});
test('A3@$ is all uppercase', () => {
expect(isUpperCase('A3@$'), true).toBe()
expect(isUpperCase('A3@$')).toBeTruthy();
});

View File

@ -1,17 +1,15 @@
const expect = require('expect');
const isValidJSON = require('./isValidJSON.js');
test('isValidJSON is a Function', () => {
expect(isValidJSON).toBeInstanceOf(Function);
});
test('{"name":"Adam","age":20} is a valid JSON', () => {
expect(isValidJSON('{"name":"Adam","age":20}'), true).toBe()
expect(isValidJSON('{"name":"Adam","age":20}')).toBeTruthy();
});
test('{"name":"Adam",age:"20"} is not a valid JSON', () => {
expect(isValidJSON('{"name":"Adam",age:"20"}'), false).toBe()
expect(isValidJSON('{"name":"Adam",age:"20"}')).toBeFalsy();
});
test('null is a valid JSON', () => {
expect(isValidJSON(null), true).toBe()
expect(isValidJSON(null)).toBeTruthy();
});

View File

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

View File

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

View File

@ -1,17 +1,15 @@
const expect = require('expect');
const join = require('./join.js');
test('join is a Function', () => {
expect(join).toBeInstanceOf(Function);
});
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")
expect(join(['pen', 'pineapple', 'apple', 'pen'], ',', '&')).toEqual('pen,pineapple,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")
expect(join(['pen', 'pineapple', 'apple', 'pen'], ',')).toEqual('pen,pineapple,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")
expect(join(['pen', 'pineapple', 'apple', 'pen'])).toEqual('pen,pineapple,apple,pen');
});

View File

@ -1,7 +1,6 @@
const expect = require('expect');
const last = require('./last.js');
test('last is a Function', () => {
expect(last).toBeInstanceOf(Function);
});
@ -9,22 +8,26 @@ const last = require('./last.js');
expect(last({ a: 1234}) === undefined).toBeTruthy();
});
test('last([1, 2, 3]) returns 3', () => {
expect(last([1, 2, 3])).toBe(3)
expect(last([1, 2, 3])).toBe(3);
});
test('last({ 0: false}) returns undefined', () => {
expect(last({ 0: false}), undefined).toBe()
expect(last({ 0: false})).toBe(undefined);
});
test('last(String) returns g', () => {
expect(last('String'), 'g').toBe()
expect(last('String')).toBe('g');
});
test('last(null) throws an Error', () => {
expect(last(null)).toThrow();
});
test('last(undefined) throws an Error', () => {
expect(last(undefined)).toThrow();
});
test('last() throws an Error', () => {
expect(last()).toThrow();
});
t.throws(() => last(null), 'last(null) throws an Error');
t.throws(() => last(undefined), 'last(undefined) throws an Error');
t.throws(() => last(), 'last() throws an Error');
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();
});

View File

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

View File

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

View File

@ -1,11 +1,9 @@
const expect = require('expect');
const longestItem = require('./longestItem.js');
test('longestItem is a Function', () => {
expect(longestItem).toBeInstanceOf(Function);
});
test('Returns the longest object', () => {
expect(longestItem('this', 'is', 'a', 'testcase')).toEqual('testcase')
expect(longestItem('this', 'is', 'a', 'testcase')).toEqual('testcase');
});

View File

@ -1,17 +1,14 @@
const expect = require('expect');
const lowercaseKeys = require('./lowercaseKeys.js');
test('lowercaseKeys is a Function', () => {
expect(lowercaseKeys).toBeInstanceOf(Function);
});
const myObj = { Name: 'Adam', sUrnAME: 'Smith' };
const myObjLower = lowercaseKeys(myObj);
test('Lowercases object keys', () => {
expect(myObjLower, {name: 'Adam', surname: 'Smith'}).toEqual()
expect(myObjLower).toEqual( {name: 'Adam', surname: 'Smith'});
});
test('Does not mutate original object', () => {
expect(myObj, { Name: 'Adam', sUrnAME: 'Smith' }).toEqual()
expect(myObj).toEqual({ Name: 'Adam', sUrnAME: 'Smith' });
});

View File

@ -1,17 +1,15 @@
const expect = require('expect');
const luhnCheck = require('./luhnCheck.js');
test('luhnCheck is a Function', () => {
expect(luhnCheck).toBeInstanceOf(Function);
});
test('validates identification number', () => {
expect(luhnCheck(6011329933655299)).toBe(false)
expect(luhnCheck(6011329933655299)).toBeFalsy();
});
test('validates identification number', () => {
expect(luhnCheck('4485275742308327')).toBe(true)
expect(luhnCheck('4485275742308327')).toBeTruthy();
});
test('validates identification number', () => {
expect(luhnCheck(123456789)).toBe(false)
expect(luhnCheck(123456789)).toBeFalsy();
});