Add tests for sample, sampleSize

This commit is contained in:
Angelos Chalaris
2018-02-09 13:06:15 +02:00
parent 35dd2aba19
commit a6701e44f9
4 changed files with 31 additions and 6 deletions

View File

@ -5,9 +5,13 @@ test('Testing sample', (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 sample === 'function', 'sample is a Function'); 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.deepEqual(sample(args..), 'Expected');
//t.equal(sample(args..), 'Expected'); //t.equal(sample(args..), 'Expected');
//t.false(sample(args..), 'Expected'); //t.false(sample(args..), 'Expected');
//t.throws(sample(args..), 'Expected'); //t.throws(sample(args..), 'Expected');
t.end(); t.end();
}); });

View File

@ -5,9 +5,15 @@ test('Testing sampleSize', (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 sampleSize === 'function', 'sampleSize is a Function'); 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.deepEqual(sampleSize(args..), 'Expected');
//t.equal(sampleSize(args..), 'Expected'); //t.equal(sampleSize(args..), 'Expected');
//t.false(sampleSize(args..), 'Expected'); //t.false(sampleSize(args..), 'Expected');
//t.throws(sampleSize(args..), 'Expected'); //t.throws(sampleSize(args..), 'Expected');
t.end(); t.end();
}); });

View File

@ -6,7 +6,10 @@ test('Testing shuffle', (t) => {
//Please go to https://github.com/substack/tape //Please go to https://github.com/substack/tape
t.true(typeof shuffle === 'function', 'shuffle is a Function'); t.true(typeof shuffle === 'function', 'shuffle is a Function');
const arr = [1,2,3,4,5,6]; 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.deepEqual(shuffle(args..), 'Expected');
//t.equal(shuffle(args..), 'Expected'); //t.equal(shuffle(args..), 'Expected');
//t.false(shuffle(args..), 'Expected'); //t.false(shuffle(args..), 'Expected');

View File

@ -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 > 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
@ -1296,10 +1296,18 @@ Test log for: Thu Feb 08 2018 16:12:32 GMT+0200 (GTB Standard Time)
Testing sample Testing sample
√ sample is a Function √ sample is a Function
√ Returns a random element from the array
√ Works for single-element arrays
√ Returns undefined for empty array
Testing sampleSize Testing sampleSize
√ sampleSize is a Function √ 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 Testing scrollToTop
@ -1332,6 +1340,10 @@ Test log for: Thu Feb 08 2018 16:12:32 GMT+0200 (GTB Standard Time)
Testing shuffle Testing shuffle
√ shuffle is a Function √ shuffle is a Function
√ Shuffles the array
√ New array contains all original elements
√ Works for empty arrays
√ Works for single-element arrays
Testing similarity 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 √ Works with multiple promises
total: 856 total: 868
passing: 856 passing: 868
duration: 2.4s duration: 2.4s