Added some tests
This commit is contained in:
@ -6,8 +6,8 @@ Use `Array.forEach()` to return a `function` that uses `Function.apply()` to app
|
|||||||
const bindAll = (obj, ...fns) =>
|
const bindAll = (obj, ...fns) =>
|
||||||
fns.forEach(
|
fns.forEach(
|
||||||
fn =>
|
fn =>
|
||||||
(obj[fn] = function() {
|
(f = obj[fn], obj[fn] = function() {
|
||||||
return fn.apply(obj);
|
return f.apply(obj);
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
```
|
```
|
||||||
|
|||||||
@ -6,6 +6,8 @@ test('Testing anagrams', (t) => {
|
|||||||
//Please go to https://github.com/substack/tape
|
//Please go to https://github.com/substack/tape
|
||||||
t.true(typeof anagrams === 'function', 'anagrams is a Function');
|
t.true(typeof anagrams === 'function', 'anagrams is a Function');
|
||||||
t.deepEqual(anagrams('abc'), ['abc','acb','bac','bca','cab','cba'], "Generates all anagrams of a string");
|
t.deepEqual(anagrams('abc'), ['abc','acb','bac','bca','cab','cba'], "Generates all anagrams of a string");
|
||||||
|
t.deepEqual(anagrams('a'), ['a'], "Works for single-letter strings");
|
||||||
|
t.deepEqual(anagrams(''), [''], "Works for empty strings");
|
||||||
//t.deepEqual(anagrams(args..), 'Expected');
|
//t.deepEqual(anagrams(args..), 'Expected');
|
||||||
//t.equal(anagrams(args..), 'Expected');
|
//t.equal(anagrams(args..), 'Expected');
|
||||||
//t.false(anagrams(args..), 'Expected');
|
//t.false(anagrams(args..), 'Expected');
|
||||||
|
|||||||
@ -5,6 +5,8 @@ test('Testing ary', (t) => {
|
|||||||
//For more information on all the methods supported by tape
|
//For more information on all the methods supported by tape
|
||||||
//Please go to https://github.com/substack/tape
|
//Please go to https://github.com/substack/tape
|
||||||
t.true(typeof ary === 'function', 'ary is a Function');
|
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.deepEqual(ary(args..), 'Expected');
|
||||||
//t.equal(ary(args..), 'Expected');
|
//t.equal(ary(args..), 'Expected');
|
||||||
//t.false(ary(args..), 'Expected');
|
//t.false(ary(args..), 'Expected');
|
||||||
|
|||||||
8
test/attempt/attempt.js
Normal file
8
test/attempt/attempt.js
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
const attempt = (fn, ...args) => {
|
||||||
|
try {
|
||||||
|
return fn(args);
|
||||||
|
} catch (e) {
|
||||||
|
return e instanceof Error ? e : new Error(e);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
module.exports = attempt
|
||||||
15
test/attempt/attempt.test.js
Normal file
15
test/attempt/attempt.test.js
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
const test = require('tape');
|
||||||
|
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();
|
||||||
|
});
|
||||||
@ -5,6 +5,12 @@ test('Testing bind', (t) => {
|
|||||||
//For more information on all the methods supported by tape
|
//For more information on all the methods supported by tape
|
||||||
//Please go to https://github.com/substack/tape
|
//Please go to https://github.com/substack/tape
|
||||||
t.true(typeof bind === 'function', 'bind is a Function');
|
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.deepEqual(bind(args..), 'Expected');
|
||||||
//t.equal(bind(args..), 'Expected');
|
//t.equal(bind(args..), 'Expected');
|
||||||
//t.false(bind(args..), 'Expected');
|
//t.false(bind(args..), 'Expected');
|
||||||
|
|||||||
@ -1,8 +1,8 @@
|
|||||||
const bindAll = (obj, ...fns) =>
|
const bindAll = (obj, ...fns) =>
|
||||||
fns.forEach(
|
fns.forEach(
|
||||||
fn =>
|
fn =>
|
||||||
(obj[fn] = function() {
|
(f = obj[fn], obj[fn] = function() {
|
||||||
return fn.apply(obj);
|
return f.apply(obj);
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
module.exports = bindAll
|
module.exports = bindAll
|
||||||
@ -5,6 +5,14 @@ test('Testing bindAll', (t) => {
|
|||||||
//For more information on all the methods supported by tape
|
//For more information on all the methods supported by tape
|
||||||
//Please go to https://github.com/substack/tape
|
//Please go to https://github.com/substack/tape
|
||||||
t.true(typeof bindAll === 'function', 'bindAll is a Function');
|
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.deepEqual(bindAll(args..), 'Expected');
|
||||||
//t.equal(bindAll(args..), 'Expected');
|
//t.equal(bindAll(args..), 'Expected');
|
||||||
//t.false(bindAll(args..), 'Expected');
|
//t.false(bindAll(args..), 'Expected');
|
||||||
|
|||||||
@ -5,6 +5,14 @@ test('Testing bindKey', (t) => {
|
|||||||
//For more information on all the methods supported by tape
|
//For more information on all the methods supported by tape
|
||||||
//Please go to https://github.com/substack/tape
|
//Please go to https://github.com/substack/tape
|
||||||
t.true(typeof bindKey === 'function', 'bindKey is a Function');
|
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.deepEqual(bindKey(args..), 'Expected');
|
||||||
//t.equal(bindKey(args..), 'Expected');
|
//t.equal(bindKey(args..), 'Expected');
|
||||||
//t.false(bindKey(args..), 'Expected');
|
//t.false(bindKey(args..), 'Expected');
|
||||||
|
|||||||
@ -5,6 +5,9 @@ test('Testing byteSize', (t) => {
|
|||||||
//For more information on all the methods supported by tape
|
//For more information on all the methods supported by tape
|
||||||
//Please go to https://github.com/substack/tape
|
//Please go to https://github.com/substack/tape
|
||||||
t.true(typeof byteSize === 'function', 'byteSize is a Function');
|
t.true(typeof byteSize === 'function', 'byteSize is a Function');
|
||||||
|
// 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
|
// Works only in browser
|
||||||
// t.equal(byteSize('Hello World'), 11, "Returns the length of a string in bytes");
|
// t.equal(byteSize('Hello World'), 11, "Returns the length of a string in bytes");
|
||||||
//t.deepEqual(byteSize(args..), 'Expected');
|
//t.deepEqual(byteSize(args..), 'Expected');
|
||||||
|
|||||||
10
test/debounce/debounce.js
Normal file
10
test/debounce/debounce.js
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
const debounce = (fn, wait = 0) => {
|
||||||
|
let inDebounce;
|
||||||
|
return function() {
|
||||||
|
const context = this,
|
||||||
|
args = arguments;
|
||||||
|
clearTimeout(inDebounce);
|
||||||
|
inDebounce = setTimeout(() => fn.apply(context, args), wait);
|
||||||
|
};
|
||||||
|
};
|
||||||
|
module.exports = debounce
|
||||||
13
test/debounce/debounce.test.js
Normal file
13
test/debounce/debounce.test.js
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
const test = require('tape');
|
||||||
|
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');
|
||||||
|
//t.deepEqual(debounce(args..), 'Expected');
|
||||||
|
//t.equal(debounce(args..), 'Expected');
|
||||||
|
//t.false(debounce(args..), 'Expected');
|
||||||
|
//t.throws(debounce(args..), 'Expected');
|
||||||
|
t.end();
|
||||||
|
});
|
||||||
2
test/overArgs/overArgs.js
Normal file
2
test/overArgs/overArgs.js
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
const overArgs = (fn, transforms) => (...args) => fn(...args.map((val, i) => transforms[i](val)));
|
||||||
|
module.exports = overArgs
|
||||||
13
test/overArgs/overArgs.test.js
Normal file
13
test/overArgs/overArgs.test.js
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
const test = require('tape');
|
||||||
|
const overArgs = require('./overArgs.js');
|
||||||
|
|
||||||
|
test('Testing overArgs', (t) => {
|
||||||
|
//For more information on all the methods supported by tape
|
||||||
|
//Please go to https://github.com/substack/tape
|
||||||
|
t.true(typeof overArgs === 'function', 'overArgs is a Function');
|
||||||
|
//t.deepEqual(overArgs(args..), 'Expected');
|
||||||
|
//t.equal(overArgs(args..), 'Expected');
|
||||||
|
//t.false(overArgs(args..), 'Expected');
|
||||||
|
//t.throws(overArgs(args..), 'Expected');
|
||||||
|
t.end();
|
||||||
|
});
|
||||||
8
test/rearg/rearg.js
Normal file
8
test/rearg/rearg.js
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
const rearg = (fn, indexes) => (...args) =>
|
||||||
|
fn(
|
||||||
|
...args.reduce(
|
||||||
|
(acc, val, i) => ((acc[indexes.indexOf(i)] = val), acc),
|
||||||
|
Array.from({ length: indexes.length })
|
||||||
|
)
|
||||||
|
);
|
||||||
|
module.exports = rearg
|
||||||
13
test/rearg/rearg.test.js
Normal file
13
test/rearg/rearg.test.js
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
const test = require('tape');
|
||||||
|
const rearg = require('./rearg.js');
|
||||||
|
|
||||||
|
test('Testing rearg', (t) => {
|
||||||
|
//For more information on all the methods supported by tape
|
||||||
|
//Please go to https://github.com/substack/tape
|
||||||
|
t.true(typeof rearg === 'function', 'rearg is a Function');
|
||||||
|
//t.deepEqual(rearg(args..), 'Expected');
|
||||||
|
//t.equal(rearg(args..), 'Expected');
|
||||||
|
//t.false(rearg(args..), 'Expected');
|
||||||
|
//t.throws(rearg(args..), 'Expected');
|
||||||
|
t.end();
|
||||||
|
});
|
||||||
125
test/testlog
125
test/testlog
@ -1,4 +1,4 @@
|
|||||||
Test log for: Sun Jan 28 2018 14:28:04 GMT+0200 (GTB Standard Time)
|
Test log for: Sun Jan 28 2018 16:28:45 GMT+0200 (GTB Standard Time)
|
||||||
|
|
||||||
> 30-seconds-of-code@0.0.1 test G:\My Files\git Repositories\30-seconds-of-code
|
> 30-seconds-of-code@0.0.1 test G:\My Files\git Repositories\30-seconds-of-code
|
||||||
> tape test/**/*.test.js | tap-spec
|
> tape test/**/*.test.js | tap-spec
|
||||||
@ -8,6 +8,8 @@ Test log for: Sun Jan 28 2018 14:28:04 GMT+0200 (GTB Standard Time)
|
|||||||
|
|
||||||
√ anagrams is a Function
|
√ anagrams is a Function
|
||||||
√ Generates all anagrams of a string
|
√ Generates all anagrams of a string
|
||||||
|
√ Works for single-letter strings
|
||||||
|
√ Works for empty strings
|
||||||
|
|
||||||
Testing arrayToHtmlList
|
Testing arrayToHtmlList
|
||||||
|
|
||||||
@ -17,6 +19,7 @@ Test log for: Sun Jan 28 2018 14:28:04 GMT+0200 (GTB Standard Time)
|
|||||||
Testing ary
|
Testing ary
|
||||||
|
|
||||||
√ ary is a Function
|
√ ary is a Function
|
||||||
|
√ Discards arguments with index >=n
|
||||||
|
|
||||||
Testing atob
|
Testing atob
|
||||||
|
|
||||||
@ -24,6 +27,12 @@ Test log for: Sun Jan 28 2018 14:28:04 GMT+0200 (GTB Standard Time)
|
|||||||
√ atob("Zm9vYmFy") equals "foobar"
|
√ atob("Zm9vYmFy") equals "foobar"
|
||||||
√ atob("Z") returns ""
|
√ atob("Z") returns ""
|
||||||
|
|
||||||
|
Testing attempt
|
||||||
|
|
||||||
|
√ attempt is a Function
|
||||||
|
√ Returns a value
|
||||||
|
√ Returns an error
|
||||||
|
|
||||||
Testing average
|
Testing average
|
||||||
|
|
||||||
√ average is a Function
|
√ average is a Function
|
||||||
@ -52,14 +61,17 @@ Test log for: Sun Jan 28 2018 14:28:04 GMT+0200 (GTB Standard Time)
|
|||||||
Testing bind
|
Testing bind
|
||||||
|
|
||||||
√ bind is a Function
|
√ bind is a Function
|
||||||
|
√ Binds to an object context
|
||||||
|
|
||||||
Testing bindAll
|
Testing bindAll
|
||||||
|
|
||||||
√ bindAll is a Function
|
√ bindAll is a Function
|
||||||
|
√ Binds to an object context
|
||||||
|
|
||||||
Testing bindKey
|
Testing bindKey
|
||||||
|
|
||||||
√ bindKey is a Function
|
√ bindKey is a Function
|
||||||
|
√ Binds function to an object context
|
||||||
|
|
||||||
Testing bottomVisible
|
Testing bottomVisible
|
||||||
|
|
||||||
@ -202,6 +214,10 @@ Test log for: Sun Jan 28 2018 14:28:04 GMT+0200 (GTB Standard Time)
|
|||||||
√ curries a Math.pow
|
√ curries a Math.pow
|
||||||
√ curries a Math.min
|
√ curries a Math.min
|
||||||
|
|
||||||
|
Testing debounce
|
||||||
|
|
||||||
|
√ debounce is a Function
|
||||||
|
|
||||||
Testing decapitalize
|
Testing decapitalize
|
||||||
|
|
||||||
√ decapitalize is a Function
|
√ decapitalize is a Function
|
||||||
@ -959,6 +975,10 @@ Test log for: Sun Jan 28 2018 14:28:04 GMT+0200 (GTB Standard Time)
|
|||||||
|
|
||||||
√ over is a Function
|
√ over is a Function
|
||||||
|
|
||||||
|
Testing overArgs
|
||||||
|
|
||||||
|
√ overArgs is a Function
|
||||||
|
|
||||||
Testing palindrome
|
Testing palindrome
|
||||||
|
|
||||||
√ palindrome is a Function
|
√ palindrome is a Function
|
||||||
@ -1082,6 +1102,10 @@ Test log for: Sun Jan 28 2018 14:28:04 GMT+0200 (GTB Standard Time)
|
|||||||
|
|
||||||
√ README is a Function
|
√ README is a Function
|
||||||
|
|
||||||
|
Testing rearg
|
||||||
|
|
||||||
|
√ rearg is a Function
|
||||||
|
|
||||||
Testing redirect
|
Testing redirect
|
||||||
|
|
||||||
√ redirect is a Function
|
√ redirect is a Function
|
||||||
@ -1125,7 +1149,16 @@ Test log for: Sun Jan 28 2018 14:28:04 GMT+0200 (GTB Standard Time)
|
|||||||
Testing round
|
Testing round
|
||||||
|
|
||||||
√ round is a Function
|
√ round is a Function
|
||||||
√ Rounds a number to a specified amount of digits.
|
√ round(1.005, 2) returns 1.01
|
||||||
|
√ round(123.3423345345345345344, 11) returns 123.34233453453
|
||||||
|
√ round(3.342, 11) returns 3.342
|
||||||
|
√ round(1.005) returns 1
|
||||||
|
√ round([1.005, 2]) returns NaN
|
||||||
|
√ round(string) returns NaN
|
||||||
|
√ round() returns NaN
|
||||||
|
√ round(132, 413, 4134) returns NaN
|
||||||
|
√ round({a: 132}, 413) returns NaN
|
||||||
|
√ round(123.3423345345345345344, 11) takes less than 2s to run
|
||||||
|
|
||||||
Testing runAsync
|
Testing runAsync
|
||||||
|
|
||||||
@ -1295,6 +1328,10 @@ Test log for: Sun Jan 28 2018 14:28:04 GMT+0200 (GTB Standard Time)
|
|||||||
|
|
||||||
√ takeWhile is a Function
|
√ takeWhile is a Function
|
||||||
|
|
||||||
|
Testing throttle
|
||||||
|
|
||||||
|
√ throttle is a Function
|
||||||
|
|
||||||
Testing times
|
Testing times
|
||||||
|
|
||||||
√ times is a Function
|
√ times is a Function
|
||||||
@ -1306,10 +1343,15 @@ Test log for: Sun Jan 28 2018 14:28:04 GMT+0200 (GTB Standard Time)
|
|||||||
Testing toCamelCase
|
Testing toCamelCase
|
||||||
|
|
||||||
√ toCamelCase is a Function
|
√ toCamelCase is a Function
|
||||||
√ Converts a string to camelCase
|
√ toCamelCase('some_database_field_name') returns someDatabaseFieldName
|
||||||
√ Converts a string to camelCase
|
√ toCamelCase('Some label that needs to be camelized') returns someLabelThatNeedsToBeCamelized
|
||||||
√ Converts a string to camelCase
|
√ toCamelCase('some-javascript-property') return someJavascriptProperty
|
||||||
√ Converts a string to camelCase
|
√ toCamelCase('some-mixed_string with spaces_underscores-and-hyphens') returns someMixedStringWithSpacesUnderscoresAndHyphens
|
||||||
|
√ toCamelCase() throws a error
|
||||||
|
√ toCamelCase([]) throws a error
|
||||||
|
√ toCamelCase({}) throws a error
|
||||||
|
√ toCamelCase(123) throws a error
|
||||||
|
√ toCamelCase(some-mixed_string with spaces_underscores-and-hyphens) takes less than 2s to run
|
||||||
|
|
||||||
Testing toDecimalMark
|
Testing toDecimalMark
|
||||||
|
|
||||||
@ -1323,10 +1365,15 @@ Test log for: Sun Jan 28 2018 14:28:04 GMT+0200 (GTB Standard Time)
|
|||||||
Testing toKebabCase
|
Testing toKebabCase
|
||||||
|
|
||||||
√ toKebabCase is a Function
|
√ toKebabCase is a Function
|
||||||
√ string converts to snake case
|
√ toKebabCase('camelCase') returns camel-case
|
||||||
√ string converts to snake case
|
√ toKebabCase('some text') returns some-text
|
||||||
√ string converts to snake case
|
√ toKebabCase('some-mixed-string With spaces-underscores-and-hyphens') returns some-mixed-string-with-spaces-underscores-and-hyphens
|
||||||
√ string converts to snake case
|
√ toKebabCase('IAmListeningToFMWhileLoadingDifferentURLOnMyBrowserAndAlsoEditingSomeXMLAndHTML') returns i-am-listening-to-fm-while-loading-different-url-on-my-browser-and-also-editing-some-xml-and-html
|
||||||
|
√ toKebabCase() return undefined
|
||||||
|
√ toKebabCase([]) throws an error
|
||||||
|
√ toKebabCase({}) throws an error
|
||||||
|
√ toKebabCase(123) throws an error
|
||||||
|
√ toKebabCase(IAmListeningToFMWhileLoadingDifferentURLOnMyBrowserAndAlsoEditingSomeXMLAndHTML) takes less than 2s to run
|
||||||
|
|
||||||
Testing tomorrow
|
Testing tomorrow
|
||||||
|
|
||||||
@ -1343,19 +1390,30 @@ Test log for: Sun Jan 28 2018 14:28:04 GMT+0200 (GTB Standard Time)
|
|||||||
Testing toSafeInteger
|
Testing toSafeInteger
|
||||||
|
|
||||||
√ toSafeInteger is a Function
|
√ toSafeInteger is a Function
|
||||||
|
√ Number(toSafeInteger(3.2)) is a number
|
||||||
√ Converts a value to a safe integer
|
√ Converts a value to a safe integer
|
||||||
√ Converts a value to a safe integer
|
√ toSafeInteger('4.2') returns 4
|
||||||
√ Converts a value to a safe integer
|
√ toSafeInteger(4.6) returns 5
|
||||||
√ Converts a value to a safe integer
|
√ toSafeInteger([]) returns 0
|
||||||
√ Converts a value to a safe integer
|
√ isNaN(toSafeInteger([1.5, 3124])) is true
|
||||||
|
√ isNaN(toSafeInteger('string')) is true
|
||||||
|
√ isNaN(toSafeInteger({})) is true
|
||||||
|
√ isNaN(toSafeInteger()) is true
|
||||||
|
√ toSafeInteger(Infinity) returns 9007199254740991
|
||||||
|
√ toSafeInteger(3.2) takes less than 2s to run
|
||||||
|
|
||||||
Testing toSnakeCase
|
Testing toSnakeCase
|
||||||
|
|
||||||
√ toSnakeCase is a Function
|
√ toSnakeCase is a Function
|
||||||
√ string converts to snake case
|
√ toSnakeCase('camelCase') returns camel_case
|
||||||
√ string converts to snake case
|
√ toSnakeCase('some text') returns some_text
|
||||||
√ string converts to snake case
|
√ toSnakeCase('some-mixed_string With spaces_underscores-and-hyphens') returns some_mixed_string_with_spaces_underscores_and_hyphens
|
||||||
√ string converts to snake case
|
√ toSnakeCase('IAmListeningToFMWhileLoadingDifferentURLOnMyBrowserAndAlsoEditingSomeXMLAndHTML') returns i_am_listening_to_fm_while_loading_different_url_on_my_browser_and_also_editing_some_xml_and_html
|
||||||
|
√ toSnakeCase() returns undefined
|
||||||
|
√ toSnakeCase([]) throws an error
|
||||||
|
√ toSnakeCase({}) throws an error
|
||||||
|
√ toSnakeCase(123) throws an error
|
||||||
|
√ toSnakeCase(IAmListeningToFMWhileLoadingDifferentURLOnMyBrowserAndAlsoEditingSomeXMLAndHTML) takes less than 2s to run
|
||||||
|
|
||||||
Testing transform
|
Testing transform
|
||||||
|
|
||||||
@ -1387,7 +1445,17 @@ Test log for: Sun Jan 28 2018 14:28:04 GMT+0200 (GTB Standard Time)
|
|||||||
Testing union
|
Testing union
|
||||||
|
|
||||||
√ union is a Function
|
√ union is a Function
|
||||||
√ Returns every element that exists in any of the two arrays once
|
√ union([1, 2, 3], [4, 3, 2]) returns [1, 2, 3, 4]
|
||||||
|
√ union('str', 'asd') returns [ 's', 't', 'r', 'a', 'd' ]
|
||||||
|
√ union([[], {}], [1, 2, 3]) returns [[], {}, 1, 2, 3]
|
||||||
|
√ union([], []) returns []
|
||||||
|
√ union() throws an error
|
||||||
|
√ union(true, str) throws an error
|
||||||
|
√ union(false, true) throws an error
|
||||||
|
√ union(123, {}) throws an error
|
||||||
|
√ union([], {}) throws an error
|
||||||
|
√ union(undefined, null) throws an error
|
||||||
|
√ union([1, 2, 3], [4, 3, 2]) takes less than 2s to run
|
||||||
|
|
||||||
Testing unionBy
|
Testing unionBy
|
||||||
|
|
||||||
@ -1400,7 +1468,18 @@ Test log for: Sun Jan 28 2018 14:28:04 GMT+0200 (GTB Standard Time)
|
|||||||
Testing uniqueElements
|
Testing uniqueElements
|
||||||
|
|
||||||
√ uniqueElements is a Function
|
√ uniqueElements is a Function
|
||||||
√ Returns all unique values of an array
|
√ uniqueElements([1, 2, 2, 3, 4, 4, 5]) returns [1,2,3,4,5]
|
||||||
|
√ uniqueElements([1, 23, 53]) returns [1, 23, 53]
|
||||||
|
√ uniqueElements([true, 0, 1, false, false, undefined, null, '']) returns [true, 0, 1, false, false, undefined, null, '']
|
||||||
|
√ uniqueElements() returns []
|
||||||
|
√ uniqueElements(null) returns []
|
||||||
|
√ uniqueElements(undefined) returns []
|
||||||
|
√ uniqueElements('strt') returns ['s', 't', 'r']
|
||||||
|
√ uniqueElements(1, 1, 2543, 534, 5) throws an error
|
||||||
|
√ uniqueElements({}) throws an error
|
||||||
|
√ uniqueElements(true) throws an error
|
||||||
|
√ uniqueElements(false) throws an error
|
||||||
|
√ uniqueElements([true, 0, 1, false, false, undefined, null]) takes less than 2s to run
|
||||||
|
|
||||||
Testing untildify
|
Testing untildify
|
||||||
|
|
||||||
@ -1524,8 +1603,8 @@ Test log for: Sun Jan 28 2018 14:28:04 GMT+0200 (GTB Standard Time)
|
|||||||
√ zipWith is a Function
|
√ zipWith is a Function
|
||||||
|
|
||||||
|
|
||||||
total: 652
|
total: 716
|
||||||
passing: 652
|
passing: 716
|
||||||
duration: 1.7s
|
duration: 1.1s
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
21
test/throttle/throttle.js
Normal file
21
test/throttle/throttle.js
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
const throttle = (fn, wait) => {
|
||||||
|
let inThrottle, lastFn, lastTime;
|
||||||
|
return function() {
|
||||||
|
const context = this,
|
||||||
|
args = arguments;
|
||||||
|
if (!inThrottle) {
|
||||||
|
fn.apply(context, args);
|
||||||
|
lastTime = Date.now();
|
||||||
|
inThrottle = true;
|
||||||
|
} else {
|
||||||
|
clearTimeout(lastFn);
|
||||||
|
lastFn = setTimeout(function() {
|
||||||
|
if (Date.now() - lastTime >= wait) {
|
||||||
|
fn.apply(context, args);
|
||||||
|
lastTime = Date.now();
|
||||||
|
}
|
||||||
|
}, wait - (Date.now() - lastTime));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
||||||
|
module.exports = throttle
|
||||||
13
test/throttle/throttle.test.js
Normal file
13
test/throttle/throttle.test.js
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
const test = require('tape');
|
||||||
|
const throttle = require('./throttle.js');
|
||||||
|
|
||||||
|
test('Testing throttle', (t) => {
|
||||||
|
//For more information on all the methods supported by tape
|
||||||
|
//Please go to https://github.com/substack/tape
|
||||||
|
t.true(typeof throttle === 'function', 'throttle is a Function');
|
||||||
|
//t.deepEqual(throttle(args..), 'Expected');
|
||||||
|
//t.equal(throttle(args..), 'Expected');
|
||||||
|
//t.false(throttle(args..), 'Expected');
|
||||||
|
//t.throws(throttle(args..), 'Expected');
|
||||||
|
t.end();
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user