Merge pull request #682 from Chalarangelo/jest-test

[ENHANCEMENT] Migrated tests from tape to jest
This commit is contained in:
Angelos Chalaris
2018-06-18 21:21:42 +03:00
committed by GitHub
337 changed files with 11784 additions and 7558 deletions

2
.gitignore vendored
View File

@ -8,3 +8,5 @@ test.sh
dist/flavor\.min\.css
dist/flavor\.css
test_old/

5194
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -4,7 +4,8 @@
"chalk": "^2.4.1",
"fs-extra": "^6.0.0",
"html-minifier": "^3.5.15",
"jsdom": "^11.10.0",
"jest": "^23.1.0",
"jest-tap-reporter": "^1.9.0",
"markdown-it": "^8.4.1",
"mini.css": "^2.3.7",
"node-sass": "^4.9.0",
@ -14,9 +15,7 @@
"rollup": "^0.58.2",
"rollup-plugin-babel": "^3.0.4",
"rollup-plugin-babel-minify": "^4.0.0",
"semistandard": "^12.0.1",
"tap-spec": "^4.1.1",
"tape": "^4.9.0"
"semistandard": "^12.0.1"
},
"name": "30-seconds-of-code",
"description": "A collection of useful JavaScript snippets.",
@ -32,7 +31,7 @@
"extractor": "node ./scripts/extract.js",
"packager": "node ./scripts/module.js",
"localizer": "node ./scripts/localize.js",
"test": "tape test/**/*.test.js | tap-spec"
"test": "jest --verbose"
},
"repository": {
"type": "git",
@ -49,5 +48,17 @@
"url": "https://github.com/Chalarangelo/30-seconds-of-code/issues"
},
"homepage": "https://github.com/Chalarangelo/30-seconds-of-code#readme",
"dependencies": {}
"dependencies": {},
"jest": {
"reporters": [
[
"jest-tap-reporter",
{
"logLevel": "INFO",
"showInternalStackTraces": false,
"filePath": "test/testlog"
}
]
]
}
}

View File

@ -5,7 +5,7 @@
// Load modules
const fs = require('fs-extra'), path = require('path');
const child_process = require('child_process');
const childProcess = require('child_process');
const chalk = require('chalk');
const util = require('./util');
if(util.isTravisCI() && process.env['TRAVIS_EVENT_TYPE'] !== 'cron' && process.env['TRAVIS_EVENT_TYPE'] !== 'api') {
@ -64,16 +64,10 @@ snippetFiles
// Export template for snippetName.test.js which generates a example test & other information
const exportTest = [
`const test = require('tape');`,
`const expect = require('expect');`,
`const ${fileName} = require('./${fileName}.js');`,
`\ntest('Testing ${fileName}', (t) => {`,
` //For more information on all the methods supported by tape\n //Please go to https://github.com/substack/tape`,
` t.true(typeof ${fileName} === 'function', '${fileName} is a Function');`,
` //t.deepEqual(${fileName}(args..), 'Expected');`,
` //t.equal(${fileName}(args..), 'Expected');`,
` //t.false(${fileName}(args..), 'Expected');`,
` //t.throws(${fileName}(args..), 'Expected');`,
` t.end();`,
`\ntest('${fileName} is a Function', () => {`,
` expect(${fileName}).toBeInstanceOf(Function);`,
`});`
].join('\n');
@ -90,7 +84,7 @@ snippetFiles
});
try {
fs.writeFileSync(path.join(TEST_PATH,'testlog'),`Test log for: ${new Date().toString()}\n`);
child_process.execSync(`npm test >> ${TEST_PATH}/testlog`);
childProcess.execSync(`npm test`);
}
catch (e) {
fs.appendFileSync(path.join(TEST_PATH,'testlog'));

View File

@ -1,13 +1,6 @@
const test = require('tape');
const expect = require('expect');
const JSONToDate = require('./JSONToDate.js');
test('Testing JSONToDate', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof JSONToDate === 'function', 'JSONToDate is a Function');
//t.deepEqual(JSONToDate(args..), 'Expected');
//t.equal(JSONToDate(args..), 'Expected');
//t.false(JSONToDate(args..), 'Expected');
//t.throws(JSONToDate(args..), 'Expected');
t.end();
});
test('JSONToDate is a Function', () => {
expect(JSONToDate).toBeInstanceOf(Function);
});

View File

@ -1,14 +1,6 @@
const test = require('tape');
const expect = require('expect');
const JSONToFile = require('./JSONToFile.js');
test('Testing JSONToFile', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof JSONToFile === 'function', 'JSONToFile is a Function');
t.pass('Tested on 09/02/2018 by @chalarangelo');
//t.deepEqual(JSONToFile(args..), 'Expected');
//t.equal(JSONToFile(args..), 'Expected');
//t.false(JSONToFile(args..), 'Expected');
//t.throws(JSONToFile(args..), 'Expected');
t.end();
test('JSONToFile is a Function', () => {
expect(JSONToFile).toBeInstanceOf(Function);
});

View File

@ -1,14 +1,9 @@
const test = require('tape');
const expect = require('expect');
const RGBToHex = require('./RGBToHex.js');
test('Testing RGBToHex', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof RGBToHex === 'function', 'RGBToHex is a Function');
t.equal(RGBToHex(255, 165, 1), 'ffa501', "Converts the values of RGB components to a color code.");
//t.deepEqual(RGBToHex(args..), 'Expected');
//t.equal(RGBToHex(args..), 'Expected');
//t.false(RGBToHex(args..), 'Expected');
//t.throws(RGBToHex(args..), 'Expected');
t.end();
});
test('RGBToHex is a Function', () => {
expect(RGBToHex).toBeInstanceOf(Function);
});
test('Converts the values of RGB components to a color code.', () => {
expect(RGBToHex(255, 165, 1)).toBe('ffa501');
});

View File

@ -1,15 +1,12 @@
const test = require('tape');
const expect = require('expect');
const URLJoin = require('./URLJoin.js');
test('Testing URLJoin', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof URLJoin === 'function', 'URLJoin is a Function');
t.equal(URLJoin('http://www.google.com', 'a', '/b/cd', '?foo=123', '?bar=foo'), 'http://www.google.com/a/b/cd?foo=123&bar=foo', 'Returns proper URL');
t.equal(URLJoin('file://www.google.com', 'a', '/b/cd', '?foo=123', '?bar=foo'), 'file:///www.google.com/a/b/cd?foo=123&bar=foo', 'Returns proper URL');
//t.deepEqual(URLJoin(args..), 'Expected');
//t.equal(URLJoin(args..), 'Expected');
//t.false(URLJoin(args..), 'Expected');
//t.throws(URLJoin(args..), 'Expected');
t.end();
test('URLJoin is a Function', () => {
expect(URLJoin).toBeInstanceOf(Function);
});
test('Returns proper URL', () => {
expect(URLJoin('http://www.google.com', 'a', '/b/cd', '?foo=123', '?bar=foo')).toBe('http://www.google.com/a/b/cd?foo=123&bar=foo');
});
test('Returns proper URL', () => {
expect(URLJoin('file://www.google.com', 'a', '/b/cd', '?foo=123', '?bar=foo')).toBe('file:///www.google.com/a/b/cd?foo=123&bar=foo');
});

View File

@ -1,14 +1,6 @@
const test = require('tape');
const expect = require('expect');
const UUIDGeneratorBrowser = require('./UUIDGeneratorBrowser.js');
test('Testing UUIDGeneratorBrowser', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof UUIDGeneratorBrowser === 'function', 'UUIDGeneratorBrowser is a Function');
t.pass('Tested 09/02/2018 by @chalarangelo');
//t.deepEqual(UUIDGeneratorBrowser(args..), 'Expected');
//t.equal(UUIDGeneratorBrowser(args..), 'Expected');
//t.false(UUIDGeneratorBrowser(args..), 'Expected');
//t.throws(UUIDGeneratorBrowser(args..), 'Expected');
t.end();
test('UUIDGeneratorBrowser is a Function', () => {
expect(UUIDGeneratorBrowser).toBeInstanceOf(Function);
});

View File

@ -1,16 +1,13 @@
const test = require('tape');
const expect = require('expect');
const UUIDGeneratorNode = require('./UUIDGeneratorNode.js');
test('Testing UUIDGeneratorNode', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof UUIDGeneratorNode === 'function', 'UUIDGeneratorNode is a Function');
const uuid = UUIDGeneratorNode();
t.deepEqual([uuid[8], uuid[13], uuid[18], uuid[23]], ['-', '-', '-', '-'], 'Contains dashes in the proper places');
t.true(/^[0-9A-Fa-f-]+$/.test(uuid), 'Only contains hexadecimal digits');
//t.deepEqual(UUIDGeneratorNode(args..), 'Expected');
//t.equal(UUIDGeneratorNode(args..), 'Expected');
//t.false(UUIDGeneratorNode(args..), 'Expected');
//t.throws(UUIDGeneratorNode(args..), 'Expected');
t.end();
test('UUIDGeneratorNode is a Function', () => {
expect(UUIDGeneratorNode).toBeInstanceOf(Function);
});
const uuid = UUIDGeneratorNode();
test('Contains dashes in the proper places', () => {
expect([uuid[8], uuid[13], uuid[18], uuid[23]]).toEqual(['-', '-', '-', '-']);
});
test('Only contains hexadecimal digits', () => {
expect(/^[0-9A-Fa-f-]+$/.test(uuid)).toBeTruthy();
});

View File

@ -1,21 +1,30 @@
const test = require('tape');
const expect = require('expect');
const all = require('./all.js');
test('Testing all', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof all === 'function', 'all is a Function');
t.true(all([4,1,2,3]), 'Returns true for arrays with no falsey values');
t.false(all([0,1]), 'Returns false for arrays with 0');
t.false(all([NaN,1]), 'Returns false for arrays with NaN');
t.false(all([undefined,1]), 'Returns false for arrays with undefined');
t.false(all([null,1]), 'Returns false for arrays with null');
t.false(all(['',1]), 'Returns false for arrays with empty strings');
t.true(all([4,1,2,3], x => x >= 1), 'Returns true with predicate function');
t.false(all([0,1], x => x >= 1), 'Returns false with a predicate function');
//t.deepEqual(all(args..), 'Expected');
//t.equal(all(args..), 'Expected');
//t.false(all(args..), 'Expected');
//t.throws(all(args..), 'Expected');
t.end();
test('all is a Function', () => {
expect(all).toBeInstanceOf(Function);
});
test('Returns true for arrays with no falsey values', () => {
expect(all([4,1,2,3])).toBeTruthy();
});
test('Returns false for arrays with 0', () => {
expect(all([0,1])).toBeFalsy();
});
test('Returns false for arrays with NaN', () => {
expect(all([NaN,1])).toBeFalsy();
});
test('Returns false for arrays with undefined', () => {
expect(all([undefined,1])).toBeFalsy();
});
test('Returns false for arrays with null', () => {
expect(all([null,1])).toBeFalsy();
});
test('Returns false for arrays with empty strings', () => {
expect(all(['',1])).toBeFalsy();
});
test('Returns true with predicate function', () => {
expect(all([4,1,2,3], x => x >= 1)).toBeTruthy();
});
test('Returns false with a predicate function', () => {
expect(all([0,1], x => x >= 1)).toBeFalsy();
});

View File

@ -1,18 +1,21 @@
const test = require('tape');
const expect = require('expect');
const any = require('./any.js');
test('Testing any', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof any === 'function', 'any is a Function');
t.true(any([0,1,2,3]), 'Returns true for arrays with at least one truthy value');
t.false(any([0,0]), 'Returns false for arrays with no truthy values');
t.false(any([NaN,0,undefined,null,'']), 'Returns false for arrays with no truthy values');
t.true(any([4,1,0,3], x => x >= 1), 'Returns true with predicate function');
t.false(any([0,1], x => x < 0), 'Returns false with a predicate function');
//t.deepEqual(any(args..), 'Expected');
//t.equal(any(args..), 'Expected');
//t.false(any(args..), 'Expected');
//t.throws(any(args..), 'Expected');
t.end();
test('any is a Function', () => {
expect(any).toBeInstanceOf(Function);
});
test('Returns true for arrays with at least one truthy value', () => {
expect(any([0,1,2,3])).toBeTruthy();
});
test('Returns false for arrays with no truthy values', () => {
expect(any([0,0])).toBeFalsy();
});
test('Returns false for arrays with no truthy values', () => {
expect(any([NaN,0,undefined,null,''])).toBeFalsy();
});
test('Returns true with predicate function', () => {
expect(any([4,1,0,3], x => x >= 1)).toBeTruthy();
});
test('Returns false with a predicate function', () => {
expect(any([0,1], x => x < 0)).toBeFalsy();
});

