From a9d67950d91b55fab4ad3dfecd5cd06456a0b074 Mon Sep 17 00:00:00 2001 From: Angelos Chalaris Date: Wed, 24 Jan 2018 17:38:08 +0200 Subject: [PATCH] Tests for averageBy, maxBy, minBy Fixed examples in minBy --- snippets/minBy.md | 4 ++-- test/averageBy/averageBy.test.js | 4 +++- test/maxBy/maxBy.test.js | 4 +++- test/minBy/minBy.test.js | 4 +++- test/testlog | 14 ++++++++++---- test/xProd/xProd.js | 2 +- 6 files changed, 22 insertions(+), 10 deletions(-) diff --git a/snippets/minBy.md b/snippets/minBy.md index 594d83f5e..e9d8a53e2 100644 --- a/snippets/minBy.md +++ b/snippets/minBy.md @@ -9,6 +9,6 @@ const minBy = (arr, fn) => Math.min(...arr.map(typeof fn === 'function' ? fn : v ``` ```js -minBy([{ n: 4 }, { n: 2 }, { n: 8 }, { n: 6 }], o => o.n); // 8 -minBy([{ n: 4 }, { n: 2 }, { n: 8 }, { n: 6 }], 'n'); // 8 +minBy([{ n: 4 }, { n: 2 }, { n: 8 }, { n: 6 }], o => o.n); // 2 +minBy([{ n: 4 }, { n: 2 }, { n: 8 }, { n: 6 }], 'n'); // 2 ``` diff --git a/test/averageBy/averageBy.test.js b/test/averageBy/averageBy.test.js index 60675dfb7..f1f83b740 100644 --- a/test/averageBy/averageBy.test.js +++ b/test/averageBy/averageBy.test.js @@ -5,9 +5,11 @@ 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(); -}); \ No newline at end of file +}); diff --git a/test/maxBy/maxBy.test.js b/test/maxBy/maxBy.test.js index 765bb73ec..1fff2c517 100644 --- a/test/maxBy/maxBy.test.js +++ b/test/maxBy/maxBy.test.js @@ -5,9 +5,11 @@ test('Testing maxBy', (t) => { //For more information on all the methods supported by tape //Please go to https://github.com/substack/tape t.true(typeof maxBy === 'function', 'maxBy is a Function'); + t.equals(maxBy([{ n: 4 }, { n: 2 }, { n: 8 }, { n: 6 }], o => o.n), 8, 'Produces the right result with a function'); + t.equals(maxBy([{ n: 4 }, { n: 2 }, { n: 8 }, { n: 6 }], 'n'), 8, 'Produces the right result with a property name'); //t.deepEqual(maxBy(args..), 'Expected'); //t.equal(maxBy(args..), 'Expected'); //t.false(maxBy(args..), 'Expected'); //t.throws(maxBy(args..), 'Expected'); t.end(); -}); \ No newline at end of file +}); diff --git a/test/minBy/minBy.test.js b/test/minBy/minBy.test.js index 130b2de7e..975fc6232 100644 --- a/test/minBy/minBy.test.js +++ b/test/minBy/minBy.test.js @@ -5,9 +5,11 @@ test('Testing minBy', (t) => { //For more information on all the methods supported by tape //Please go to https://github.com/substack/tape t.true(typeof minBy === 'function', 'minBy is a Function'); + t.equals(minBy([{ n: 4 }, { n: 2 }, { n: 8 }, { n: 6 }], o => o.n), 2, 'Produces the right result with a function'); + t.equals(minBy([{ n: 4 }, { n: 2 }, { n: 8 }, { n: 6 }], 'n'), 2, 'Produces the right result with a property name'); //t.deepEqual(minBy(args..), 'Expected'); //t.equal(minBy(args..), 'Expected'); //t.false(minBy(args..), 'Expected'); //t.throws(minBy(args..), 'Expected'); t.end(); -}); \ No newline at end of file +}); diff --git a/test/testlog b/test/testlog index ee7e14e18..3b1c8f3f5 100644 --- a/test/testlog +++ b/test/testlog @@ -1,4 +1,4 @@ -Test log for: Wed Jan 24 2018 17:33:18 GMT+0200 (GTB Standard Time) +Test log for: Wed Jan 24 2018 17:37:28 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 @@ -41,6 +41,8 @@ Test log for: Wed Jan 24 2018 17:33:18 GMT+0200 (GTB Standard Time) Testing averageBy √ averageBy is a Function + √ Produces the right result with a function + √ Produces the right result with a property name Testing binarySearch @@ -837,6 +839,8 @@ Test log for: Wed Jan 24 2018 17:33:18 GMT+0200 (GTB Standard Time) Testing maxBy √ maxBy is a Function + √ Produces the right result with a function + √ Produces the right result with a property name Testing maxN @@ -861,6 +865,8 @@ Test log for: Wed Jan 24 2018 17:33:18 GMT+0200 (GTB Standard Time) Testing minBy √ minBy is a Function + √ Produces the right result with a function + √ Produces the right result with a property name Testing minN @@ -1457,8 +1463,8 @@ Test log for: Wed Jan 24 2018 17:33:18 GMT+0200 (GTB Standard Time) √ zipWith is a Function - total: 621 - passing: 621 - duration: 417ms + total: 627 + passing: 627 + duration: 419ms diff --git a/test/xProd/xProd.js b/test/xProd/xProd.js index 37b3556a6..2b7a126c3 100644 --- a/test/xProd/xProd.js +++ b/test/xProd/xProd.js @@ -1,2 +1,2 @@ -const xProd = (a, b) => a.reduce((acc,x) => acc.concat(b.map(y => [x, y])),[]); +const xProd = (a, b) => a.reduce((acc, x) => acc.concat(b.map(y => [x, y])), []); module.exports = xProd \ No newline at end of file