Test cleanup and fixes [g-h]

This commit is contained in:
Angelos Chalaris
2018-06-18 16:57:55 +03:00
parent 382c452858
commit 7e9aae6f13
26 changed files with 113 additions and 168 deletions

View File

@ -1,14 +1,12 @@
const expect = require('expect'); const expect = require('expect');
const gcd = require('./gcd.js'); const gcd = require('./gcd.js');
test('gcd is a Function', () => {
test('gcd is a Function', () => {
expect(gcd).toBeInstanceOf(Function); expect(gcd).toBeInstanceOf(Function);
}); });
test('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) expect(gcd(8, 36)).toBe(4);
}); });
test('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(...[12, 8, 32])).toEqual(4) expect(gcd(...[12, 8, 32])).toEqual(4);
}); });

View File

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

View File

@ -1,13 +1,10 @@
const expect = require('expect'); const expect = require('expect');
const get = require('./get.js'); const get = require('./get.js');
test('get is a Function', () => {
test('get is a Function', () => {
expect(get).toBeInstanceOf(Function); expect(get).toBeInstanceOf(Function);
}); });
const obj = { selector: { to: { val: 'val to get' } } }; const obj = { selector: { to: { val: 'val to get' } } };
test('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']) expect(get(obj, 'selector.to.val')).toEqual(['val to get'])
}); });

View File

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

View File

@ -1,11 +1,9 @@
const expect = require('expect'); const expect = require('expect');
const getDaysDiffBetweenDates = require('./getDaysDiffBetweenDates.js'); const getDaysDiffBetweenDates = require('./getDaysDiffBetweenDates.js');
test('getDaysDiffBetweenDates is a Function', () => {
test('getDaysDiffBetweenDates is a Function', () => {
expect(getDaysDiffBetweenDates).toBeInstanceOf(Function); expect(getDaysDiffBetweenDates).toBeInstanceOf(Function);
}); });
test('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) expect(getDaysDiffBetweenDates(new Date('2017-12-13'), new Date('2017-12-22'))).toBe(9);
}); });

View File

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

View File

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

View File

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

View File

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

View File

@ -1,9 +1,9 @@
const expect = require('expect'); const expect = require('expect');
const getURLParameters = require('./getURLParameters.js'); const getURLParameters = require('./getURLParameters.js');
test('getURLParameters is a Function', () => {
test('getURLParameters is a Function', () => {
expect(getURLParameters).toBeInstanceOf(Function); expect(getURLParameters).toBeInstanceOf(Function);
}); });
t.deepEqual(getURLParameters('http: test('Returns an object containing the parameters of the current URL', () => {
expect(getURLParameters(getURLParameters('http://url.com/page?name=Adam&surname=Smith')).toEqual({name: 'Adam', surname: 'Smith'});
});

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,10 +1,9 @@
const expect = require('expect'); const expect = require('expect');
const hashNode = require('./hashNode.js'); const hashNode = require('./hashNode.js');
test('hashNode is a Function', () => {
test('hashNode is a Function', () => {
expect(hashNode).toBeInstanceOf(Function); expect(hashNode).toBeInstanceOf(Function);
}); });
hashNode(JSON.stringify({ a: 'a', b: [1, 2, 3, 4], foo: { c: 'bar' } })).then(v => t.equal(v, '04aa106279f5977f59f9067fa9712afc4aedc6f5862a8defc34552d8c7206393', 'Produces the appropriate hash')); test('Produces the appropriate hash', () => {
hashNode(JSON.stringify({ a: 'a', b: [1, 2, 3, 4], foo: { c: 'bar' } })).then(v => expect(v).toBe('04aa106279f5977f59f9067fa9712afc4aedc6f5862a8defc34552d8c7206393'));
});

View File

@ -1,30 +1,33 @@
const expect = require('expect'); const expect = require('expect');
const head = require('./head.js'); const head = require('./head.js');
test('head is a Function', () => {
test('head is a Function', () => {
expect(head).toBeInstanceOf(Function); expect(head).toBeInstanceOf(Function);
}); });
test('head({ a: 1234}) returns undefined', () => { test('head({ a: 1234}) returns undefined', () => {
expect(head({ a: 1234}) === undefined).toBeTruthy(); expect(head({ a: 1234}) === undefined).toBeTruthy();
}); });
test('head([1, 2, 3]) returns 1', () => { test('head([1, 2, 3]) returns 1', () => {
expect(head([1, 2, 3])).toBe(1) expect(head([1, 2, 3])).toBe(1);
}); });
test('head({ 0: false}) returns false', () => { test('head({ 0: false}) returns false', () => {
expect(head({ 0: false}), false).toBe() expect(head({ 0: false})).toBeFalsy();
}); });
test('head(String) returns S', () => { test('head(String) returns S', () => {
expect(head('String'), 'S').toBe() expect(head('String')).toBe('S');
}); });
t.throws(() => head(null), 'head(null) throws an Error'); test('head(null) throws an Error', () => {
t.throws(() => head(undefined), 'head(undefined) throws an Error'); expect(head(null)).toThrow();
t.throws(() => head(), 'head() throws an Error'); });
test('head(undefined) throws an Error', () => {
let start = new Date().getTime(); expect(head(undefined)).toThrow();
head([1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 1122, 32124, 23232]); });
let end = new Date().getTime(); test('head() throws an Error', () => {
test('head([1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 1122, 32124, 23232]) takes less than 2s to run', () => { expect(head()).toThrow();
});
let start = new Date().getTime();
head([1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 1122, 32124, 23232]);
let end = new Date().getTime();
test('head([1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 1122, 32124, 23232]) takes less than 2s to run', () => {
expect((end - start) < 2000).toBeTruthy(); expect((end - start) < 2000).toBeTruthy();
}); });

View File

@ -1,17 +1,15 @@
const expect = require('expect'); const expect = require('expect');
const hexToRGB = require('./hexToRGB.js'); const hexToRGB = require('./hexToRGB.js');
test('hexToRGB is a Function', () => {
test('hexToRGB is a Function', () => {
expect(hexToRGB).toBeInstanceOf(Function); expect(hexToRGB).toBeInstanceOf(Function);
}); });
test('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)') expect(hexToRGB('#27ae60ff')).toBe('rgba(39, 174, 96, 255)');
}); });
test('Converts a color code to a rgb() or rgba() string', () => { test('Converts a color code to a rgb() or rgba() string', () => {
expect(hexToRGB('27ae60'), 'rgb(39, 174).toBe(96)') expect(hexToRGB('27ae60')).toBe('rgb(39, 174, 96)');
}); });
test('Converts a color code to a rgb() or rgba() string', () => { test('Converts a color code to a rgb() or rgba() string', () => {
expect(hexToRGB('#fff'), 'rgb(255, 255).toBe(255)') expect(hexToRGB('#fff')).toBe('rgb(255, 255, 255)');
}); });