View File

@ -1,17 +1,18 @@
const test = require('tape');
const expect = require('expect');
const approximatelyEqual = require('./approximatelyEqual.js');
test('Testing approximatelyEqual', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof approximatelyEqual === 'function', 'approximatelyEqual is a Function');
t.true(approximatelyEqual(Math.PI / 2.0 , 1.5708), 'Works for PI / 2');
t.true(approximatelyEqual(0.1 + 0.2, 0.3), 'Works for 0.1 + 0.2 === 0.3');
t.true(approximatelyEqual(0.5, 0.5), 'Works for exactly equal values');
t.true(approximatelyEqual(0.501, 0.5, 0.1), 'Works for a custom epsilon');
//t.deepEqual(approximatelyEqual(args..), 'Expected');
//t.equal(approximatelyEqual(args..), 'Expected');
//t.false(approximatelyEqual(args..), 'Expected');
//t.throws(approximatelyEqual(args..), 'Expected');
t.end();
test('approximatelyEqual is a Function', () => {
expect(approximatelyEqual).toBeInstanceOf(Function);
});
test('Works for PI / 2', () => {
expect(approximatelyEqual(Math.PI / 2.0 , 1.5708)).toBeTruthy();
});
test('Works for 0.1 + 0.2 === 0.3', () => {
expect(approximatelyEqual(0.1 + 0.2, 0.3)).toBeTruthy();
});
test('Works for exactly equal values', () => {
expect(approximatelyEqual(0.5, 0.5)).toBeTruthy();
});
test('Works for a custom epsilon', () => {
expect(approximatelyEqual(0.501, 0.5, 0.1)).toBeTruthy();
});

View File

@ -1,14 +1,6 @@
const test = require('tape');
const expect = require('expect');
const arrayToHtmlList = require('./arrayToHtmlList.js');
test('Testing arrayToHtmlList', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof arrayToHtmlList === 'function', 'arrayToHtmlList is a Function');
t.pass('Tested by @chalarangelo on 16/02/2018');
//t.deepEqual(arrayToHtmlList(args..), 'Expected');
//t.equal(arrayToHtmlList(args..), 'Expected');
//t.false(arrayToHtmlList(args..), 'Expected');
//t.throws(arrayToHtmlList(args..), 'Expected');
t.end();
test('arrayToHtmlList is a Function', () => {
expect(arrayToHtmlList).toBeInstanceOf(Function);
});

View File

@ -1,15 +1,10 @@
const test = require('tape');
const expect = require('expect');
const ary = require('./ary.js');
test('Testing ary', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof ary === 'function', 'ary is a Function');
const firstTwoMax = ary(Math.max, 2);
t.deepEquals([[2, 6, 'a'], [8, 4, 6], [10]].map(x => firstTwoMax(...x)), [6, 8, 10], 'Discards arguments with index >=n');
//t.deepEqual(ary(args..), 'Expected');
//t.equal(ary(args..), 'Expected');
//t.false(ary(args..), 'Expected');
//t.throws(ary(args..), 'Expected');
t.end();
test('ary is a Function', () => {
expect(ary).toBeInstanceOf(Function);
});
const firstTwoMax = ary(Math.max, 2);
test('Discards arguments with index >=n', () => {
expect([[2, 6, 'a'], [8, 4, 6], [10]].map(x => firstTwoMax(...x))).toEqual([6, 8, 10]);
});

View File

@ -1,15 +1,12 @@
const test = require('tape');
const expect = require('expect');
const atob = require('./atob.js');
test('Testing atob', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof atob === 'function', 'atob is a Function');
t.equals(atob('Zm9vYmFy'), 'foobar', 'atob("Zm9vYmFy") equals "foobar"');
t.equals(atob('Z'), '', 'atob("Z") returns ""');
//t.deepEqual(atob(args..), 'Expected');
//t.equal(atob(args..), 'Expected');
//t.false(atob(args..), 'Expected');
//t.throws(atob(args..), 'Expected');
t.end();
test('atob is a Function', () => {
expect(atob).toBeInstanceOf(Function);
});
test('atob("Zm9vYmFy") equals "foobar"', () => {
expect(atob('Zm9vYmFy')).toBe('foobar');
});
test('atob("Z") returns ""', () => {
expect(atob('Z')).toBe('');
});

View File

@ -1,15 +1,12 @@
const test = require('tape');
const expect = require('expect');
const attempt = require('./attempt.js');
test('Testing attempt', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof attempt === 'function', 'attempt is a Function');
t.equals(attempt(() => 0), 0, 'Returns a value');
t.true(attempt(() => {throw new Error();}) instanceof Error, 'Returns an error');
//t.deepEqual(attempt(args..), 'Expected');
//t.equal(attempt(args..), 'Expected');
//t.false(attempt(args..), 'Expected');
//t.throws(attempt(args..), 'Expected');
t.end();
test('attempt is a Function', () => {
expect(attempt).toBeInstanceOf(Function);
});
test('Returns a value', () => {
expect(attempt(() => 0)).toBe(0);
});
test('Returns an error', () => {
expect(attempt(() => {throw new Error();})).toBeInstanceOf(Error);
});

View File

@ -1,24 +1,43 @@
const test = require('tape');
const expect = require('expect');
const average = require('./average.js');
test('Testing average', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof average === 'function', 'average is a Function');
t.true(average(true) === 1, 'average(true) returns 0');
t.true(average(false) === 0, 'average(false) returns 1');
t.equal(average(9, 1), 5, 'average(9, 1) returns 5');
t.equal(average(153, 44, 55, 64, 71, 1122, 322774, 2232, 23423, 234, 3631), 32163.909090909092, 'average(153, 44, 55, 64, 71, 1122, 322774, 2232, 23423, 234, 3631) returns 32163.909090909092 ');
t.equal(average(1, 2, 3), 2, 'average(1, 2, 3) returns 2');
t.equal(average(null), 0, 'average(null) returns 0');
t.true(isNaN(average(undefined)), 'average(1, 2, 3) returns NaN');
t.true(isNaN(average('String')), 'average(String) returns NaN');
t.true(isNaN(average({ a: 123})), 'average({ a: 123}) returns NaN');
t.true(isNaN(average([undefined, 0, 'string'])), 'average([undefined, 0, string]) returns NaN');
test('average is a Function', () => {
expect(average).toBeInstanceOf(Function);
});
test('average(true) returns 0', () => {
expect(average(true) === 1).toBeTruthy();
});
test('average(false) returns 1', () => {
expect(average(false) === 0).toBeTruthy();
});
test('average(9, 1) returns 5', () => {
expect(average(9, 1)).toBe(5);
});
test('average(153, 44, 55, 64, 71, 1122, 322774, 2232, 23423, 234, 3631) returns 32163.909090909092 ', () => {
expect(average(153, 44, 55, 64, 71, 1122, 322774, 2232, 23423, 234, 3631)).toBeCloseTo(32163.909090909092, 3);
});
test('average(1, 2, 3) returns 2', () => {
expect(average(1, 2, 3)).toBe(2);
});
test('average(null) returns 0', () => {
expect(average(null)).toBe(0);
});
test('average(1, 2, 3) returns NaN', () => {
expect(isNaN(average(undefined))).toBeTruthy();
});
test('average(String) returns NaN', () => {
expect(isNaN(average('String'))).toBeTruthy();
});
test('average({ a: 123}) returns NaN', () => {
expect(isNaN(average({ a: 123}))).toBeTruthy();
});
test('average([undefined, 0, string]) returns NaN', () => {
expect(isNaN(average([undefined, 0, 'string']))).toBeTruthy();
});
let start = new Date().getTime();
average(153, 44, 55, 64, 71, 1122, 322774, 2232, 23423, 234, 3631);
let end = new Date().getTime();
t.true((end - start) < 2000, 'average([1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 1122, 32124, 23232]) takes less than 2s to run');
t.end();
});
let start = new Date().getTime();
average(153, 44, 55, 64, 71, 1122, 322774, 2232, 23423, 234, 3631);
let end = new Date().getTime();
test('average([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,15 +1,12 @@
const test = require('tape');
const expect = require('expect');
const averageBy = require('./averageBy.js');
test('Testing averageBy', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof averageBy === 'function', 'averageBy is a Function');
t.equals(averageBy([{ n: 4 }, { n: 2 }, { n: 8 }, { n: 6 }], o => o.n), 5, 'Produces the right result with a function');
t.equals(averageBy([{ n: 4 }, { n: 2 }, { n: 8 }, { n: 6 }], 'n'), 5, 'Produces the right result with a property name');
//t.deepEqual(averageBy(args..), 'Expected');
//t.equal(averageBy(args..), 'Expected');
//t.false(averageBy(args..), 'Expected');
//t.throws(averageBy(args..), 'Expected');
t.end();
test('averageBy is a Function', () => {
expect(averageBy).toBeInstanceOf(Function);
});
test('Produces the right result with a function', () => {
expect(averageBy([{ n: 4 }, { n: 2 }, { n: 8 }, { n: 6 }], o => o.n)).toBe(5);
});
test('Produces the right result with a property name', () => {
expect(averageBy([{ n: 4 }, { n: 2 }, { n: 8 }, { n: 6 }], 'n')).toBe(5);
});

View File

@ -1,14 +1,9 @@
const test = require('tape');
const expect = require('expect');
const bifurcate = require('./bifurcate.js');
test('Testing bifurcate', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof bifurcate === 'function', 'bifurcate is a Function');
t.deepEqual(bifurcate([ 'beep', 'boop', 'foo', 'bar' ], [ true, true, false, true ]), [ ['beep', 'boop', 'bar'], ['foo'] ], 'Splits the collection into two groups');
//t.deepEqual(bifurcate(args..), 'Expected');
//t.equal(bifurcate(args..), 'Expected');
//t.false(bifurcate(args..), 'Expected');
//t.throws(bifurcate(args..), 'Expected');
t.end();
test('bifurcate is a Function', () => {
expect(bifurcate).toBeInstanceOf(Function);
});
test('Splits the collection into two groups', () => {
expect(bifurcate([ 'beep', 'boop', 'foo', 'bar' ], [ true, true, false, true ])).toEqual([ ['beep', 'boop', 'bar'], ['foo'] ]);
});

View File

@ -1,14 +1,9 @@
const test = require('tape');
const expect = require('expect');
const bifurcateBy = require('./bifurcateBy.js');
test('Testing bifurcateBy', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof bifurcateBy === 'function', 'bifurcateBy is a Function');
t.deepEqual(bifurcateBy([ 'beep', 'boop', 'foo', 'bar' ], x => x[0] === 'b'), [ ['beep', 'boop', 'bar'], ['foo'] ], 'Splits the collection into two groups');
//t.deepEqual(bifurcateBy(args..), 'Expected');
//t.equal(bifurcateBy(args..), 'Expected');
//t.false(bifurcateBy(args..), 'Expected');
//t.throws(bifurcateBy(args..), 'Expected');
t.end();
test('bifurcateBy is a Function', () => {
expect(bifurcateBy).toBeInstanceOf(Function);
});
test('Splits the collection into two groups', () => {
expect(bifurcateBy([ 'beep', 'boop', 'foo', 'bar' ], x => x[0] === 'b')).toEqual([ ['beep', 'boop', 'bar'], ['foo'] ]);
});

View File

@ -1,16 +1,18 @@
const test = require('tape');
const expect = require('expect');
const binarySearch = require('./binarySearch.js');
test('Testing binarySearch', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof binarySearch === 'function', 'binarySearch is a Function');
//t.deepEqual(binarySearch(args..), 'Expected');
t.equal(binarySearch([1, 4, 6, 7, 12, 13, 15, 18, 19, 20, 22, 24], 6), 2, 'Finds item in array');
t.equal(binarySearch([1, 4, 6, 7, 12, 13, 15, 18, 19, 20, 22, 24], 21), -1, 'Returns -1 when not found');
t.equal(binarySearch([], 21), -1, 'Works with empty arrays');
t.equal(binarySearch([1], 1), 0, "Works for one element arrays");
//t.false(binarySearch(args..), 'Expected');
//t.throws(binarySearch(args..), 'Expected');
t.end();
});
test('binarySearch is a Function', () => {
expect(binarySearch).toBeInstanceOf(Function);
});
test('Finds item in array', () => {
expect(binarySearch([1, 4, 6, 7, 12, 13, 15, 18, 19, 20, 22, 24], 6)).toBe(2);
});
test('Returns -1 when not found', () => {
expect(binarySearch([1, 4, 6, 7, 12, 13, 15, 18, 19, 20, 22, 24], 21)).toBe(-1);
});
test('Works with empty arrays', () => {
expect(binarySearch([], 21)).toBe(-1);
});
test('Works for one element arrays', () => {
expect(binarySearch([1], 1)).toBe(0);
});

