Test cleanup and fixes [c-d]

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

View File

@ -1,32 +1,36 @@
const expect = require('expect');
const chunk = require('./chunk.js');
test('chunk is a Function', () => {
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([]) returns []', () => {
expect(chunk([]), []).toEqual()
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(123) returns []', () => {
expect(chunk(123), []).toEqual()
test('chunk([]) returns []', () => {
expect(chunk([])).toEqual([])
});
test('chunk({ a: 123}) returns []', () => {
expect(chunk({ a: 123}), []).toEqual()
test('chunk(123) returns []', () => {
expect(chunk(123)).toEqual([])
});
test('chunk(string, 2) returns [ st, ri, ng ]', () => {
expect(chunk('string', 2), [ 'st', 'ri', 'ng' ]).toEqual()
test('chunk({ a: 123}) returns []', () => {
expect(chunk({ a: 123})).toEqual([])
});
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', () => {
test('chunk(string, 2) returns [ st, ri, ng ]', () => {
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();
});
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();
});