View File

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

View File

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

View File

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

View File

@ -7,21 +7,20 @@ const httpGet = (url, callback, err = console.error) => {
request.send(); request.send();
}; };
test('httpGet is a Function', () => {
test('httpGet is a Function', () => {
expect(httpGet).toBeInstanceOf(Function); expect(httpGet).toBeInstanceOf(Function);
}); });
httpGet('https: test('Sends a GET request', () => {
t.deepEqual(JSON.parse(response), { httpGet('https://jsonplaceholder.typicode.com/posts/1', response => {
expect(JSON.parse(response)),toEqual({
userId: 1, userId: 1,
id: 1, id: 1,
title: title:
'sunt aut facere repellat provident occaecati excepturi optio reprehenderit', 'sunt aut facere repellat provident occaecati excepturi optio reprehenderit',
body: body:
'quia et suscipit\nsuscipit recusandae consequuntur expedita et cum\nreprehenderit molestiae ut ut quas totam\nnostrum rerum est autem sunt rem eveniet architecto', 'quia et suscipit\nsuscipit recusandae consequuntur expedita et cum\nreprehenderit molestiae ut ut quas totam\nnostrum rerum est autem sunt rem eveniet architecto',
}, 'Sends a GET request'); });
});
var Url = require("url"); var Url = require("url");
var spawn = require("child_process").spawn; var spawn = require("child_process").spawn;

View File

@ -8,21 +8,20 @@ const httpPost = (url, data, callback, err = console.error) => {
request.send(data); request.send(data);
}; };
test('httpPost is a Function', () => { test('httpPost is a Function', () => {
expect(httpPost).toBeInstanceOf(Function); expect(httpPost).toBeInstanceOf(Function);
}); });
const data = { const data = {
title: 'foo', title: 'foo',
body: 'bar', body: 'bar',
userId: 1 userId: 1
}; };
httpPost('https: test('Sends a POST request', () => {
test('Sends a POST request', () => { httpPost('https://jsonplaceholder.typicode.com/posts', JSON.stringify(data), response => {
expect(JSON.parse(response).id, 101).toEqual() expect(JSON.parse(response).id).toEqual(101);
});
}); });
var Url = require("url"); var Url = require("url");
var spawn = require("child_process").spawn; var spawn = require("child_process").spawn;
var fs = require("fs"); var fs = require("fs");

View File

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

View File

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

View File

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