View File

@ -1,19 +1,14 @@
const test = require('tape');
const expect = require('expect');
const bind = require('./bind.js');
test('Testing bind', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof bind === 'function', 'bind is a Function');
function greet(greeting, punctuation) {
return greeting + ' ' + this.user + punctuation;
}
const freddy = { user: 'fred' };
const freddyBound = bind(greet, freddy);
t.equals(freddyBound('hi', '!'),'hi fred!', 'Binds to an object context');
//t.deepEqual(bind(args..), 'Expected');
//t.equal(bind(args..), 'Expected');
//t.false(bind(args..), 'Expected');
//t.throws(bind(args..), 'Expected');
t.end();
test('bind is a Function', () => {
expect(bind).toBeInstanceOf(Function);
});
function greet(greeting, punctuation) {
return greeting + ' ' + this.user + punctuation;
}
const freddy = { user: 'fred' };
const freddyBound = bind(greet, freddy);
test('Binds to an object context', () => {
expect(freddyBound('hi', '!')).toBe('hi fred!');
});

View File

@ -1,21 +1,16 @@
const test = require('tape');
const expect = require('expect');
const bindAll = require('./bindAll.js');
test('Testing bindAll', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof bindAll === 'function', 'bindAll is a Function');
var view = {
label: 'docs',
'click': function() {
return 'clicked ' + this.label;
}
};
bindAll(view, 'click');
t.equal(view.click(), 'clicked docs', 'Binds to an object context');
//t.deepEqual(bindAll(args..), 'Expected');
//t.equal(bindAll(args..), 'Expected');
//t.false(bindAll(args..), 'Expected');
//t.throws(bindAll(args..), 'Expected');
t.end();
test('bindAll is a Function', () => {
expect(bindAll).toBeInstanceOf(Function);
});
var view = {
label: 'docs',
'click': function() {
return 'clicked ' + this.label;
}
};
bindAll(view, 'click');
test('Binds to an object context', () => {
expect(view.click()).toBe('clicked docs');
});

View File

@ -1,21 +1,16 @@
const test = require('tape');
const expect = require('expect');
const bindKey = require('./bindKey.js');
test('Testing bindKey', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof bindKey === 'function', 'bindKey is a Function');
const freddy = {
user: 'fred',
greet: function(greeting, punctuation) {
return greeting + ' ' + this.user + punctuation;
}
};
const freddyBound = bindKey(freddy, 'greet');
t.equal(freddyBound('hi', '!'), 'hi fred!', 'Binds function to an object context');
//t.deepEqual(bindKey(args..), 'Expected');
//t.equal(bindKey(args..), 'Expected');
//t.false(bindKey(args..), 'Expected');
//t.throws(bindKey(args..), 'Expected');
t.end();
test('bindKey is a Function', () => {
expect(bindKey).toBeInstanceOf(Function);
});
const freddy = {
user: 'fred',
greet: function(greeting, punctuation) {
return greeting + ' ' + this.user + punctuation;
}
};
const freddyBound = bindKey(freddy, 'greet');
test('Binds function to an object context', () => {
expect(freddyBound('hi', '!')).toBe('hi fred!');
});

View File

@ -1,18 +1,21 @@
const test = require('tape');
const expect = require('expect');
const binomialCoefficient = require('./binomialCoefficient.js');
test('Testing binomialCoefficient', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof binomialCoefficient === 'function', 'binomialCoefficient is a Function');
t.equal(binomialCoefficient(8, 2), 28, 'Returns the appropriate value');
t.equal(binomialCoefficient(0, 0), 1, 'Returns the appropriate value');
t.equal(binomialCoefficient(5, 3), 10, 'Returns the appropriate value');
t.true(Number.isNaN(binomialCoefficient(NaN, 3)), 'Returns NaN');
t.true(Number.isNaN(binomialCoefficient(5, NaN)), 'Returns NaN');
//t.deepEqual(binomialCoefficient(args..), 'Expected');
//t.equal(binomialCoefficient(args..), 'Expected');
//t.false(binomialCoefficient(args..), 'Expected');
//t.throws(binomialCoefficient(args..), 'Expected');
t.end();
test('binomialCoefficient is a Function', () => {
expect(binomialCoefficient).toBeInstanceOf(Function);
});
test('Returns the appropriate value', () => {
expect(binomialCoefficient(8, 2)).toBe(28);
});
test('Returns the appropriate value', () => {
expect(binomialCoefficient(0, 0)).toBe(1);
});
test('Returns the appropriate value', () => {
expect(binomialCoefficient(5, 3)).toBe(10);
});
test('Returns NaN', () => {
expect(Number.isNaN(binomialCoefficient(NaN, 3))).toBeTruthy();
});
test('Returns NaN', () => {
expect(Number.isNaN(binomialCoefficient(5, NaN))).toBeTruthy();
});

View File

@ -1,14 +1,6 @@
const test = require('tape');
const expect = require('expect');
const bottomVisible = require('./bottomVisible.js');
test('Testing bottomVisible', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof bottomVisible === 'function', 'bottomVisible is a Function');
t.pass('Tested on 09/02/2018 by @chalarangelo');
//t.deepEqual(bottomVisible(args..), 'Expected');
//t.equal(bottomVisible(args..), 'Expected');
//t.false(bottomVisible(args..), 'Expected');
//t.throws(bottomVisible(args..), 'Expected');
t.end();
test('bottomVisible is a Function', () => {
expect(bottomVisible).toBeInstanceOf(Function);
});

View File

@ -1,14 +1,9 @@
const test = require('tape');
const expect = require('expect');
const btoa = require('./btoa.js');
test('Testing btoa', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof btoa === 'function', 'btoa is a Function');
t.equals(btoa('foobar'), 'Zm9vYmFy', 'btoa("foobar") equals "Zm9vYmFy"');
//t.deepEqual(btoa(args..), 'Expected');
//t.equal(btoa(args..), 'Expected');
//t.false(btoa(args..), 'Expected');
//t.throws(btoa(args..), 'Expected');
t.end();
test('btoa is a Function', () => {
expect(btoa).toBeInstanceOf(Function);
});
test('btoa("foobar") equals "Zm9vYmFy"', () => {
expect(btoa('foobar')).toBe('Zm9vYmFy');
});

View File

@ -1,5 +1,4 @@
const test = require('tape');
// Custom implementation of Blob for the requirements of this snippet.
const expect = require('expect');
const Blob = class{
constructor(s) {
return {
@ -7,24 +6,17 @@ const Blob = class{
};
}
};
// const byteSize = require('./byteSize.js');
// Override
const byteSize = str => new Blob([str]).size;
test('Testing byteSize', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof byteSize === 'function', 'byteSize is a Function');
t.equal(byteSize('a'), 1, 'Works for a single letter');
t.equal(byteSize('Hello World'), 11, 'Works for a common string');
t.equal(byteSize('😀'), 4, 'Works for emoji');
// Blob is not part of Node apparently?
//t.equal(byteSize('Hello World'), 11, 'Works for text');
//t.equal(byteSize('😀'), 4, 'Works for emojis');
// Works only in browser
// t.equal(byteSize('Hello World'), 11, "Returns the length of a string in bytes");
//t.deepEqual(byteSize(args..), 'Expected');
//t.equal(byteSize(args..), 'Expected');
//t.false(byteSize(args..), 'Expected');
//t.throws(byteSize(args..), 'Expected');
t.end();
test('byteSize is a Function', () => {
expect(byteSize).toBeInstanceOf(Function);
});
test('Works for a single letter', () => {
expect(byteSize('a')).toBe(1);
});
test('Works for a common string', () => {
expect(byteSize('Hello World')).toBe(11);
});
test('Works for emoji', () => {
expect(byteSize('😀')).toBe(4);
});

View File

@ -1,13 +1,9 @@
const test = require('tape');
const expect = require('expect');
const call = require('./call.js');
test('Testing call', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof call === 'function', 'call is a Function');
//t.deepEqual(call(args..), 'Expected');
t.looseEqual(call('map', x => x * 2)([1, 2, 3]), [2, 4, 6], 'Calls function on given object');
//t.false(call(args..), 'Expected');
//t.throws(call(args..), 'Expected');
t.end();
});
test('call is a Function', () => {
expect(call).toBeInstanceOf(Function);
});
test('Calls function on given object', () => {
expect(call('map', x => x * 2)([1, 2, 3])).toEqual([2, 4, 6]);
});

View File

@ -1,17 +1,18 @@
const test = require('tape');
const expect = require('expect');
const capitalize = require('./capitalize.js');
test('Testing capitalize', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof capitalize === 'function', 'capitalize is a Function');
t.equal(capitalize('fooBar'), 'FooBar', "Capitalizes the first letter of a string");
t.equal(capitalize('fooBar', true), 'Foobar', "Capitalizes the first letter of a string");
t.equal(capitalize('#!#', true), '#!#', "Works with characters");
t.equal(capitalize('a', true), 'A', "Works with single character words");
//t.deepEqual(capitalize(args..), 'Expected');
//t.equal(capitalize(args..), 'Expected');
//t.false(capitalize(args..), 'Expected');
//t.throws(capitalize(args..), 'Expected');
t.end();
});
test('capitalize is a Function', () => {
expect(capitalize).toBeInstanceOf(Function);
});
test('Capitalizes the first letter of a string', () => {
expect(capitalize('fooBar')).toBe('FooBar');
});
test('Capitalizes the first letter of a string', () => {
expect(capitalize('fooBar', true)).toBe('Foobar');
});
test('Works with characters', () => {
expect(capitalize('#!#', true)).toBe('#!#');
});
test('"Works with single character words', () => {
expect(capitalize('a', true)).toBe('A');
});

View File

@ -1,16 +1,15 @@
const test = require('tape');
const expect = require('expect');
const capitalizeEveryWord = require('./capitalizeEveryWord.js');
test('Testing capitalizeEveryWord', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof capitalizeEveryWord === 'function', 'capitalizeEveryWord is a Function');
t.equal(capitalizeEveryWord('hello world!'), 'Hello World!', "Capitalizes the first letter of every word in a string");
t.equal(capitalizeEveryWord('$# @!'), '$# @!', "Works with characters");
t.equal(capitalizeEveryWord('a'), 'A', "Works with one word string");
//t.deepEqual(capitalizeEveryWord(args..), 'Expected');
//t.equal(capitalizeEveryWord(args..), 'Expected');
//t.false(capitalizeEveryWord(args..), 'Expected');
//t.throws(capitalizeEveryWord(args..), 'Expected');
t.end();
});
test('capitalizeEveryWord is a Function', () => {
expect(capitalizeEveryWord).toBeInstanceOf(Function);
});
test('Capitalizes the first letter of every word in a string', () => {
expect(capitalizeEveryWord('hello world!')).toBe('Hello World!');
});
test('Works with characters', () => {
expect(capitalizeEveryWord('$# @!')).toBe('$# @!');
});
test('Works with one word string', () => {
expect(capitalizeEveryWord('a')).toBe('A');
});

View File

@ -1,18 +1,21 @@
const test = require('tape');
const expect = require('expect');
const castArray = require('./castArray.js');
test('Testing castArray', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof castArray === 'function', 'castArray is a Function');
t.deepEqual(castArray(1), [1], 'Works for single values');
t.deepEqual(castArray([1]), [1], 'Works for arrays with one value');
t.deepEqual(castArray([1,2,3]), [1,2,3], 'Works for arrays with multiple value');
t.deepEqual(castArray('test'), ['test'], 'Works for strings');
t.deepEqual(castArray({}), [{}], 'Works for objects');
//t.deepEqual(castArray(args..), 'Expected');
//t.equal(castArray(args..), 'Expected');
//t.false(castArray(args..), 'Expected');
//t.throws(castArray(args..), 'Expected');
t.end();
test('castArray is a Function', () => {
expect(castArray).toBeInstanceOf(Function);
});
test('Works for single values', () => {
expect(castArray(1)).toEqual([1]);
});
test('Works for arrays with one value', () => {
expect(castArray([1])).toEqual([1]);
});
test('Works for arrays with multiple value', () => {
expect(castArray([1,2,3])).toEqual( [1,2,3]);
});
test('Works for strings', () => {
expect(castArray('test')).toEqual(['test']);
});
test('Works for objects', () => {
expect(castArray({})).toEqual([{}]);
});

View File

