Test cleanup and fixes [w-z]

This commit is contained in:
Angelos Chalaris
2018-06-18 19:01:06 +03:00
parent c0a42d906a
commit 584ed191d4
8 changed files with 118 additions and 106 deletions

View File

@ -1,18 +1,16 @@
const expect = require('expect'); const expect = require('expect');
const when = require('./when.js'); const when = require('./when.js');
test('when is a Function', () => { test('when is a Function', () => {
expect(when).toBeInstanceOf(Function); expect(when).toBeInstanceOf(Function);
}); });
const doubleEvenNumbers = when( const doubleEvenNumbers = when(
(x) => x % 2 === 0, (x) => x % 2 === 0,
(x) => x * 2 (x) => x * 2
); );
test('Returns the proper result', () => {
t.true(doubleEvenNumbers(2) === 4); expect(doubleEvenNumbers(2)).toBe(4);
t.true(doubleEvenNumbers(1) === 1); });
test('Returns the proper result', () => {
expect(doubleEvenNumbers(1)).toBe(1);
});

View File

@ -1,27 +1,33 @@
const expect = require('expect'); const expect = require('expect');
const without = require('./without.js'); const without = require('./without.js');
test('without is a Function', () => { test('without is a Function', () => {
expect(without).toBeInstanceOf(Function); expect(without).toBeInstanceOf(Function);
}); });
test('without([2, 1, 2, 3], 1, 2) returns [3]', () => { test('without([2, 1, 2, 3], 1, 2) returns [3]', () => {
expect(without([2, 1, 2, 3], 1, 2)).toEqual([3]) expect(without([2, 1, 2, 3], 1, 2)).toEqual([3]);
}); });
test('without([]) returns []', () => { test('without([]) returns []', () => {
expect(without([])).toEqual([]) expect(without([])).toEqual([]);
}); });
test('without([3, 1, true, '3', true], '3', true) returns [3, 1]', () => { test('without([3, 1, true, '3', true], '3', true) returns [3, 1]', () => {
expect(without([3, 1, true, '3', true], '3', true), [3).toEqual(1]) expect(without([3, 1, true, '3', true], '3', true)).toEqual([3, 1]);
}); });
test('without('string'.split(''), 's', 't', 'g') returns ['r', 'i', 'n']', () => { test('without('string'.split(''), 's', 't', 'g') returns [\'r\', \'i\', \'n\']', () => {
expect(without('string'.split(''), 's', 't', 'g'), ['r', 'i').toEqual('n']) expect(without('string'.split(''), 's', 't', 'g')).toEqual(['r', 'i', 'n']);
});
test('without() throws an error', () => {
expect(without()).toThrow();
});
test('without(null) throws an error', () => {
expect(without(null)).toThrow();
});
test('without(undefined) throws an error', () => {
expect(without(undefined)).toThrow();
});
test('without(123) throws an error', () => {
expect(without(123)).toThrow();
});
test('without({}) throws an error', () => {
expect(without({})).toThrow();
}); });
t.throws(() => without(), 'without() throws an error');
t.throws(() => without(null), 'without(null) throws an error');
t.throws(() => without(undefined), 'without(undefined) throws an error');
t.throws(() => without(123), 'without() throws an error');
t.throws(() => without({}), 'without({}) throws an error');

View File

