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 gcd = require('./gcd.js');
test('gcd is a Function', () => {
expect(gcd).toBeInstanceOf(Function);
});
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', () => {
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 geometricProgression = require('./geometricProgression.js');
test('geometricProgression is a Function', () => {
expect(geometricProgression).toBeInstanceOf(Function);
});
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', () => {
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', () => {
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,7 +1,6 @@
const expect = require('expect');
const get = require('./get.js');
test('get is a Function', () => {
expect(get).toBeInstanceOf(Function);
});
@ -9,5 +8,3 @@ const get = require('./get.js');
test('Retrieve a property indicated by the selector from an object.', () => {
expect(get(obj, 'selector.to.val')).toEqual(['val to get'])
});

View File

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

View File

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

View File

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

View File

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

View File

@ -1,11 +1,9 @@
const expect = require('expect');
const getType = require('./getType.js');
test('getType is a Function', () => {
expect(getType).toBeInstanceOf(Function);
});
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 getURLParameters = require('./getURLParameters.js');
test('getURLParameters is a 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 groupBy = require('./groupBy.js');
test('groupBy is a Function', () => {
expect(groupBy).toBeInstanceOf(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', () => {
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 hammingDistance = require('./hammingDistance.js');
test('hammingDistance is a Function', () => {
expect(hammingDistance).toBeInstanceOf(Function);
});
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 hasClass = require('./hasClass.js');
test('hasClass is a Function', () => {
expect(hasClass).toBeInstanceOf(Function);
});

View File

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

View File

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

View File

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

View File

@ -1,17 +1,15 @@
const expect = require('expect');
const hexToRGB = require('./hexToRGB.js');
test('hexToRGB is a Function', () => {
expect(hexToRGB).toBeInstanceOf(Function);
});
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', () => {
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', () => {
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 hide = require('./hide.js');
test('hide is a Function', () => {
expect(hide).toBeInstanceOf(Function);
});

View File

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

View File

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

View File

@ -7,21 +7,20 @@ const httpGet = (url, callback, err = console.error) => {
request.send();
};
test('httpGet is a Function', () => {
expect(httpGet).toBeInstanceOf(Function);
});
httpGet('https:
t.deepEqual(JSON.parse(response), {
test('Sends a GET request', () => {
httpGet('https://jsonplaceholder.typicode.com/posts/1', response => {
expect(JSON.parse(response)),toEqual({
userId: 1,
id: 1,
title:
'sunt aut facere repellat provident occaecati excepturi optio reprehenderit',
body:
'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 spawn = require("child_process").spawn;

View File

@ -16,12 +16,11 @@ const httpPost = (url, data, callback, err = console.error) => {
body: 'bar',
userId: 1
};
httpPost('https:
test('Sends a POST request', () => {
expect(JSON.parse(response).id, 101).toEqual()
httpPost('https://jsonplaceholder.typicode.com/posts', JSON.stringify(data), response => {
expect(JSON.parse(response).id).toEqual(101);
});
});
var Url = require("url");
var spawn = require("child_process").spawn;

View File

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

View File

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

View File

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