@ -1,10 +1,11 @@
const test = require('tape');
const expect = require('expect');
const chainAsync = require('./chainAsync.js');
test('Testing chainAsync', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof chainAsync === 'function', 'chainAsync is a Function');
test('chainAsync is a Function', () => {
expect(chainAsync).toBeInstanceOf(Function);
});
test('Calls all functions in an array', () => {
chainAsync([
next => {
next();
@ -15,13 +16,7 @@ test('Testing chainAsync', (t) => {
})();
},
next => {
t.pass("Calls all functions in an array");
expect(true).toBeTruthy();
}
]);
// // Ensure we wait for the 2nd assertion to be made
// t.plan(2);
//t.false(chainAsync(args..), 'Expected');
//t.throws(chainAsync(args..), 'Expected');
t.end();
});

View File

@ -1,22 +1,36 @@
const test = require('tape');
const expect = require('expect');
const chunk = require('./chunk.js');
test('Testing chunk', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof chunk === 'function', 'chunk is a 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]] ");
t.deepEqual(chunk([]), [], 'chunk([]) returns []');
t.deepEqual(chunk(123), [], 'chunk(123) returns []');
t.deepEqual(chunk({ a: 123}), [], 'chunk({ a: 123}) returns []');
t.deepEqual(chunk('string', 2), [ 'st', 'ri', 'ng' ], 'chunk(string, 2) returns [ st, ri, ng ]');
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();
t.true((end - start) < 2000, 'chunk(This is a string, 2) takes less than 2s to run');
t.end();
test('chunk is a Function', () => {
expect(chunk).toBeInstanceOf(Function);
});
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([]) returns []', () => {
expect(chunk([])).toEqual([]);
});
test('chunk(123) returns []', () => {
expect(chunk(123)).toEqual([]);
});
test('chunk({ a: 123}) returns []', () => {
expect(chunk({ a: 123})).toEqual([]);
});
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();
});

View File

@ -1,14 +1,9 @@
const test = require('tape');
const expect = require('expect');
const clampNumber = require('./clampNumber.js');
test('Testing clampNumber', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof clampNumber === 'function', 'clampNumber is a Function');
t.equal(clampNumber(2, 3, 5), 3, "Clamps num within the inclusive range specified by the boundary values a and b");
//t.deepEqual(clampNumber(args..), 'Expected');
//t.equal(clampNumber(args..), 'Expected');
//t.false(clampNumber(args..), 'Expected');
//t.throws(clampNumber(args..), 'Expected');
t.end();
});
test('clampNumber is a Function', () => {
expect(clampNumber).toBeInstanceOf(Function);
});
test('Clamps num within the inclusive range specified by the boundary values a and b', () => {
expect(clampNumber(2, 3, 5)).toBe(3);
});

View File

@ -1,15 +1,10 @@
const test = require('tape');
const expect = require('expect');
const cleanObj = require('./cleanObj.js');
test('Testing cleanObj', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof cleanObj === 'function', 'cleanObj is a Function');
const testObj = { a: 1, b: 2, children: { a: 1, b: 2 } };
t.deepEqual(cleanObj(testObj, ['a'], 'children'), { a: 1, children : { a: 1}}, "Removes any properties except the ones specified from a JSON object");
//t.deepEqual(cleanObj(args..), 'Expected');
//t.equal(cleanObj(args..), 'Expected');
//t.false(cleanObj(args..), 'Expected');
//t.throws(cleanObj(args..), 'Expected');
t.end();
});
test('cleanObj is a Function', () => {
expect(cleanObj).toBeInstanceOf(Function);
});
const testObj = { a: 1, b: 2, children: { a: 1, b: 2 } };
test('Removes any properties except the ones specified from a JSON object', () => {
expect(cleanObj(testObj, ['a'], 'children')).toEqual({ a: 1, children : { a: 1}});
});

View File

@ -1,15 +1,10 @@
const test = require('tape');
const expect = require('expect');
const cloneRegExp = require('./cloneRegExp.js');
test('Testing cloneRegExp', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof cloneRegExp === 'function', 'cloneRegExp is a Function');
const rgTest = /./g;
t.notEqual(cloneRegExp(rgTest), rgTest, 'Clones regular expressions properly');
//t.deepEqual(cloneRegExp(args..), 'Expected');
//t.equal(cloneRegExp(args..), 'Expected');
//t.false(cloneRegExp(args..), 'Expected');
//t.throws(cloneRegExp(args..), 'Expected');
t.end();
test('cloneRegExp is a Function', () => {
expect(cloneRegExp).toBeInstanceOf(Function);
});
const rgTest = /./g;
test('Clones regular expressions properly', () => {
expect(cloneRegExp(rgTest)).not.toBe(rgTest);
});

View File

@ -1,14 +1,9 @@
const test = require('tape');
const expect = require('expect');
const coalesce = require('./coalesce.js');
test('Testing coalesce', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof coalesce === 'function', 'coalesce is a Function');
t.deepEqual(coalesce(null, undefined, '', NaN, 'Waldo'), '', "Returns the first non-null/undefined argument");
//t.deepEqual(coalesce(args..), 'Expected');
//t.equal(coalesce(args..), 'Expected');
//t.false(coalesce(args..), 'Expected');
//t.throws(coalesce(args..), 'Expected');
t.end();
});
test('coalesce is a Function', () => {
expect(coalesce).toBeInstanceOf(Function);
});
test('Returns the first non-null/undefined argument', () => {
expect(coalesce(null, undefined, '', NaN, 'Waldo')).toEqual('');
});

View File

@ -1,15 +1,10 @@
const test = require('tape');
const expect = require('expect');
const coalesceFactory = require('./coalesceFactory.js');
test('Testing coalesceFactory', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof coalesceFactory === 'function', 'coalesceFactory is a Function');
const customCoalesce = coalesceFactory(_ => ![null, undefined, '', NaN].includes(_));
t.deepEqual(customCoalesce(undefined, null, NaN, '', 'Waldo'), 'Waldo', "Returns a customized coalesce function");
//t.deepEqual(coalesceFactory(args..), 'Expected');
//t.equal(coalesceFactory(args..), 'Expected');
//t.false(coalesceFactory(args..), 'Expected');
//t.throws(coalesceFactory(args..), 'Expected');
t.end();
});
test('coalesceFactory is a Function', () => {
expect(coalesceFactory).toBeInstanceOf(Function);
});
const customCoalesce = coalesceFactory(_ => ![null, undefined, '', NaN].includes(_));
test('Returns a customized coalesce function', () => {
expect(customCoalesce(undefined, null, NaN, '', 'Waldo')).toEqual('Waldo');
});

View File

@ -1,24 +1,22 @@
const test = require('tape');
const expect = require('expect');
const collatz = require('./collatz.js');
test('Testing collatz', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof collatz === 'function', 'collatz is a Function');
//t.deepEqual(collatz(args..), 'Expected');
t.equal(collatz(8), 4, 'When n is even, divide by 2');
t.equal(collatz(9), 28, 'When n is odd, times by 3 and add 1');
test('collatz is a Function', () => {
expect(collatz).toBeInstanceOf(Function);
});
test('When n is even, divide by 2', () => {
expect(collatz(8)).toBe(4);
});
test('When n is odd, times by 3 and add 1', () => {
expect(collatz(9)).toBe(28);
});
test('Eventually reaches 1', () => {
let n = 9;
while(true){
if (n === 1){
t.pass('Eventually reaches 1');
expect(n).toBe(1);
break;
}
n = collatz(n);
}
//t.false(collatz(args..), 'Expected');
//t.throws(collatz(args..), 'Expected');
t.end();
});

View File

@ -1,18 +1,13 @@
const test = require('tape');
const expect = require('expect');
const collectInto = require('./collectInto.js');
test('Testing collectInto', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof collectInto === 'function', 'collectInto is a Function');
const Pall = collectInto(Promise.all.bind(Promise));
let p1 = Promise.resolve(1);
let p2 = Promise.resolve(2);
let p3 = new Promise(resolve => setTimeout(resolve, 2000, 3));
Pall(p1, p2, p3).then(function(val){ t.deepEqual(val, [1,2,3], 'Works with multiple promises');}, function(reason){});
//t.deepEqual(collectInto(args..), 'Expected');
//t.equal(collectInto(args..), 'Expected');
//t.false(collectInto(args..), 'Expected');
//t.throws(collectInto(args..), 'Expected');
t.end();
test('collectInto is a Function', () => {
expect(collectInto).toBeInstanceOf(Function);
});
const Pall = collectInto(Promise.all.bind(Promise));
let p1 = Promise.resolve(1);
let p2 = Promise.resolve(2);
let p3 = new Promise(resolve => setTimeout(resolve, 2000, 3));
test('Works with multiple promises', () => {
Pall(p1, p2, p3).then(function(val){ expect(val).toBe([1,2,3]);}, function(reason){});
});

View File

@ -1,14 +1,6 @@
const test = require('tape');
const expect = require('expect');
const colorize = require('./colorize.js');
test('Testing colorize', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof colorize === 'function', 'colorize is a Function');
t.pass('Tested on 09/02/2018 by @chalarangelo');
//t.deepEqual(colorize(args..), 'Expected');
//t.equal(colorize(args..), 'Expected');
//t.false(colorize(args..), 'Expected');
//t.throws(colorize(args..), 'Expected');
t.end();
test('colorize is a Function', () => {
expect(colorize).toBeInstanceOf(Function);
});

View File

@ -1,14 +1,9 @@
const test = require('tape');
const expect = require('expect');
const compact = require('./compact.js');
test('Testing compact', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof compact === 'function', 'compact is a Function');
t.deepEqual(compact([0, 1, false, 2, '', 3, 'a', 'e' * 23, NaN, 's', 34]), [ 1, 2, 3, 'a', 's', 34 ], "Removes falsey values from an array");
//t.deepEqual(compact(args..), 'Expected');
//t.equal(compact(args..), 'Expected');
//t.false(compact(args..), 'Expected');
//t.throws(compact(args..), 'Expected');
t.end();
});
test('compact is a Function', () => {
expect(compact).toBeInstanceOf(Function);
});
test('Removes falsey values from an array', () => {
expect(compact([0, 1, false, 2, '', 3, 'a', 'e' * 23, NaN, 's', 34])).toEqual([ 1, 2, 3, 'a', 's', 34 ]);
});

View File

@ -1,17 +1,12 @@
const test = require('tape');
const expect = require('expect');
const compose = require('./compose.js');
test('Testing compose', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof compose === 'function', 'compose is a Function');
const add5 = x => x + 5;
const multiply = (x, y) => x * y;
const multiplyAndAdd5 = compose(add5, multiply);
t.equal(multiplyAndAdd5(5, 2), 15, "Performs right-to-left function composition");
//t.deepEqual(compose(args..), 'Expected');
//t.equal(compose(args..), 'Expected');
//t.false(compose(args..), 'Expected');
//t.throws(compose(args..), 'Expected');
t.end();
});
test('compose is a Function', () => {
expect(compose).toBeInstanceOf(Function);
});
const add5 = x => x + 5;
const multiply = (x, y) => x * y;
const multiplyAndAdd5 = compose(add5, multiply);
test('Performs right-to-left function composition', () => {
expect(multiplyAndAdd5(5, 2)).toBe(15);
});

View File

@ -1,17 +1,12 @@
const test = require('tape');
const expect = require('expect');
const composeRight = require('./composeRight.js');
test('Testing composeRight', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof composeRight === 'function', 'composeRight is a Function');
const add = (x, y) => x + y;
const square = x => x * x;
const addAndSquare = composeRight(add, square);
t.equal(addAndSquare(1, 2), 9, "Performs left-to-right function composition");
//t.deepEqual(composeRight(args..), 'Expected');
//t.equal(composeRight(args..), 'Expected');
//t.false(composeRight(args..), 'Expected');
//t.throws(composeRight(args..), 'Expected');
t.end();
test('composeRight is a Function', () => {
expect(composeRight).toBeInstanceOf(Function);
});
const add = (x, y) => x + y;
const square = x => x * x;
const addAndSquare = composeRight(add, square);
test('Performs left-to-right function composition', () => {
expect(addAndSquare(1, 2)).toBe(9);
});

View File