@ -1,25 +1,33 @@
const expect = require('expect'); const expect = require('expect');
const words = require('./words.js'); const words = require('./words.js');
test('words is a Function', () => { test('words is a Function', () => {
expect(words).toBeInstanceOf(Function); expect(words).toBeInstanceOf(Function);
}); });
test('words('I love javaScript!!') returns [I, love, javaScript]', () => { test('words('I love javaScript!!') returns [I, love, javaScript]', () => {
expect(words('I love javaScript!!'), ["I", "love").toEqual("javaScript"]) expect(words('I love javaScript!!')).toEqual(["I", "love", "javaScript"]);
}); });
test('words('python, javaScript & coffee') returns [python, javaScript, coffee]', () => { test('words('python, javaScript & coffee') returns [python, javaScript, coffee]', () => {
expect(words('python, javaScript & coffee'), ["python", "javaScript").toEqual("coffee"]) expect(words('python, javaScript & coffee')).toEqual(["python", "javaScript", "coffee"]);
}); });
test('words(I love javaScript!!) returns an array', () => { test('words(I love javaScript!!) returns an array', () => {
expect(Array.isArray(words('I love javaScript!!'))).toBeTruthy(); expect(Array.isArray(words('I love javaScript!!'))).toBeTruthy();
}); });
t.throws(() => words(), 'words() throws a error'); test('words() throws an error', () => {
t.throws(() => words(null), 'words(null) throws a error'); expect(words()).toThrow();
t.throws(() => words(undefined), 'words(undefined) throws a error'); });
t.throws(() => words({}), 'words({}) throws a error'); test('words(null) throws an error', () => {
t.throws(() => words([]), 'words([]) throws a error'); expect(words(null)).toThrow();
t.throws(() => words(1234), 'words(1234) throws a error'); });
test('words(undefined) throws an error', () => {
expect(words(undefined)).toThrow();
});
test('words({}) throws an error', () => {
expect(words({})).toThrow();
});
test('words([]) throws an error', () => {
expect(words([])).toThrow();
});
test('words(1234) throws an error', () => {
expect(words(1234)).toThrow();
});

View File

@ -1,10 +1,9 @@
const expect = require('expect'); const expect = require('expect');
const xProd = require('./xProd.js'); const xProd = require('./xProd.js');
test('xProd is a Function', () => { test('xProd is a Function', () => {
expect(xProd).toBeInstanceOf(Function); expect(xProd).toBeInstanceOf(Function);
}); });
t.deepEqual(xProd([1, 2], ['a', 'b']), [[1, 'a'], [1, 'b'], [2, 'a'], [2, 'b']], `xProd([1, 2], ['a', 'b']) returns [[1, 'a'], [1, 'b'], [2, 'a'], [2, 'b']]`); test('xProd([1, 2], [\'a\', \'b\']) returns [[1, \'a\'], [1, \'b\'], [2, \'a\'], [2, \'b\']]', () => {
expect(xProd([1, 2], ['a', 'b'])).toEqual([[1, 'a'], [1, 'b'], [2, 'a'], [2, 'b']]);
});

View File

@ -1,7 +1,6 @@
const expect = require('expect'); const expect = require('expect');
const yesNo = require('./yesNo.js'); const yesNo = require('./yesNo.js');
test('yesNo is a Function', () => { test('yesNo is a Function', () => {
expect(yesNo).toBeInstanceOf(Function); expect(yesNo).toBeInstanceOf(Function);
}); });
@ -41,6 +40,3 @@ const yesNo = require('./yesNo.js');
test('yesNo({ 2: Yes }, true) returns true', () => { test('yesNo({ 2: Yes }, true) returns true', () => {
expect(yesNo({ 2: 'Yes' }, true)).toBeTruthy(); expect(yesNo({ 2: 'Yes' }, true)).toBeTruthy();
}); });

View File

