Add tests for sample, sampleSize
This commit is contained in:
@ -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();
|
||||
});
|
||||
});
|
||||
|
||||
@ -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();
|
||||
});
|
||||
});
|
||||
|
||||
@ -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');
|
||||
|
||||
18
test/testlog
18
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
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user