@ -1,23 +1,20 @@
const test = require('tape');
const expect = require('expect');
const converge = require('./converge.js');
test('Testing converge', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof converge === 'function', 'converge is a Function');
const average = converge((a, b) => a / b, [
arr => arr.reduce((a, v) => a + v, 0),
arr => arr.length,
]);
t.equal(average([1, 2, 3, 4, 5, 6, 7]), 4, 'Produces the average of the array');
const strangeConcat = converge((a, b) => a + b, [
x => x.toUpperCase(),
x => x.toLowerCase()]
);
t.equal(strangeConcat('Yodel'), "YODELyodel", 'Produces the strange concatenation');
//t.deepEqual(converge(args..), 'Expected');
//t.equal(converge(args..), 'Expected');
//t.false(converge(args..), 'Expected');
//t.throws(converge(args..), 'Expected');
t.end();
test('converge is a Function', () => {
expect(converge).toBeInstanceOf(Function);
});
const average = converge((a, b) => a / b, [
arr => arr.reduce((a, v) => a + v, 0),
arr => arr.length,
]);
test('Produces the average of the array', () => {
expect(average([1, 2, 3, 4, 5, 6, 7])).toBe(4);
});
const strangeConcat = converge((a, b) => a + b, [
x => x.toUpperCase(),
x => x.toLowerCase()]
);
test('Produces the strange concatenation', () => {
expect(strangeConcat('Yodel')).toBe('YODELyodel');
});

View File

@ -1,14 +1,6 @@
const test = require('tape');
const expect = require('expect');
const copyToClipboard = require('./copyToClipboard.js');
test('Testing copyToClipboard', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof copyToClipboard === 'function', 'copyToClipboard is a Function');
t.pass('Tested on 09/02/2018 by @chalarangelo');
//t.deepEqual(copyToClipboard(args..), 'Expected');
//t.equal(copyToClipboard(args..), 'Expected');
//t.false(copyToClipboard(args..), 'Expected');
//t.throws(copyToClipboard(args..), 'Expected');
t.end();
test('copyToClipboard is a Function', () => {
expect(copyToClipboard).toBeInstanceOf(Function);
});

View File

@ -1,15 +1,12 @@
const test = require('tape');
const expect = require('expect');
const countBy = require('./countBy.js');
test('Testing countBy', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof countBy === 'function', 'countBy is a Function');
t.deepEqual(countBy([6.1, 4.2, 6.3], Math.floor), {4: 1, 6: 2}, 'Works for functions');
t.deepEqual(countBy(['one', 'two', 'three'], 'length'), {3: 2, 5: 1}, 'Works for property names');
//t.deepEqual(countBy(args..), 'Expected');
//t.equal(countBy(args..), 'Expected');
//t.false(countBy(args..), 'Expected');
//t.throws(countBy(args..), 'Expected');
t.end();
test('countBy is a Function', () => {
expect(countBy).toBeInstanceOf(Function);
});
test('Works for functions', () => {
expect(countBy([6.1, 4.2, 6.3], Math.floor)).toEqual({4: 1, 6: 2});
});
test('Works for property names', () => {
expect(countBy(['one', 'two', 'three'], 'length')).toEqual({3: 2, 5: 1});
});

View File

@ -1,14 +1,9 @@
const test = require('tape');
const expect = require('expect');
const countOccurrences = require('./countOccurrences.js');
test('Testing countOccurrences', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof countOccurrences === 'function', 'countOccurrences is a Function');
t.deepEqual(countOccurrences([1, 1, 2, 1, 2, 3], 1), 3, "Counts the occurrences of a value in an array");
//t.deepEqual(countOccurrences(args..), 'Expected');
//t.equal(countOccurrences(args..), 'Expected');
//t.false(countOccurrences(args..), 'Expected');
//t.throws(countOccurrences(args..), 'Expected');
t.end();
});
test('countOccurrences is a Function', () => {
expect(countOccurrences).toBeInstanceOf(Function);
});
test('Counts the occurrences of a value in an array', () => {
expect(countOccurrences([1, 1, 2, 1, 2, 3], 1)).toEqual(3);
});

View File

@ -1,13 +1,6 @@
const test = require('tape');
const expect = require('expect');
const countVowels = require('./countVowels.js');
test('Testing countVowels', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof countVowels === 'function', 'countVowels is a Function');
//t.deepEqual(countVowels(args..), 'Expected');
//t.equal(countVowels(args..), 'Expected');
//t.false(countVowels(args..), 'Expected');
//t.throws(countVowels(args..), 'Expected');
t.end();
});
test('countVowels is a Function', () => {
expect(countVowels).toBeInstanceOf(Function);
});

View File

@ -1,13 +1,6 @@
const test = require('tape');
const expect = require('expect');
const counter = require('./counter.js');
test('Testing counter', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof counter === 'function', 'counter is a Function');
//t.deepEqual(counter(args..), 'Expected');
//t.equal(counter(args..), 'Expected');
//t.false(counter(args..), 'Expected');
//t.throws(counter(args..), 'Expected');
t.end();
});
test('counter is a Function', () => {
expect(counter).toBeInstanceOf(Function);
});

View File

@ -1,14 +1,6 @@
const test = require('tape');
const expect = require('expect');
const createElement = require('./createElement.js');
test('Testing createElement', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof createElement === 'function', 'createElement is a Function');
t.pass('Tested by @chalarangelo on 16/02/2018');
//t.deepEqual(createElement(args..), 'Expected');
//t.equal(createElement(args..), 'Expected');
//t.false(createElement(args..), 'Expected');
//t.throws(createElement(args..), 'Expected');
t.end();
test('createElement is a Function', () => {
expect(createElement).toBeInstanceOf(Function);
});

View File

@ -1,14 +1,6 @@
const test = require('tape');
const expect = require('expect');
const createEventHub = require('./createEventHub.js');
test('Testing createEventHub', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof createEventHub === 'function', 'createEventHub is a Function');
t.pass('Tested by @chalarangelo on 16/02/2018');
//t.deepEqual(createEventHub(args..), 'Expected');
//t.equal(createEventHub(args..), 'Expected');
//t.false(createEventHub(args..), 'Expected');
//t.throws(createEventHub(args..), 'Expected');
t.end();
test('createEventHub is a Function', () => {
expect(createEventHub).toBeInstanceOf(Function);
});

View File

@ -1,14 +1,6 @@
const test = require('tape');
const expect = require('expect');
const currentURL = require('./currentURL.js');
test('Testing currentURL', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof currentURL === 'function', 'currentURL is a Function');
t.pass('Tested by @chalarangelo on 16/02/2018');
//t.deepEqual(currentURL(args..), 'Expected');
//t.equal(currentURL(args..), 'Expected');
//t.false(currentURL(args..), 'Expected');
//t.throws(currentURL(args..), 'Expected');
t.end();
test('currentURL is a Function', () => {
expect(currentURL).toBeInstanceOf(Function);
});

View File

@ -1,15 +1,12 @@
const test = require('tape');
const expect = require('expect');
const curry = require('./curry.js');
test('Testing curry', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof curry === 'function', 'curry is a Function');
t.equal(curry(Math.pow)(2)(10), 1024, "curries a Math.pow");
t.equal(curry(Math.min, 3)(10)(50)(2), 2, "curries a Math.min");
//t.deepEqual(curry(args..), 'Expected');
//t.equal(curry(args..), 'Expected');
//t.false(curry(args..), 'Expected');
//t.throws(curry(args..), 'Expected');
t.end();
});
test('curry is a Function', () => {
expect(curry).toBeInstanceOf(Function);
});
test('curries a Math.pow', () => {
expect(curry(Math.pow)(2)(10)).toBe(1024);
});
test('curries a Math.min', () => {
expect(curry(Math.min, 3)(10)(50)(2)).toBe(2);
});

View File

@ -1,14 +1,9 @@
const test = require('tape');
const expect = require('expect');
const debounce = require('./debounce.js');
test('Testing debounce', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof debounce === 'function', 'debounce is a Function');
debounce(() => {t.pass('Works as expected');}, 250);
//t.deepEqual(debounce(args..), 'Expected');
//t.equal(debounce(args..), 'Expected');
//t.false(debounce(args..), 'Expected');
//t.throws(debounce(args..), 'Expected');
t.end();
test('debounce is a Function', () => {
expect(debounce).toBeInstanceOf(Function);
});
test('Works as expected', () => {
debounce(() => { expect(true).toBeTruthy(); });
});

View File

@ -1,15 +1,12 @@
const test = require('tape');
const expect = require('expect');
const decapitalize = require('./decapitalize.js');
test('Testing decapitalize', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof decapitalize === 'function', 'decapitalize is a Function');
t.equal(decapitalize('FooBar'), 'fooBar', 'Works with default parameter');
t.equal(decapitalize('FooBar', true), 'fOOBAR', 'Works with second parameter set to true');
//t.deepEqual(decapitalize(args..), 'Expected');
//t.equal(decapitalize(args..), 'Expected');
//t.false(decapitalize(args..), 'Expected');
//t.throws(decapitalize(args..), 'Expected');
t.end();
test('decapitalize is a Function', () => {
expect(decapitalize).toBeInstanceOf(Function);
});
test('Works with default parameter', () => {
expect(decapitalize('FooBar')).toBe('fooBar');
});
test('Works with second parameter set to true', () => {
expect(decapitalize('FooBar', true)).toBe('fOOBAR');
});

View File

@ -1,21 +1,22 @@
const test = require('tape');
const expect = require('expect');
const deepClone = require('./deepClone.js');
test('Testing deepClone', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof deepClone === 'function', 'deepClone is a Function');
const a = { foo: 'bar', obj: { a: 1, b: 2 } };
const b = deepClone(a);
const c = [{foo: "bar"}];
const d = deepClone(c);
t.notEqual(a, b, 'Shallow cloning works');
t.notEqual(a.obj, b.obj, 'Deep cloning works');
t.notEqual(c, d, "Array shallow cloning works");
t.notEqual(c[0], d[0], "Array deep cloning works");
//t.deepEqual(deepClone(args..), 'Expected');
//t.equal(deepClone(args..), 'Expected');
//t.false(deepClone(args..), 'Expected');
//t.throws(deepClone(args..), 'Expected');
t.end();
test('deepClone is a Function', () => {
expect(deepClone).toBeInstanceOf(Function);
});
const a = { foo: 'bar', obj: { a: 1, b: 2 } };
const b = deepClone(a);
const c = [{foo: "bar"}];
const d = deepClone(c);
test('Shallow cloning works', () => {
expect(a).not.toBe(b);
});
test('Deep cloning works', () => {
expect(a.obj).not.toBe(b.obj);
});
test('Array shallow cloning works', () => {
expect(c).not.toBe(d);
});
test('Array deep cloning works', () => {
expect(c[0]).not.toBe(d[0]);
});

View File

@ -1,14 +1,9 @@
const test = require('tape');
const expect = require('expect');
const deepFlatten = require('./deepFlatten.js');
test('Testing deepFlatten', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof deepFlatten === 'function', 'deepFlatten is a Function');
t.deepEqual(deepFlatten([1, [2], [[3], 4], 5]), [1, 2, 3, 4, 5], "Deep flattens an array");
//t.deepEqual(deepFlatten(args..), 'Expected');
//t.equal(deepFlatten(args..), 'Expected');
//t.false(deepFlatten(args..), 'Expected');
//t.throws(deepFlatten(args..), 'Expected');
t.end();
});
test('deepFlatten is a Function', () => {
expect(deepFlatten).toBeInstanceOf(Function);
});
test('Deep flattens an array', () => {
expect(deepFlatten([1, [2], [[3], 4], 5])).toEqual( [1, 2, 3, 4, 5]);
});

View File

@ -1,14 +1,9 @@
const test = require('tape');
const expect = require('expect');
const defaults = require('./defaults.js');
test('Testing defaults', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof defaults === 'function', 'defaults is a Function');
t.deepEqual(defaults({ a: 1 }, { b: 2 }, { b: 6 }, { a: 3 }), { a: 1, b: 2 }, 'Assigns default values for undefined properties');
//t.deepEqual(defaults(args..), 'Expected');
//t.equal(defaults(args..), 'Expected');
//t.false(defaults(args..), 'Expected');
//t.throws(defaults(args..), 'Expected');
t.end();
test('defaults is a Function', () => {
expect(defaults).toBeInstanceOf(Function);
});
test('Assigns default values for undefined properties', () => {
expect(defaults({ a: 1 }, { b: 2 }, { b: 6 }, { a: 3 })).toEqual({ a: 1, b: 2 });
});

View File

@ -1,14 +1,6 @@
const test = require('tape');
const expect = require('expect');
const defer = require('./defer.js');
test('Testing defer', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof defer === 'function', 'defer is a Function');
t.pass('Tested by @chalarangelo on 16/02/2018');
//t.deepEqual(defer(args..), 'Expected');
//t.equal(defer(args..), 'Expected');
//t.false(defer(args..), 'Expected');
//t.throws(defer(args..), 'Expected');
t.end();
test('defer is a Function', () => {
expect(defer).toBeInstanceOf(Function);
});

View File