@ -6,16 +6,16 @@ const zip = require('./zip.js');
expect(zip).toBeInstanceOf(Function); expect(zip).toBeInstanceOf(Function);
}); });
test('zip([a, b], [1, 2], [true, false]) returns [[a, 1, true], [b, 2, false]]', () => { test('zip([a, b], [1, 2], [true, false]) returns [[a, 1, true], [b, 2, false]]', () => {
expect(zip(['a', 'b'], [1, 2], [true, false]), [['a', 1, true], ['b', 2, false]]).toEqual() expect(zip(['a', 'b'], [1, 2], [true, false])).toEqual([['a', 1, true], ['b', 2, false]]);
}); });
test('zip([a], [1, 2], [true, false]) returns [[a, 1, true], [undefined, 2, false]]', () => { test('zip([a], [1, 2], [true, false]) returns [[a, 1, true], [undefined, 2, false]]', () => {
expect(zip(['a'], [1, 2], [true, false]), [['a', 1, true], [undefined, 2, false]]).toEqual() expect(zip(['a'], [1, 2], [true, false])).toEqual([['a', 1, true], [undefined, 2, false]]);
}); });
test('zip([]) returns []', () => { test('zip([]) returns []', () => {
expect(zip(), []).toEqual() expect(zip()).toEqual([]);
}); });
test('zip(123) returns []', () => { test('zip(123) returns []', () => {
expect(zip(123), []).toEqual() expect(zip(123)).toEqual([]);
}); });
test('zip([a, b], [1, 2], [true, false]) returns an Array', () => { test('zip([a, b], [1, 2], [true, false]) returns an Array', () => {
expect(Array.isArray(zip(['a', 'b'], [1, 2], [true, false]))).toBeTruthy(); expect(Array.isArray(zip(['a', 'b'], [1, 2], [true, false]))).toBeTruthy();
@ -23,8 +23,9 @@ const zip = require('./zip.js');
test('zip([a], [1, 2], [true, false]) returns an Array', () => { test('zip([a], [1, 2], [true, false]) returns an Array', () => {
expect(Array.isArray(zip(['a'], [1, 2], [true, false]))).toBeTruthy(); expect(Array.isArray(zip(['a'], [1, 2], [true, false]))).toBeTruthy();
}); });
t.throws(() => zip(null), 'zip(null) throws an error'); test('zip(null) throws an error', () => {
t.throws(() => zip(undefined), 'zip(undefined) throws an error'); expect(zip(null)).toThrow();
});
test('zip(undefined) throws an error', () => {
expect(zip(undefined)).toThrow();
});

View File

@ -1,27 +1,33 @@
const expect = require('expect'); const expect = require('expect');
const zipObject = require('./zipObject.js'); const zipObject = require('./zipObject.js');
test('zipObject is a Function', () => { test('zipObject is a Function', () => {
expect(zipObject).toBeInstanceOf(Function); expect(zipObject).toBeInstanceOf(Function);
}); });
test('zipObject([a, b, c], [1, 2]) returns {a: 1, b: 2, c: undefined}', () => { test('zipObject([a, b, c], [1, 2]) returns {a: 1, b: 2, c: undefined}', () => {
expect(zipObject(['a', 'b', 'c'], [1, 2]), {a: 1, b: 2, c: undefined}).toEqual() expect(zipObject(['a', 'b', 'c'], [1, 2])).toEqual({a: 1, b: 2, c: undefined});
}); });
test('zipObject([a, b], [1, 2, 3]) returns {a: 1, b: 2}', () => { test('zipObject([a, b], [1, 2, 3]) returns {a: 1, b: 2}', () => {
expect(zipObject(['a', 'b'], [1, 2, 3]), {a: 1, b: 2}).toEqual() expect(zipObject(['a', 'b'], [1, 2, 3])).toEqual({a: 1, b: 2});
}); });
test('zipObject([a, b, c], string) returns { a: s, b: t, c: r }', () => { test('zipObject([a, b, c], string) returns { a: s, b: t, c: r }', () => {
expect(zipObject(['a', 'b', 'c'], 'string'), { a: 's', b: 't', c: 'r' }).toEqual() expect(zipObject(['a', 'b', 'c'], 'string')).toEqual({ a: 's', b: 't', c: 'r' });
}); });
test('zipObject([a], string) returns { a: s }', () => { test('zipObject([a], string) returns { a: s }', () => {
expect(zipObject(['a'], 'string'), { a: 's' }).toEqual() expect(zipObject(['a'], 'string')).toEqual({ a: 's' });
});
test('zipObject() throws an error', () => {
expect(zipObject()).toThrow();
});
test('zipObject(([\'string\'], null) throws an error', () => {
expect(zipObject((['string'], null)).toThrow();
});
test('zipObject(null, [1]) throws an error', () => {
expect(zipObject(null, [1])).toThrow();
});
test('zipObject(\'string\') throws an error', () => {
expect(zipObject('string')).toThrow();
});
test('zipObject(\'test\', \'string\') throws an error', () => {
expect(zipObject('test', 'string')).toThrow();
}); });
t.throws(() => zipObject(), 'zipObject() throws an error');
t.throws(() => zipObject(['string'], null), 'zipObject([string], null) throws an error');
t.throws(() => zipObject(null, [1]), 'zipObject(null, [1]) throws an error');
t.throws(() => zipObject('string'), 'zipObject(string) throws an error');
t.throws(() => zipObject('test', 'string'), 'zipObject(test, string) throws an error');

View File

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