diff --git a/test/sample/sample.test.js b/test/sample/sample.test.js index 47f575acb..258d58e6f 100644 --- a/test/sample/sample.test.js +++ b/test/sample/sample.test.js @@ -5,9 +5,13 @@ test('Testing sample', (t) => { //For more information on all the methods supported by tape //Please go to https://github.com/substack/tape t.true(typeof sample === 'function', 'sample is a Function'); + const arr = [3,7,9,11]; + t.true(arr.includes(sample(arr)), 'Returns a random element from the array'); + t.equal(sample([1]), 1, 'Works for single-element arrays'); + t.equal(sample([]), undefined, 'Returns undefined for empty array'); //t.deepEqual(sample(args..), 'Expected'); //t.equal(sample(args..), 'Expected'); //t.false(sample(args..), 'Expected'); //t.throws(sample(args..), 'Expected'); t.end(); -}); \ No newline at end of file +}); diff --git a/test/sampleSize/sampleSize.test.js b/test/sampleSize/sampleSize.test.js index 1ac15836e..6c610fa2d 100644 --- a/test/sampleSize/sampleSize.test.js +++ b/test/sampleSize/sampleSize.test.js @@ -5,9 +5,15 @@ test('Testing sampleSize', (t) => { //For more information on all the methods supported by tape //Please go to https://github.com/substack/tape t.true(typeof sampleSize === 'function', 'sampleSize is a Function'); + const arr = [3,7,9,11]; + t.equal(sampleSize(arr).length, 1, 'Returns a single element without n specified'); + t.true(sampleSize(arr, 2).every(x => arr.includes(x)), 'Returns a random sample of specified size from an array'); + t.equal(sampleSize(arr, 5).length, 4, 'Returns all elements in an array if n >= length'); + t.deepEqual(sampleSize([], 2), [], 'Returns an empty array if original array is empty'); + t.deepEqual(sampleSize(arr, 0), [], 'Returns an empty array if n = 0'); //t.deepEqual(sampleSize(args..), 'Expected'); //t.equal(sampleSize(args..), 'Expected'); //t.false(sampleSize(args..), 'Expected'); //t.throws(sampleSize(args..), 'Expected'); t.end(); -}); \ No newline at end of file +}); diff --git a/test/shuffle/shuffle.test.js b/test/shuffle/shuffle.test.js index 31773a746..aed55ad03 100644 --- a/test/shuffle/shuffle.test.js +++ b/test/shuffle/shuffle.test.js @@ -6,7 +6,10 @@ test('Testing shuffle', (t) => { //Please go to https://github.com/substack/tape t.true(typeof shuffle === 'function', 'shuffle is a Function'); const arr = [1,2,3,4,5,6]; - //t.notDeepEqual(shuffle(arr), arr, 'Shuffles the array'); Does not work always (got a test failing once) + t.notEqual(shuffle(arr), arr, 'Shuffles the array'); + t.true(shuffle(arr).every(x => arr.includes(x)), 'New array contains all original elements'); + t.deepEqual(shuffle([]),[],'Works for empty arrays'); + t.deepEqual(shuffle([1]),[1],'Works for single-element arrays'); //t.deepEqual(shuffle(args..), 'Expected'); //t.equal(shuffle(args..), 'Expected'); //t.false(shuffle(args..), 'Expected'); diff --git a/test/testlog b/test/testlog index ad8982482..ede50b9f8 100644 --- a/test/testlog +++ b/test/testlog @@ -1,4 +1,4 @@ -Test log for: Thu Feb 08 2018 16:12:32 GMT+0200 (GTB Standard Time) +Test log for: Fri Feb 09 2018 13:05:56 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 @@ -1296,10 +1296,18 @@ Test log for: Thu Feb 08 2018 16:12:32 GMT+0200 (GTB Standard Time) Testing sample √ sample is a Function + √ Returns a random element from the array + √ Works for single-element arrays + √ Returns undefined for empty array Testing sampleSize √ sampleSize is a Function + √ Returns a single element without n specified + √ Returns a random sample of specified size from an array + √ Returns all elements in an array if n >= length + √ Returns an empty array if original array is empty + √ Returns an empty array if n = 0 Testing scrollToTop @@ -1332,6 +1340,10 @@ Test log for: Thu Feb 08 2018 16:12:32 GMT+0200 (GTB Standard Time) Testing shuffle √ shuffle is a Function + √ Shuffles the array + √ New array contains all original elements + √ Works for empty arrays + √ Works for single-element arrays Testing similarity @@ -1758,8 +1770,8 @@ Test log for: Thu Feb 08 2018 16:12:32 GMT+0200 (GTB Standard Time) √ Works with multiple promises - total: 856 - passing: 856 + total: 868 + passing: 868 duration: 2.4s