@ -1,15 +1,10 @@
const test = require('tape');
const expect = require('expect');
const degreesToRads = require('./degreesToRads.js');
test('Testing degreesToRads', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
const approxeq = (v1,v2, diff = 0.001) => Math.abs(v1 - v2) < diff; // Use to account for rounding errors
t.true(typeof degreesToRads === 'function', 'degreesToRads is a Function');
t.true(approxeq(degreesToRads(90.0), Math.PI / 2), 'Returns the appropriate value');
//t.deepEqual(degreesToRads(args..), 'Expected');
//t.equal(degreesToRads(args..), 'Expected');
//t.false(degreesToRads(args..), 'Expected');
//t.throws(degreesToRads(args..), 'Expected');
t.end();
// const approxeq = (v1,v2, diff = 0.001) => Math.abs(v1 - v2) < diff;
test('degreesToRads is a Function', () => {
expect(degreesToRads).toBeInstanceOf(Function);
});
test('Returns the appropriate value', () => {
expect(degreesToRads(90.0)).toBeCloseTo(Math.PI / 2, 3);
});

View File

@ -1,20 +1,15 @@
const test = require('tape');
const expect = require('expect');
const delay = require('./delay.js');
test('Testing delay', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof delay === 'function', 'delay is a Function');
test('delay is a Function', () => {
expect(delay).toBeInstanceOf(Function);
});
test('Works as expecting, passing arguments properly', () => {
delay(
function(text) {
t.equals(text, 'test', 'Works as expecting, passing arguments properly');
expect(text).toBe('test');
},
1000,
'test'
);
//t.deepEqual(delay(args..), 'Expected');
//t.equal(delay(args..), 'Expected');
//t.false(delay(args..), 'Expected');
//t.throws(delay(args..), 'Expected');
t.end();
});

View File

@ -1,14 +1,6 @@
const test = require('tape');
const expect = require('expect');
const detectDeviceType = require('./detectDeviceType.js');
test('Testing detectDeviceType', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof detectDeviceType === 'function', 'detectDeviceType is a Function');
t.pass('Tested on 09/02/2018 by @chalarangelo');
//t.deepEqual(detectDeviceType(args..), 'Expected');
//t.equal(detectDeviceType(args..), 'Expected');
//t.false(detectDeviceType(args..), 'Expected');
//t.throws(detectDeviceType(args..), 'Expected');
t.end();
test('detectDeviceType is a Function', () => {
expect(detectDeviceType).toBeInstanceOf(Function);
});

View File

@ -1,14 +1,9 @@
const test = require('tape');
const expect = require('expect');
const difference = require('./difference.js');
test('Testing difference', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof difference === 'function', 'difference is a Function');
t.deepEqual(difference([1, 2, 3], [1, 2, 4]), [3], "Returns the difference between two arrays");
//t.deepEqual(difference(args..), 'Expected');
//t.equal(difference(args..), 'Expected');
//t.false(difference(args..), 'Expected');
//t.throws(difference(args..), 'Expected');
t.end();
});
test('difference is a Function', () => {
expect(difference).toBeInstanceOf(Function);
});
test('Returns the difference between two arrays', () => {
expect(difference([1, 2, 3], [1, 2, 4])).toEqual([3]);
});

View File

@ -1,15 +1,12 @@
const test = require('tape');
const expect = require('expect');
const differenceBy = require('./differenceBy.js');
test('Testing differenceBy', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof differenceBy === 'function', 'differenceBy is a Function');
t.deepEqual(differenceBy([2.1, 1.2], [2.3, 3.4], Math.floor), [1.2], 'Works using a native function and numbers');
t.deepEqual(differenceBy([{ x: 2 }, { x: 1 }], [{ x: 1 }], v => v.x), [ { x: 2 } ], 'Works with arrow function and objects');
//t.deepEqual(differenceBy(args..), 'Expected');
//t.equal(differenceBy(args..), 'Expected');
//t.false(differenceBy(args..), 'Expected');
//t.throws(differenceBy(args..), 'Expected');
t.end();
test('differenceBy is a Function', () => {
expect(differenceBy).toBeInstanceOf(Function);
});
test('Works using a native function and numbers', () => {
expect(differenceBy([2.1, 1.2], [2.3, 3.4], Math.floor)).toEqual( [1.2]);
});
test('Works with arrow function and objects', () => {
expect(differenceBy([{ x: 2 }, { x: 1 }], [{ x: 1 }], v => v.x)).toEqual([ { x: 2 } ]);
});

View File

@ -1,14 +1,9 @@
const test = require('tape');
const expect = require('expect');
const differenceWith = require('./differenceWith.js');
test('Testing differenceWith', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof differenceWith === 'function', 'differenceWith is a Function');
t.deepEqual(differenceWith([1, 1.2, 1.5, 3, 0], [1.9, 3, 0], (a, b) => Math.round(a) === Math.round(b)), [1, 1.2], "Filters out all values from an array");
//t.deepEqual(differenceWith(args..), 'Expected');
//t.equal(differenceWith(args..), 'Expected');
//t.false(differenceWith(args..), 'Expected');
//t.throws(differenceWith(args..), 'Expected');
t.end();
});
test('differenceWith is a Function', () => {
expect(differenceWith).toBeInstanceOf(Function);
});
test('Filters out all values from an array', () => {
expect(differenceWith([1, 1.2, 1.5, 3, 0], [1.9, 3, 0], (a, b) => Math.round(a) === Math.round(b))).toEqual([1, 1.2]);
});

View File

@ -1,14 +1,9 @@
const test = require('tape');
const expect = require('expect');
const digitize = require('./digitize.js');
test('Testing digitize', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof digitize === 'function', 'digitize is a Function');
t.deepEqual(digitize(123), [1, 2, 3], "Converts a number to an array of digits");
//t.deepEqual(digitize(args..), 'Expected');
//t.equal(digitize(args..), 'Expected');
//t.false(digitize(args..), 'Expected');
//t.throws(digitize(args..), 'Expected');
t.end();
});
test('digitize is a Function', () => {
expect(digitize).toBeInstanceOf(Function);
});
test('Converts a number to an array of digits', () => {
expect(digitize(123)).toEqual([1, 2,3]);
});

View File

@ -1,14 +1,9 @@
const test = require('tape');
const expect = require('expect');
const distance = require('./distance.js');
test('Testing distance', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof distance === 'function', 'distance is a Function');
t.equals(distance(1, 1, 2, 3), 2.23606797749979, 'Calculates the distance between two points');
//t.deepEqual(distance(args..), 'Expected');
//t.equal(distance(args..), 'Expected');
//t.false(distance(args..), 'Expected');
//t.throws(distance(args..), 'Expected');
t.end();
test('distance is a Function', () => {
expect(distance).toBeInstanceOf(Function);
});
test('Calculates the distance between two points', () => {
expect(distance(1, 1, 2, 3)).toBeCloseTo(2.23606797749979, 5);
});

View File

@ -1,16 +1,15 @@
const test = require('tape');
const expect = require('expect');
const drop = require('./drop.js');
test('Testing drop', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof drop === 'function', 'drop is a Function');
t.deepEqual(drop([1, 2, 3]), [2,3], 'Works without the last argument');
t.deepEqual(drop([1, 2, 3], 2), [3], 'Removes appropriate element count as specified');
t.deepEqual(drop([1, 2, 3], 42), [], 'Empties array given a count greater than length');
//t.deepEqual(drop(args..), 'Expected');
//t.equal(drop(args..), 'Expected');
//t.false(drop(args..), 'Expected');
//t.throws(drop(args..), 'Expected');
t.end();
test('drop is a Function', () => {
expect(drop).toBeInstanceOf(Function);
});
test('Works without the last argument', () => {
expect(drop([1, 2, 3])).toEqual([2,3]);
});
test('Removes appropriate element count as specified', () => {
expect(drop([1, 2, 3], 2)).toEqual([3]);
});
test('Empties array given a count greater than length', () => {
expect(drop([1, 2, 3], 42)).toEqual([]);
});

View File

@ -1,16 +1,15 @@
const test = require('tape');
const expect = require('expect');
const dropRight = require('./dropRight.js');
test('Testing dropRight', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof dropRight === 'function', 'dropRight is a Function');
t.deepEqual(dropRight([1, 2, 3]), [1,2], "Returns a new array with n elements removed from the right");
t.deepEqual(dropRight([1, 2, 3], 2), [1], "Returns a new array with n elements removed from the right");
t.deepEqual(dropRight([1, 2, 3], 42), [], "Returns a new array with n elements removed from the right");
//t.deepEqual(dropRight(args..), 'Expected');
//t.equal(dropRight(args..), 'Expected');
//t.false(dropRight(args..), 'Expected');
//t.throws(dropRight(args..), 'Expected');
t.end();
});
test('dropRight is a Function', () => {
expect(dropRight).toBeInstanceOf(Function);
});
test('Returns a new array with n elements removed from the right', () => {
expect(dropRight([1, 2, 3])).toEqual([1, 2]);
});
test('Returns a new array with n elements removed from the right', () => {
expect(dropRight([1, 2, 3], 2)).toEqual([1]);
});
test('Returns a new array with n elements removed from the right', () => {
expect(dropRight([1, 2, 3], 42)).toEqual([]);
});

View File

@ -1,14 +1,9 @@
const test = require('tape');
const expect = require('expect');
const dropRightWhile = require('./dropRightWhile.js');
test('Testing dropRightWhile', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof dropRightWhile === 'function', 'dropRightWhile is a Function');
t.deepEqual(dropRightWhile([1, 2, 3, 4], n => n < 3), [1, 2], 'Removes elements from the end of an array until the passed function returns true.');
//t.deepEqual(dropRightWhile(args..), 'Expected');
//t.equal(dropRightWhile(args..), 'Expected');
//t.false(dropRightWhile(args..), 'Expected');
//t.throws(dropRightWhile(args..), 'Expected');
t.end();
test('dropRightWhile is a Function', () => {
expect(dropRightWhile).toBeInstanceOf(Function);
});
test('Removes elements from the end of an array until the passed function returns true.', () => {
expect(dropRightWhile([1, 2, 3, 4], n => n < 3)).toEqual([1, 2]);
});

View File

@ -1,14 +1,9 @@
const test = require('tape');
const expect = require('expect');
const dropWhile = require('./dropWhile.js');
test('Testing dropWhile', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof dropWhile === 'function', 'dropWhile is a Function');
t.deepEqual(dropWhile([1, 2, 3, 4], n => n >= 3), [3,4], 'Removes elements in an array until the passed function returns true.');
//t.deepEqual(dropWhile(args..), 'Expected');
//t.equal(dropWhile(args..), 'Expected');
//t.false(dropWhile(args..), 'Expected');
//t.throws(dropWhile(args..), 'Expected');
t.end();
test('dropWhile is a Function', () => {
expect(dropWhile).toBeInstanceOf(Function);
});
test('Removes elements in an array until the passed function returns true.', () => {
expect(dropWhile([1, 2, 3, 4], n => n >= 3)).toEqual([3,4]);
});

View File

@ -1,14 +1,6 @@
const test = require('tape');
const expect = require('expect');
const elementIsVisibleInViewport = require('./elementIsVisibleInViewport.js');
test('Testing elementIsVisibleInViewport', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof elementIsVisibleInViewport === 'function', 'elementIsVisibleInViewport is a Function');
t.pass('Tested on 09/02/2018 by @chalarangelo');
//t.deepEqual(elementIsVisibleInViewport(args..), 'Expected');
//t.equal(elementIsVisibleInViewport(args..), 'Expected');
//t.false(elementIsVisibleInViewport(args..), 'Expected');
//t.throws(elementIsVisibleInViewport(args..), 'Expected');
t.end();
test('elementIsVisibleInViewport is a Function', () => {
expect(elementIsVisibleInViewport).toBeInstanceOf(Function);
});

View File

@ -1,16 +1,15 @@
const test = require('tape');
const expect = require('expect');
const elo = require('./elo.js');
test('Testing elo', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof elo === 'function', 'elo is a Function');
t.deepEqual(elo([1200, 1200]), [1216, 1184], "Standard 1v1s");
t.deepEqual(elo([1200, 1200], 64), [1232, 1168]), "Standard 1v1s";
t.deepEqual(elo([1200, 1200, 1200, 1200]).map(Math.round), [1246, 1215, 1185, 1154], "4 player FFA, all same rank");
//t.deepEqual(elo(args..), 'Expected');
//t.equal(elo(args..), 'Expected');
//t.false(elo(args..), 'Expected');
//t.throws(elo(args..), 'Expected');
t.end();
});
test('elo is a Function', () => {
expect(elo).toBeInstanceOf(Function);
});
test('Standard 1v1s', () => {
expect(elo([1200, 1200])).toEqual([1216,1184]);
});
test('Standard 1v1s' ,() => {
expect(elo([1200, 1200], 64)).toEqual([1232, 1168]);
});
test('4 player FFA, all same rank', () => {
expect(elo([1200, 1200, 1200, 1200]).map(Math.round)).toEqual([1246, 1215, 1185, 1154]);
});

