Test migration to jest by hand
Apparently using regular expressions is way easier.
This commit is contained in:
9
test/sampleSize/sampleSize.js
Normal file
9
test/sampleSize/sampleSize.js
Normal file
@ -0,0 +1,9 @@
|
||||
const sampleSize = ([...arr], n = 1) => {
|
||||
let m = arr.length;
|
||||
while (m) {
|
||||
const i = Math.floor(Math.random() * m--);
|
||||
[arr[m], arr[i]] = [arr[i], arr[m]];
|
||||
}
|
||||
return arr.slice(0, n);
|
||||
};
|
||||
module.exports = sampleSize;
|
||||
17
test/sampleSize/sampleSize.test.js
Normal file
17
test/sampleSize/sampleSize.test.js
Normal file
@ -0,0 +1,17 @@
|
||||
const expect = require('expect');
|
||||
const sampleSize = require('./sampleSize.js');
|
||||
|
||||
|
||||
test('sampleSize is a Function', () => {
|
||||
expect(sampleSize).toBeInstanceOf(Function);
|
||||
});
|
||||
const arr = [3,7,9,11];
|
||||
t.equal(sampleSize(arr).length, 1, 'Returns a single element without n specified');
|
||||
test('Returns a random sample of specified size from an array', () => {
|
||||
expect(sampleSize(arr, 2).every(x => arr.includes(x))).toBeTruthy();
|
||||
});
|
||||
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');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user