From 252ed5f30400b897620f09924ab2d7651ad27484 Mon Sep 17 00:00:00 2001 From: Oscar Shrimpton Date: Tue, 30 Jan 2018 19:01:54 +0000 Subject: [PATCH 01/12] Test for binarySearch() --- test/binarySearch/binarySearch.test.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/binarySearch/binarySearch.test.js b/test/binarySearch/binarySearch.test.js index a98fc8e90..c1ed00043 100644 --- a/test/binarySearch/binarySearch.test.js +++ b/test/binarySearch/binarySearch.test.js @@ -6,7 +6,8 @@ test('Testing binarySearch', (t) => { //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(args..), 'Expected'); + t.equal(binarySearch([1, 4, 6, 7, 12, 13, 15, 18, 19, 20, 22, 24], 6), 2); + t.equal(binarySearch([1, 4, 6, 7, 12, 13, 15, 18, 19, 20, 22, 24], 21), -1); //t.false(binarySearch(args..), 'Expected'); //t.throws(binarySearch(args..), 'Expected'); t.end(); From 96dcda484a9c3147632c97a04be2589a4add2110 Mon Sep 17 00:00:00 2001 From: Oscar Shrimpton Date: Tue, 30 Jan 2018 19:11:56 +0000 Subject: [PATCH 02/12] bottomVisible() test --- test/bottomVisible/bottomVisible.test.js | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/test/bottomVisible/bottomVisible.test.js b/test/bottomVisible/bottomVisible.test.js index 1c8eae4be..dc8119130 100644 --- a/test/bottomVisible/bottomVisible.test.js +++ b/test/bottomVisible/bottomVisible.test.js @@ -1,12 +1,29 @@ const test = require('tape'); -const bottomVisible = require('./bottomVisible.js'); +// const bottomVisible = require('./bottomVisible.js'); + +// Make the fake properties used by the function +const document = { + documentElement: { + clientHeight: 1080, + scrollHeight: 1080 + } +}; + +const window = { + scrollY: 2160 +} + +// Override the function to use these fake properties +const bottomVisible = () => +document.documentElement.clientHeight + window.scrollY >= +(document.documentElement.scrollHeight || document.documentElement.clientHeight); 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.deepEqual(bottomVisible(args..), 'Expected'); - //t.equal(bottomVisible(args..), 'Expected'); + t.true(bottomVisible(), 'Produces the correct result'); //t.false(bottomVisible(args..), 'Expected'); //t.throws(bottomVisible(args..), 'Expected'); t.end(); From 998a2bbe30e89e0af2e4864f7e6bd01bec098a19 Mon Sep 17 00:00:00 2001 From: Oscar Shrimpton Date: Tue, 30 Jan 2018 19:12:58 +0000 Subject: [PATCH 03/12] Add description to binarySearch() test --- test/binarySearch/binarySearch.test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/binarySearch/binarySearch.test.js b/test/binarySearch/binarySearch.test.js index c1ed00043..cd7d7c2ed 100644 --- a/test/binarySearch/binarySearch.test.js +++ b/test/binarySearch/binarySearch.test.js @@ -6,8 +6,8 @@ test('Testing binarySearch', (t) => { //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); - t.equal(binarySearch([1, 4, 6, 7, 12, 13, 15, 18, 19, 20, 22, 24], 21), -1); + 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.false(binarySearch(args..), 'Expected'); //t.throws(binarySearch(args..), 'Expected'); t.end(); From bfa016cef12147ad407387040b5fbb9cf7797f4d Mon Sep 17 00:00:00 2001 From: Oscar Shrimpton Date: Tue, 30 Jan 2018 19:20:21 +0000 Subject: [PATCH 04/12] Test for call() --- test/call/call.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/call/call.test.js b/test/call/call.test.js index ba15d452e..bf1ed5e56 100644 --- a/test/call/call.test.js +++ b/test/call/call.test.js @@ -6,7 +6,7 @@ test('Testing call', (t) => { //Please go to https://github.com/substack/tape t.true(typeof call === 'function', 'call is a Function'); //t.deepEqual(call(args..), 'Expected'); - //t.equal(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(); From ecefcc40afdfd99be2fbb4c0dba83b7a35fddff0 Mon Sep 17 00:00:00 2001 From: Oscar Shrimpton Date: Tue, 30 Jan 2018 19:30:03 +0000 Subject: [PATCH 05/12] Fix chainAsync() throwing an error --- snippets/chainAsync.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/snippets/chainAsync.md b/snippets/chainAsync.md index 10bbf6613..20e72eae2 100644 --- a/snippets/chainAsync.md +++ b/snippets/chainAsync.md @@ -4,10 +4,12 @@ Chains asynchronous functions. Loop through an array of functions containing asynchronous events, calling `next` when each asynchronous event has completed. +The tenerary function checks the next function exists before calling it, otherwise it will exit. + ```js const chainAsync = fns => { let curr = 0; - const next = () => fns[curr++](next); + const next = () => fns[++curr] ? fns[curr](next) : false; next(); }; ``` From 19003bde9013e4d6e2b09058b34bdd097e054449 Mon Sep 17 00:00:00 2001 From: Oscar Shrimpton Date: Tue, 30 Jan 2018 19:30:09 +0000 Subject: [PATCH 06/12] Test for chainAsync() --- test/chainAsync/chainAsync.test.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/test/chainAsync/chainAsync.test.js b/test/chainAsync/chainAsync.test.js index 7101ab686..e3b3bd1f9 100644 --- a/test/chainAsync/chainAsync.test.js +++ b/test/chainAsync/chainAsync.test.js @@ -6,7 +6,24 @@ test('Testing chainAsync', (t) => { //Please go to https://github.com/substack/tape t.true(typeof chainAsync === 'function', 'chainAsync is a Function'); //t.deepEqual(chainAsync(args..), 'Expected'); - //t.equal(chainAsync(args..), 'Expected'); + chainAsync([ + next => { + next(); + }, + next => { + (() =>{ + next() + })(); + }, + next => { + t.pass("Calls all functions in an array"); + next(); + } + ]); + + // 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(); From aa46883a4b4ce1720161183f4e119a102d507d3c Mon Sep 17 00:00:00 2001 From: Oscar Shrimpton Date: Tue, 30 Jan 2018 19:41:04 +0000 Subject: [PATCH 07/12] Tests for collatz() --- test/collatz/collatz.test.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/test/collatz/collatz.test.js b/test/collatz/collatz.test.js index 1922e40ed..73ce78109 100644 --- a/test/collatz/collatz.test.js +++ b/test/collatz/collatz.test.js @@ -6,7 +6,18 @@ test('Testing collatz', (t) => { //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(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'); + + let n = 9; + while(true){ + if (n == 1){ + t.pass('Eventually reaches 1'); + break; + } + n = collatz(n); + } + //t.false(collatz(args..), 'Expected'); //t.throws(collatz(args..), 'Expected'); t.end(); From 51074375bf34985497b52e7db685190f95507229 Mon Sep 17 00:00:00 2001 From: Oscar Shrimpton Date: Tue, 30 Jan 2018 20:50:32 +0000 Subject: [PATCH 08/12] Minor linting issue --- snippets/chainAsync.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snippets/chainAsync.md b/snippets/chainAsync.md index 20e72eae2..1833eb4ad 100644 --- a/snippets/chainAsync.md +++ b/snippets/chainAsync.md @@ -9,7 +9,7 @@ The tenerary function checks the next function exists before calling it, otherwi ```js const chainAsync = fns => { let curr = 0; - const next = () => fns[++curr] ? fns[curr](next) : false; + const next = () => (fns[++curr] ? fns[curr](next) : false); next(); }; ``` From 7c3a6a72d986af8151dd4e5e74389a9f4a4722e5 Mon Sep 17 00:00:00 2001 From: Oscar Date: Wed, 31 Jan 2018 19:44:46 +0000 Subject: [PATCH 09/12] Revert bottomVisible() test --- test/bottomVisible/bottomVisible.test.js | 21 ++------------------- 1 file changed, 2 insertions(+), 19 deletions(-) diff --git a/test/bottomVisible/bottomVisible.test.js b/test/bottomVisible/bottomVisible.test.js index dc8119130..1c8eae4be 100644 --- a/test/bottomVisible/bottomVisible.test.js +++ b/test/bottomVisible/bottomVisible.test.js @@ -1,29 +1,12 @@ const test = require('tape'); -// const bottomVisible = require('./bottomVisible.js'); - -// Make the fake properties used by the function -const document = { - documentElement: { - clientHeight: 1080, - scrollHeight: 1080 - } -}; - -const window = { - scrollY: 2160 -} - -// Override the function to use these fake properties -const bottomVisible = () => -document.documentElement.clientHeight + window.scrollY >= -(document.documentElement.scrollHeight || document.documentElement.clientHeight); +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.deepEqual(bottomVisible(args..), 'Expected'); - t.true(bottomVisible(), 'Produces the correct result'); + //t.equal(bottomVisible(args..), 'Expected'); //t.false(bottomVisible(args..), 'Expected'); //t.throws(bottomVisible(args..), 'Expected'); t.end(); From f1ff5060d656684a60fe68199a0c22ff7148d363 Mon Sep 17 00:00:00 2001 From: Oscar Date: Thu, 1 Feb 2018 17:23:17 +0000 Subject: [PATCH 10/12] Fixed chainAsync() skipping the first function in the array. --- snippets/chainAsync.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snippets/chainAsync.md b/snippets/chainAsync.md index 1833eb4ad..f179ff4f8 100644 --- a/snippets/chainAsync.md +++ b/snippets/chainAsync.md @@ -9,7 +9,7 @@ The tenerary function checks the next function exists before calling it, otherwi ```js const chainAsync = fns => { let curr = 0; - const next = () => (fns[++curr] ? fns[curr](next) : false); + const next = () => (fns[curr] ? fns[curr++](next) : false); next(); }; ``` From 80382c8b39788353071e23a16f9bed3deb410b3a Mon Sep 17 00:00:00 2001 From: Angelos Chalaris Date: Sat, 3 Feb 2018 11:29:27 +0200 Subject: [PATCH 11/12] Revert changes to chainAsync.md --- snippets/chainAsync.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/snippets/chainAsync.md b/snippets/chainAsync.md index f179ff4f8..10bbf6613 100644 --- a/snippets/chainAsync.md +++ b/snippets/chainAsync.md @@ -4,12 +4,10 @@ Chains asynchronous functions. Loop through an array of functions containing asynchronous events, calling `next` when each asynchronous event has completed. -The tenerary function checks the next function exists before calling it, otherwise it will exit. - ```js const chainAsync = fns => { let curr = 0; - const next = () => (fns[curr] ? fns[curr++](next) : false); + const next = () => fns[curr++](next); next(); }; ``` From 49a81e2aac0ee67ec440578a8520bffb7a061844 Mon Sep 17 00:00:00 2001 From: Angelos Chalaris Date: Sat, 3 Feb 2018 11:32:34 +0200 Subject: [PATCH 12/12] Removed chainAsync tests (broken) --- test/chainAsync/chainAsync.test.js | 36 +++++++++++++++--------------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/test/chainAsync/chainAsync.test.js b/test/chainAsync/chainAsync.test.js index e3b3bd1f9..d013df52f 100644 --- a/test/chainAsync/chainAsync.test.js +++ b/test/chainAsync/chainAsync.test.js @@ -6,25 +6,25 @@ test('Testing chainAsync', (t) => { //Please go to https://github.com/substack/tape t.true(typeof chainAsync === 'function', 'chainAsync is a Function'); //t.deepEqual(chainAsync(args..), 'Expected'); - chainAsync([ - next => { - next(); - }, - next => { - (() =>{ - next() - })(); - }, - next => { - t.pass("Calls all functions in an array"); - next(); - } - ]); - - // Ensure we wait for the 2nd assertion to be made - t.plan(2); + // chainAsync([ + // next => { + // next(); + // }, + // next => { + // (() =>{ + // next() + // })(); + // }, + // next => { + // t.pass("Calls all functions in an array"); + // next(); + // } + // ]); + // + // // 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(); -}); \ No newline at end of file +});