View File

@ -1,18 +1,21 @@
const test = require('tape');
const expect = require('expect');
const equals = require('./equals.js');
test('Testing equals', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof equals === 'function', 'equals is a Function');
t.true(equals({ a: [2, {e: 3}], b: [4], c: 'foo' }, { a: [2, {e: 3}], b: [4], c: 'foo' }), "{ a: [2, {e: 3}], b: [4], c: 'foo' } is equal to { a: [2, {e: 3}], b: [4], c: 'foo' }");
t.true(equals([1, 2, 3], [1, 2, 3]), '[1,2,3] is equal to [1,2,3]');
t.false(equals({ a: [2, 3], b: [4] }, { a: [2, 3], b: [6] }), '{ a: [2, 3], b: [4] } is not equal to { a: [2, 3], b: [6] }');
t.false(equals([1, 2, 3], [1, 2, 4]), '[1,2,3] is not equal to [1,2,4]');
t.true(equals([1, 2, 3], { 0: 1, 1: 2, 2: 3 }), '[1, 2, 3] should be equal to { 0: 1, 1: 2, 2: 3 }) - type is different, but their enumerable properties match.');
//t.deepEqual(equals(args..), 'Expected');
//t.equal(equals(args..), 'Expected');
//t.false(equals(args..), 'Expected');
//t.throws(equals(args..), 'Expected');
t.end();
test('equals is a Function', () => {
expect(equals).toBeInstanceOf(Function);
});
test('{ a: [2, {e: 3}], b: [4], c: \'foo\' } is equal to { a: [2, {e: 3}], b: [4], c: \'foo\' }', () => {
expect(equals({ a: [2, {e: 3}], b: [4], c: 'foo' }, { a: [2, {e: 3}], b: [4], c: 'foo' })).toBeTruthy();
});
test('[1,2,3] is equal to [1,2,3]', () => {
expect(equals([1, 2, 3], [1, 2, 3])).toBeTruthy();
});
test('{ a: [2, 3], b: [4] } is not equal to { a: [2, 3], b: [6] }', () => {
expect(equals({ a: [2, 3], b: [4] }, { a: [2, 3], b: [6] })).toBeFalsy();
});
test('[1,2,3] is not equal to [1,2,4]', () => {
expect(equals([1, 2, 3], [1, 2, 4])).toBeFalsy();
});
test('[1, 2, 3] should be equal to { 0: 1, 1: 2, 2: 3 }) - type is different, but their enumerable properties match.', () => {
expect(equals([1, 2, 3], { 0: 1, 1: 2, 2: 3 })).toBeTruthy();
});

View File

@ -1,14 +1,9 @@
const test = require('tape');
const expect = require('expect');
const escapeHTML = require('./escapeHTML.js');
test('Testing escapeHTML', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof escapeHTML === 'function', 'escapeHTML is a Function');
t.equal(escapeHTML('<a href="#">Me & you</a>'), '&lt;a href=&quot;#&quot;&gt;Me &amp; you&lt;/a&gt;', "Escapes a string for use in HTML");
//t.deepEqual(escapeHTML(args..), 'Expected');
//t.equal(escapeHTML(args..), 'Expected');
//t.false(escapeHTML(args..), 'Expected');
//t.throws(escapeHTML(args..), 'Expected');
t.end();
});
test('escapeHTML is a Function', () => {
expect(escapeHTML).toBeInstanceOf(Function);
});
test('Escapes a string for use in HTML', () => {
expect(escapeHTML('<a href="#">Me & you</a>')).toBe('&lt;a href=&quot;#&quot;&gt;Me &amp; you&lt;/a&gt;');
});

View File

@ -1,14 +1,9 @@
const test = require('tape');
const expect = require('expect');
const escapeRegExp = require('./escapeRegExp.js');
test('Testing escapeRegExp', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof escapeRegExp === 'function', 'escapeRegExp is a Function');
t.equal(escapeRegExp('(test)'), '\\(test\\)', "Escapes a string to use in a regular expression");
//t.deepEqual(escapeRegExp(args..), 'Expected');
//t.equal(escapeRegExp(args..), 'Expected');
//t.false(escapeRegExp(args..), 'Expected');
//t.throws(escapeRegExp(args..), 'Expected');
t.end();
});
test('escapeRegExp is a Function', () => {
expect(escapeRegExp).toBeInstanceOf(Function);
});
test('Escapes a string to use in a regular expression', () => {
expect(escapeRegExp('(test)')).toBe('\\(test\\)');
});

View File

@ -1,14 +1,9 @@
const test = require('tape');
const expect = require('expect');
const everyNth = require('./everyNth.js');
test('Testing everyNth', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof everyNth === 'function', 'everyNth is a Function');
t.deepEqual(everyNth([1, 2, 3, 4, 5, 6], 2), [ 2, 4, 6 ], "Returns every nth element in an array");
//t.deepEqual(everyNth(args..), 'Expected');
//t.equal(everyNth(args..), 'Expected');
//t.false(everyNth(args..), 'Expected');
//t.throws(everyNth(args..), 'Expected');
t.end();
});
test('everyNth is a Function', () => {
expect(everyNth).toBeInstanceOf(Function);
});
test('Returns every nth element in an array', () => {
expect(everyNth([1, 2, 3, 4, 5, 6], 2)).toEqual([ 2, 4, 6 ]);
});

View File

@ -1,15 +1,12 @@
const test = require('tape');
const expect = require('expect');
const extendHex = require('./extendHex.js');
test('Testing extendHex', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof extendHex === 'function', 'extendHex is a Function');
t.equal(extendHex('#03f'), '#0033ff', "Extends a 3-digit color code to a 6-digit color code");
t.equal(extendHex('05a'), '#0055aa', "Extends a 3-digit color code to a 6-digit color code");
//t.deepEqual(extendHex(args..), 'Expected');
//t.equal(extendHex(args..), 'Expected');
//t.false(extendHex(args..), 'Expected');
//t.throws(extendHex(args..), 'Expected');
t.end();
});
test('extendHex is a Function', () => {
expect(extendHex).toBeInstanceOf(Function);
});
test('Extends a 3-digit color code to a 6-digit color code', () => {
expect(extendHex('#03f')).toBe('#0033ff');
});
test('Extends a 3-digit color code to a 6-digit color code', () => {
expect(extendHex('05a')).toBe('#0055aa');
});

View File

@ -1,18 +1,21 @@
const test = require('tape');
const expect = require('expect');
const factorial = require('./factorial.js');
test('Testing factorial', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof factorial === 'function', 'factorial is a Function');
t.equal(factorial(6), 720, "Calculates the factorial of 720");
t.equal(factorial(0), 1, "Calculates the factorial of 0");
t.equal(factorial(1), 1, "Calculates the factorial of 1");
t.equal(factorial(4), 24, "Calculates the factorial of 4");
t.equal(factorial(10), 3628800, "Calculates the factorial of 10");
//t.deepEqual(factorial(args..), 'Expected');
//t.equal(factorial(args..), 'Expected');
//t.false(factorial(args..), 'Expected');
//t.throws(factorial(args..), 'Expected');
t.end();
});
test('factorial is a Function', () => {
expect(factorial).toBeInstanceOf(Function);
});
test('Calculates the factorial of 720', () => {
expect(factorial(6)).toBe(720);
});
test('Calculates the factorial of 0', () => {
expect(factorial(0)).toBe(1);
});
test('Calculates the factorial of 1', () => {
expect(factorial(1)).toBe(1);
});
test('Calculates the factorial of 4', () => {
expect(factorial(4)).toBe(24);
});
test('Calculates the factorial of 10', () => {
expect(factorial(10)).toBe(3628800);
});

View File

@ -1,13 +1,6 @@
const test = require('tape');
const expect = require('expect');
const factors = require('./factors.js');
test('Testing factors', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof factors === 'function', 'factors is a Function');
//t.deepEqual(factors(args..), 'Expected');
//t.equal(factors(args..), 'Expected');
//t.false(factors(args..), 'Expected');
//t.throws(factors(args..), 'Expected');
t.end();
});
test('factors is a Function', () => {
expect(factors).toBeInstanceOf(Function);
});

View File

@ -1,14 +1,9 @@
const test = require('tape');
const expect = require('expect');
const fibonacci = require('./fibonacci.js');
test('Testing fibonacci', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof fibonacci === 'function', 'fibonacci is a Function');
t.deepEqual(fibonacci(6), [0, 1, 1, 2, 3, 5], "Generates an array, containing the Fibonacci sequence");
//t.deepEqual(fibonacci(args..), 'Expected');
//t.equal(fibonacci(args..), 'Expected');
//t.false(fibonacci(args..), 'Expected');
//t.throws(fibonacci(args..), 'Expected');
t.end();
});
test('fibonacci is a Function', () => {
expect(fibonacci).toBeInstanceOf(Function);
});
test('Generates an array, containing the Fibonacci sequence', () => {
expect(fibonacci(6)).toEqual([0, 1, 1, 2, 3, 5]);
});

View File

@ -1,13 +1,6 @@
const test = require('tape');
const expect = require('expect');
const fibonacciCountUntilNum = require('./fibonacciCountUntilNum.js');
test('Testing fibonacciCountUntilNum', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof fibonacciCountUntilNum === 'function', 'fibonacciCountUntilNum is a Function');
//t.deepEqual(fibonacciCountUntilNum(args..), 'Expected');
//t.equal(fibonacciCountUntilNum(args..), 'Expected');
//t.false(fibonacciCountUntilNum(args..), 'Expected');
//t.throws(fibonacciCountUntilNum(args..), 'Expected');
t.end();
});
test('fibonacciCountUntilNum is a Function', () => {
expect(fibonacciCountUntilNum).toBeInstanceOf(Function);
});

View File

@ -1,13 +1,6 @@
const test = require('tape');
const expect = require('expect');
const fibonacciUntilNum = require('./fibonacciUntilNum.js');
test('Testing fibonacciUntilNum', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof fibonacciUntilNum === 'function', 'fibonacciUntilNum is a Function');
//t.deepEqual(fibonacciUntilNum(args..), 'Expected');
//t.equal(fibonacciUntilNum(args..), 'Expected');
//t.false(fibonacciUntilNum(args..), 'Expected');
//t.throws(fibonacciUntilNum(args..), 'Expected');
t.end();
});
test('fibonacciUntilNum is a Function', () => {
expect(fibonacciUntilNum).toBeInstanceOf(Function);
});

View File

@ -1,14 +1,10 @@
const test = require('tape');
const expect = require('expect');
const filterNonUnique = require('./filterNonUnique.js');
test('Testing filterNonUnique', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof filterNonUnique === 'function', 'filterNonUnique is a Function');
t.deepEqual(filterNonUnique([1, 2, 2, 3, 4, 4, 5]), [1,3,5], "Filters out the non-unique values in an array");
//t.deepEqual(filterNonUnique(args..), 'Expected');
//t.equal(filterNonUnique(args..), 'Expected');
//t.false(filterNonUnique(args..), 'Expected');
//t.throws(filterNonUnique(args..), 'Expected');
t.end();
});
test('filterNonUnique is a Function', () => {
expect(filterNonUnique).toBeInstanceOf(Function);
});
test('Filters out the non-unique values in an array', () => {
expect(filterNonUnique([1, 2, 2, 3, 4, 4, 5])).toEqual([1,3, 5]);
});

View File

@ -1,21 +1,15 @@
const test = require('tape');
const expect = require('expect');
const findKey = require('./findKey.js');
test('Testing findKey', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof findKey === 'function', 'findKey is a Function');
t.deepEqual(findKey(
test('findKey is a Function', () => {
expect(findKey).toBeInstanceOf(Function);
});
test('Returns the appropriate key', () => {
expect(findKey(
{
barney: { age: 36, active: true },
fred: { age: 40, active: false },
pebbles: { age: 1, active: true }
},
o => o['active']
), 'barney', 'Returns the appropriate key');
//t.deepEqual(findKey(args..), 'Expected');
//t.equal(findKey(args..), 'Expected');
//t.false(findKey(args..), 'Expected');
//t.throws(findKey(args..), 'Expected');
t.end();
o => o['active'])).toBe('barney');
});

View File

