Merge branch 'master' into any-all-none
This commit is contained in:
2
test/approximatelyEqual/approximatelyEqual.js
Normal file
2
test/approximatelyEqual/approximatelyEqual.js
Normal file
@ -0,0 +1,2 @@
|
||||
const approximatelyEqual = (v1, v2, epsilon = 0.001) => Math.abs(v1 - v2) < epsilon;
|
||||
module.exports = approximatelyEqual;
|
||||
17
test/approximatelyEqual/approximatelyEqual.test.js
Normal file
17
test/approximatelyEqual/approximatelyEqual.test.js
Normal file
@ -0,0 +1,17 @@
|
||||
const test = require('tape');
|
||||
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();
|
||||
});
|
||||
3
test/bifurcate/bifurcate.js
Normal file
3
test/bifurcate/bifurcate.js
Normal file
@ -0,0 +1,3 @@
|
||||
const bifurcate = (arr, filter) =>
|
||||
arr.reduce((acc, val, i) => (acc[filter[i] ? 0 : 1].push(val), acc), [[], []]);
|
||||
module.exports = bifurcate;
|
||||
14
test/bifurcate/bifurcate.test.js
Normal file
14
test/bifurcate/bifurcate.test.js
Normal file
@ -0,0 +1,14 @@
|
||||
const test = require('tape');
|
||||
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();
|
||||
});
|
||||
3
test/bifurcateBy/bifurcateBy.js
Normal file
3
test/bifurcateBy/bifurcateBy.js
Normal file
@ -0,0 +1,3 @@
|
||||
const bifurcateBy = (arr, fn) =>
|
||||
arr.reduce((acc, val, i) => (acc[fn(val, i) ? 0 : 1].push(val), acc), [[], []]);
|
||||
module.exports = bifurcateBy;
|
||||
14
test/bifurcateBy/bifurcateBy.test.js
Normal file
14
test/bifurcateBy/bifurcateBy.test.js
Normal file
@ -0,0 +1,14 @@
|
||||
const test = require('tape');
|
||||
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();
|
||||
});
|
||||
11
test/binomialCoefficient/binomialCoefficient.js
Normal file
11
test/binomialCoefficient/binomialCoefficient.js
Normal file
@ -0,0 +1,11 @@
|
||||
const binomialCoefficient = (n, k) => {
|
||||
if (Number.isNaN(n) || Number.isNaN(k)) return NaN;
|
||||
if (k < 0 || k > n) return 0;
|
||||
if (k === 0 || k === n) return 1;
|
||||
if (k === 1 || k === n - 1) return n;
|
||||
if (n - k < k) k = n - k;
|
||||
let res = n;
|
||||
for (let j = 2; j <= k; j++) res *= (n - j + 1) / j;
|
||||
return Math.round(res);
|
||||
};
|
||||
module.exports = binomialCoefficient;
|
||||
18
test/binomialCoefficient/binomialCoefficient.test.js
Normal file
18
test/binomialCoefficient/binomialCoefficient.test.js
Normal file
@ -0,0 +1,18 @@
|
||||
const test = require('tape');
|
||||
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();
|
||||
});
|
||||
2
test/degreesToRads/degreesToRads.js
Normal file
2
test/degreesToRads/degreesToRads.js
Normal file
@ -0,0 +1,2 @@
|
||||
const degreesToRads = deg => deg * Math.PI / 180.0;
|
||||
module.exports = degreesToRads;
|
||||
15
test/degreesToRads/degreesToRads.test.js
Normal file
15
test/degreesToRads/degreesToRads.test.js
Normal file
@ -0,0 +1,15 @@
|
||||
const test = require('tape');
|
||||
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();
|
||||
});
|
||||
2
test/radsToDegrees/radsToDegrees.js
Normal file
2
test/radsToDegrees/radsToDegrees.js
Normal file
@ -0,0 +1,2 @@
|
||||
const radsToDegrees = rad => rad * 180.0 / Math.PI;
|
||||
module.exports = radsToDegrees;
|
||||
14
test/radsToDegrees/radsToDegrees.test.js
Normal file
14
test/radsToDegrees/radsToDegrees.test.js
Normal file
@ -0,0 +1,14 @@
|
||||
const test = require('tape');
|
||||
const radsToDegrees = require('./radsToDegrees.js');
|
||||
|
||||
test('Testing radsToDegrees', (t) => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
t.true(typeof radsToDegrees === 'function', 'radsToDegrees is a Function');
|
||||
t.equal(radsToDegrees(Math.PI / 2), 90, 'Returns the appropriate value');
|
||||
//t.deepEqual(radsToDegrees(args..), 'Expected');
|
||||
//t.equal(radsToDegrees(args..), 'Expected');
|
||||
//t.false(radsToDegrees(args..), 'Expected');
|
||||
//t.throws(radsToDegrees(args..), 'Expected');
|
||||
t.end();
|
||||
});
|
||||
57
test/testlog
57
test/testlog
@ -1,9 +1,11 @@
|
||||
Test log for: Wed Feb 14 2018 11:45:44 GMT+0200 (GTB Standard Time)
|
||||
Test log for: Wed Feb 14 2018 12:46:59 GMT+0200 (GTB Standard Time)
|
||||
|
||||
> 30-seconds-of-code@0.0.1 test G:\My Files\git Repositories\30-seconds-of-code
|
||||
> tape test/**/*.test.js | tap-spec
|
||||
|
||||
|
||||
|
||||
Testing all
|
||||
|
||||
√ all is a Function
|
||||
@ -39,6 +41,21 @@ Test log for: Wed Feb 14 2018 11:45:44 GMT+0200 (GTB Standard Time)
|
||||
√ anyBy is a Function
|
||||
√ Returns true with predicate function
|
||||
√ Returns false with a predicate function
|
||||
|
||||
Testing anagrams
|
||||
|
||||
√ anagrams is a Function
|
||||
√ Generates all anagrams of a string
|
||||
√ Works for single-letter strings
|
||||
√ Works for empty strings
|
||||
|
||||
Testing approximatelyEqual
|
||||
|
||||
√ approximatelyEqual is a Function
|
||||
√ Works for PI / 2
|
||||
√ Works for 0.1 + 0.2 === 0.3
|
||||
√ Works for exactly equal values
|
||||
√ Works for a custom epsilon
|
||||
|
||||
Testing arrayToHtmlList
|
||||
|
||||
@ -82,6 +99,16 @@ Test log for: Wed Feb 14 2018 11:45:44 GMT+0200 (GTB Standard Time)
|
||||
√ Produces the right result with a function
|
||||
√ Produces the right result with a property name
|
||||
|
||||
Testing bifurcate
|
||||
|
||||
√ bifurcate is a Function
|
||||
√ Splits the collection into two groups
|
||||
|
||||
Testing bifurcateBy
|
||||
|
||||
√ bifurcateBy is a Function
|
||||
√ Splits the collection into two groups
|
||||
|
||||
Testing binarySearch
|
||||
|
||||
√ binarySearch is a Function
|
||||
@ -105,6 +132,15 @@ Test log for: Wed Feb 14 2018 11:45:44 GMT+0200 (GTB Standard Time)
|
||||
√ bindKey is a Function
|
||||
√ Binds function to an object context
|
||||
|
||||
Testing binomialCoefficient
|
||||
|
||||
√ binomialCoefficient is a Function
|
||||
√ Returns the appropriate value
|
||||
√ Returns the appropriate value
|
||||
√ Returns the appropriate value
|
||||
√ Returns NaN
|
||||
√ Returns NaN
|
||||
|
||||
Testing bottomVisible
|
||||
|
||||
√ bottomVisible is a Function
|
||||
@ -297,6 +333,11 @@ Test log for: Wed Feb 14 2018 11:45:44 GMT+0200 (GTB Standard Time)
|
||||
|
||||
√ defer is a Function
|
||||
|
||||
Testing degreesToRads
|
||||
|
||||
√ degreesToRads is a Function
|
||||
√ Returns the appropriate value
|
||||
|
||||
Testing delay
|
||||
|
||||
√ delay is a Function
|
||||
@ -1252,6 +1293,11 @@ Test log for: Wed Feb 14 2018 11:45:44 GMT+0200 (GTB Standard Time)
|
||||
√ quickSort(undefined) throws an error
|
||||
√ quickSort([11, 1, 324, 23232, -1, 53, 2, 524, 32, 13, 156, 133, 62, 12, 4]) takes less than 2s to run
|
||||
|
||||
Testing radsToDegrees
|
||||
|
||||
√ radsToDegrees is a Function
|
||||
√ Returns the appropriate value
|
||||
|
||||
Testing randomHexColorCode
|
||||
|
||||
√ randomHexColorCode is a Function
|
||||
@ -1655,6 +1701,13 @@ Test log for: Wed Feb 14 2018 11:45:44 GMT+0200 (GTB Standard Time)
|
||||
√ unary is a Function
|
||||
√ Discards arguments after the first one
|
||||
|
||||
Testing uncurry
|
||||
|
||||
√ uncurry is a Function
|
||||
√ Works without a provided value for n
|
||||
√ Works without n = 2
|
||||
√ Works withoutn = 3
|
||||
|
||||
Testing unescapeHTML
|
||||
|
||||
√ unescapeHTML is a Function
|
||||
@ -1839,6 +1892,8 @@ Test log for: Wed Feb 14 2018 11:45:44 GMT+0200 (GTB Standard Time)
|
||||
√ zipWith is a Function
|
||||
√ Runs the function provided
|
||||
√ Sends a GET request
|
||||
√ Sends a GET request
|
||||
√ Runs the function provided
|
||||
√ Runs promises in series
|
||||
√ Sends a POST request
|
||||
√ Works with multiple promises
|
||||
@ -1846,6 +1901,6 @@ Test log for: Wed Feb 14 2018 11:45:44 GMT+0200 (GTB Standard Time)
|
||||
|
||||
total: 924
|
||||
passing: 924
|
||||
duration: 2.4s
|
||||
duration: 2.5s
|
||||
|
||||
|
||||
|
||||
6
test/uncurry/uncurry.js
Normal file
6
test/uncurry/uncurry.js
Normal file
@ -0,0 +1,6 @@
|
||||
const uncurry = (fn, n = 1) => (...args) => {
|
||||
const next = acc => args => args.reduce((x, y) => x(y), acc);
|
||||
if (n > args.length) throw new RangeError('Arguments too few!');
|
||||
return next(fn)(args.slice(0, n));
|
||||
};
|
||||
module.exports = uncurry;
|
||||
20
test/uncurry/uncurry.test.js
Normal file
20
test/uncurry/uncurry.test.js
Normal file
@ -0,0 +1,20 @@
|
||||
const test = require('tape');
|
||||
const uncurry = require('./uncurry.js');
|
||||
|
||||
test('Testing uncurry', (t) => {
|
||||
//For more information on all the methods supported by tape
|
||||
//Please go to https://github.com/substack/tape
|
||||
t.true(typeof uncurry === 'function', 'uncurry is a Function');
|
||||
const add = x => y => z => x + y + z;
|
||||
const add1 = uncurry(add);
|
||||
const add2 = uncurry(add, 2);
|
||||
const add3 = uncurry(add, 3);
|
||||
t.equal(add1(1)(2)(3), 6, 'Works without a provided value for n');
|
||||
t.equal(add2(1,2)(3), 6, 'Works without n = 2');
|
||||
t.equal(add3(1,2,3), 6, 'Works withoutn = 3');
|
||||
//t.deepEqual(uncurry(args..), 'Expected');
|
||||
//t.equal(uncurry(args..), 'Expected');
|
||||
//t.false(uncurry(args..), 'Expected');
|
||||
//t.throws(uncurry(args..), 'Expected');
|
||||
t.end();
|
||||
});
|
||||
Reference in New Issue
Block a user