* chore: make aware eslint that we use jest By setting up the jest environment, we no longer need to declare the 'test' global in the configuration. * chore: don't need to import expect, it's a jest environment global * chore: don't need to import expect when creating undefined test
22 lines
735 B
JavaScript
22 lines
735 B
JavaScript
const {sampleSize} = require('./_30s.js');
|
|
|
|
test('sampleSize is a Function', () => {
|
|
expect(sampleSize).toBeInstanceOf(Function);
|
|
});
|
|
const arr = [3, 7, 9, 11];
|
|
test('Returns a single element without n specified', () => {
|
|
expect(sampleSize(arr).length).toBe(1);
|
|
});
|
|
test('Returns a random sample of specified size from an array', () => {
|
|
expect(sampleSize(arr, 2).every(x => arr.includes(x))).toBeTruthy();
|
|
});
|
|
test('Returns all elements in an array if n >= length', () => {
|
|
expect(sampleSize(arr, 5).length).toBe(4);
|
|
});
|
|
test('Returns an empty array if original array is empty', () => {
|
|
expect(sampleSize([], 2)).toEqual([]);
|
|
});
|
|
test('Returns an empty array if n = 0', () => {
|
|
expect(sampleSize(arr, 0)).toEqual([]);
|
|
});
|