@ -1,14 +1,9 @@
const test = require('tape');
const expect = require('expect');
const findLast = require('./findLast.js');
test('Testing findLast', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof findLast === 'function', 'findLast is a Function');
t.equal(findLast([1, 2, 3, 4], n => n % 2 === 1), 3, 'Finds last element for which the given function returns true');
//t.deepEqual(findLast(args..), 'Expected');
//t.equal(findLast(args..), 'Expected');
//t.false(findLast(args..), 'Expected');
//t.throws(findLast(args..), 'Expected');
t.end();
test('findLast is a Function', () => {
expect(findLast).toBeInstanceOf(Function);
});
test('Finds last element for which the given function returns true', () => {
expect(findLast([1, 2, 3, 4], n => n % 2 === 1)).toBe(3);
});

View File

@ -1,14 +1,9 @@
const test = require('tape');
const expect = require('expect');
const findLastIndex = require('./findLastIndex.js');
test('Testing findLastIndex', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof findLastIndex === 'function', 'findLastIndex is a Function');
t.equal(findLastIndex([1, 2, 3, 4], n => n % 2 === 1), 2, 'Finds last index for which the given function returns true');
//t.deepEqual(findLastIndex(args..), 'Expected');
//t.equal(findLastIndex(args..), 'Expected');
//t.false(findLastIndex(args..), 'Expected');
//t.throws(findLastIndex(args..), 'Expected');
t.end();
test('findLastIndex is a Function', () => {
expect(findLastIndex).toBeInstanceOf(Function);
});
test('Finds last index for which the given function returns true', () => {
expect(findLastIndex([1, 2, 3, 4], n => n % 2 === 1)).toBe(2);
});

View File

@ -1,21 +1,15 @@
const test = require('tape');
const expect = require('expect');
const findLastKey = require('./findLastKey.js');
test('Testing findLastKey', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof findLastKey === 'function', 'findLastKey is a Function');
t.equal(findLastKey(
test('findLastKey is a Function', () => {
expect(findLastKey).toBeInstanceOf(Function);
});
test('eturns the appropriate key', () => {
expect(findLastKey(
{
barney: { age: 36, active: true },
fred: { age: 40, active: false },
pebbles: { age: 1, active: true }
},
o => o['active']
), 'pebbles', 'Returns the appropriate key');
//t.deepEqual(findLastKey(args..), 'Expected');
//t.equal(findLastKey(args..), 'Expected');
//t.false(findLastKey(args..), 'Expected');
//t.throws(findLastKey(args..), 'Expected');
t.end();
o => o['active'])).toBe('pebbles');
});

View File

@ -1,15 +1,12 @@
const test = require('tape');
const expect = require('expect');
const flatten = require('./flatten.js');
test('Testing flatten', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof flatten === 'function', 'flatten is a Function');
t.deepEqual(flatten([1, [2], 3, 4]), [1, 2, 3, 4], "Flattens an array");
t.deepEqual(flatten([1, [2, [3, [4, 5], 6], 7], 8], 2), [1, 2, 3, [4, 5], 6, 7, 8], "Flattens an array");
//t.deepEqual(flatten(args..), 'Expected');
//t.equal(flatten(args..), 'Expected');
//t.false(flatten(args..), 'Expected');
//t.throws(flatten(args..), 'Expected');
t.end();
});
test('flatten is a Function', () => {
expect(flatten).toBeInstanceOf(Function);
});
test('Flattens an array', () => {
expect(flatten([1, [2], 3, 4])).toEqual([1, 2, 3, 4]);
});
test('Flattens an array', () => {
expect(flatten([1, [2, [3, [4, 5], 6], 7], 8], 2)).toEqual([1, 2, 3, [4, 5], 6, 7, 8]);
});

View File

@ -1,15 +1,12 @@
const test = require('tape');
const expect = require('expect');
const flattenObject = require('./flattenObject.js');
test('Testing flattenObject', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof flattenObject === 'function', 'flattenObject is a Function');
t.deepEqual(flattenObject({ a: { b: { c: 1 } }, d: 1 }), { 'a.b.c': 1, d: 1 }, 'Flattens an object with the paths for keys');
t.deepEqual(flattenObject([0,1,[2,[1]],1]), { 0: 0, 1: 1, 3: 1, '2.0': 2, '2.1.0': 1 }, 'Works with arrays');
//t.deepEqual(flattenObject(args..), 'Expected');
//t.equal(flattenObject(args..), 'Expected');
//t.false(flattenObject(args..), 'Expected');
//t.throws(flattenObject(args..), 'Expected');
t.end();
test('flattenObject is a Function', () => {
expect(flattenObject).toBeInstanceOf(Function);
});
test('Flattens an object with the paths for keys', () => {
expect(flattenObject({ a: { b: { c: 1 } }, d: 1 })).toEqual({ 'a.b.c': 1, d: 1 });
});
test('Works with arrays', () => {
expect(flattenObject([0,1,[2,[1]],1])).toEqual({ 0: 0, 1: 1, 3: 1, '2.0': 2, '2.1.0': 1 });
});

View File

@ -1,18 +1,13 @@
const test = require('tape');
const expect = require('expect');
const flip = require('./flip.js');
test('Testing flip', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof flip === 'function', 'flip is a Function');
let a = { name: 'John Smith' };
let b = {};
const mergeFrom = flip(Object.assign);
let mergePerson = mergeFrom.bind(null, a);
t.deepEqual(mergePerson(b), a, 'Flips argument order');
//t.deepEqual(flip(args..), 'Expected');
//t.equal(flip(args..), 'Expected');
//t.false(flip(args..), 'Expected');
//t.throws(flip(args..), 'Expected');
t.end();
test('flip is a Function', () => {
expect(flip).toBeInstanceOf(Function);
});
let a = { name: 'John Smith' };
let b = {};
const mergeFrom = flip(Object.assign);
let mergePerson = mergeFrom.bind(null, a);
test('Flips argument order', () => {
expect(mergePerson(b)).toEqual(a);
});

View File

@ -1,16 +1,11 @@
const test = require('tape');
const expect = require('expect');
const forEachRight = require('./forEachRight.js');
test('Testing forEachRight', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof forEachRight === 'function', 'forEachRight is a Function');
let output = '';
forEachRight([1, 2, 3, 4], val => output+=val);
t.equal(output, '4321', 'Iterates over the array in reverse');
//t.deepEqual(forEachRight(args..), 'Expected');
//t.equal(forEachRight(args..), 'Expected');
//t.false(forEachRight(args..), 'Expected');
//t.throws(forEachRight(args..), 'Expected');
t.end();
test('forEachRight is a Function', () => {
expect(forEachRight).toBeInstanceOf(Function);
});
let output = '';
forEachRight([1, 2, 3, 4], val => output+=val);
test('Iterates over the array in reverse', () => {
expect(output).toBe('4321');
});

View File

@ -1,16 +1,11 @@
const test = require('tape');
const expect = require('expect');
const forOwn = require('./forOwn.js');
test('Testing forOwn', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof forOwn === 'function', 'forOwn is a Function');
let output = [];
forOwn({ foo: 'bar', a: 1 }, v => output.push(v)); // 'bar', 1
t.deepEqual(output, ['bar', 1], 'Iterates over an element\'s key-value pairs');
//t.deepEqual(forOwn(args..), 'Expected');
//t.equal(forOwn(args..), 'Expected');
//t.false(forOwn(args..), 'Expected');
//t.throws(forOwn(args..), 'Expected');
t.end();
test('forOwn is a Function', () => {
expect(forOwn).toBeInstanceOf(Function);
});
let output = [];
forOwn({ foo: 'bar', a: 1 }, v => output.push(v));
test('Iterates over an element\'s key-value pairs', () => {
expect(output).toEqual(['bar', 1]);
});

View File

@ -1,16 +1,11 @@
const test = require('tape');
const expect = require('expect');
const forOwnRight = require('./forOwnRight.js');
test('Testing forOwnRight', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof forOwnRight === 'function', 'forOwnRight is a Function');
let output = [];
forOwnRight({ foo: 'bar', a: 1 }, v => output.push(v)); // 'bar', 1
t.deepEqual(output, [1, 'bar'], 'Iterates over an element\'s key-value pairs in reverse');
//t.deepEqual(forOwnRight(args..), 'Expected');
//t.equal(forOwnRight(args..), 'Expected');
//t.false(forOwnRight(args..), 'Expected');
//t.throws(forOwnRight(args..), 'Expected');
t.end();
test('forOwnRight is a Function', () => {
expect(forOwnRight).toBeInstanceOf(Function);
});
let output = [];
forOwnRight({ foo: 'bar', a: 1 }, v => output.push(v));
test('Iterates over an element\'s key-value pairs in reverse', () => {
expect(output).toEqual([1, 'bar']);
});

View File

@ -1,15 +1,12 @@
const test = require('tape');
const expect = require('expect');
const formatDuration = require('./formatDuration.js');
test('Testing formatDuration', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof formatDuration === 'function', 'formatDuration is a Function');
t.equal(formatDuration(1001), '1 second, 1 millisecond', "Returns the human readable format of the given number of milliseconds");
t.equal(formatDuration(34325055574), '397 days, 6 hours, 44 minutes, 15 seconds, 574 milliseconds', "Returns the human readable format of the given number of milliseconds");
//t.deepEqual(formatDuration(args..), 'Expected');
//t.equal(formatDuration(args..), 'Expected');
//t.false(formatDuration(args..), 'Expected');
//t.throws(formatDuration(args..), 'Expected');
t.end();
});
test('formatDuration is a Function', () => {
expect(formatDuration).toBeInstanceOf(Function);
});
test('Returns the human readable format of the given number of milliseconds', () => {
expect(formatDuration(1001)).toBe('1 second, 1 millisecond');
});
test('Returns the human readable format of the given number of milliseconds', () => {
expect(formatDuration(34325055574)).toBe('397 days, 6 hours, 44 minutes, 15 seconds, 574 milliseconds');
});

View File

@ -1,16 +1,15 @@
const test = require('tape');
const expect = require('expect');
const fromCamelCase = require('./fromCamelCase.js');
test('Testing fromCamelCase', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof fromCamelCase === 'function', 'fromCamelCase is a Function');
t.equal(fromCamelCase('someDatabaseFieldName', ' '), 'some database field name', "Converts a string from camelcase");
t.equal(fromCamelCase('someLabelThatNeedsToBeCamelized', '-'), 'some-label-that-needs-to-be-camelized', "Converts a string from camelcase");
t.equal(fromCamelCase('someJavascriptProperty', '_'), 'some_javascript_property', "Converts a string from camelcase");
//t.deepEqual(fromCamelCase(args..), 'Expected');
//t.equal(fromCamelCase(args..), 'Expected');
//t.false(fromCamelCase(args..), 'Expected');
//t.throws(fromCamelCase(args..), 'Expected');
t.end();
});
test('fromCamelCase is a Function', () => {
expect(fromCamelCase).toBeInstanceOf(Function);
});
test('Converts a string from camelcase', () => {
expect(fromCamelCase('someDatabaseFieldName', ' ')).toBe('some database field name');
});
test('Converts a string from camelcase', () => {
expect(fromCamelCase('someLabelThatNeedsToBeCamelized', '-')).toBe('some-label-that-needs-to-be-camelized');
});
test('Converts a string from camelcase', () => {
expect(fromCamelCase('someJavascriptProperty', '_')).toBe('some_javascript_property');
});

View File

@ -1,26 +1,18 @@
const test = require('tape');
//const functionName = require('./functionName.js');
// Custom override for console.debug to check output.
const expect = require('expect');
let output = '';
const console = {};
console.debug = (x) => output = x;
// Override for testing
const functionName = fn => (console.debug(fn.name), fn);
test('Testing functionName', (t) => {
//For more information on all the methods supported by tape
//Please go to https://github.com/substack/tape
t.true(typeof functionName === 'function', 'functionName is a Function');
functionName(Math.max);
t.equal(output, 'max', 'Works for native functions');
function fun(x) {return x;}
functionName(fun);
t.equal(output, 'fun', 'Works for functions');
const fn = x => x;
functionName(fn);
t.equal(output, 'fn', 'Works for arrow functions');
//t.deepEqual(functionName(args..), 'Expected');
//t.equal(functionName(args..), 'Expected');
//t.false(functionName(args..), 'Expected');
//t.throws(functionName(args..), 'Expected');
t.end();
const functionName = fn => fn.name;
test('functionName is a Function', () => {
expect(functionName).toBeInstanceOf(Function);
});
test('Works for native functions', () => {
expect(functionName(Math.max)).toBe('max');
});
function fun(x) {return x;}
test('Works for functions', () => {
expect(functionName(fun)).toBe('fun');
});
const fn = x => x;
test('Works for arrow functions', () => {
expect(functionName(fn)).toBe('fn');
});

Some files were not shown because too many files have changed in this diff Show More