2020-06-26 09:31:23 +00:00
|
|
|
import { sampleSize } from '.';
|
|
|
|
|
2021-08-18 05:46:56 +00:00
|
|
|
describe('util/index', () => {
|
2020-06-26 09:31:23 +00:00
|
|
|
describe('sampleSize', () => {
|
|
|
|
const array = ['a', 'b', 'c', 'd'];
|
2022-04-12 14:49:49 +00:00
|
|
|
|
2020-06-26 09:31:23 +00:00
|
|
|
it('returns correct sized array', () => {
|
|
|
|
expect(sampleSize(array, 2)).toHaveLength(2);
|
|
|
|
});
|
2022-04-12 14:49:49 +00:00
|
|
|
|
2020-06-26 09:31:23 +00:00
|
|
|
it('returns full array for undefined number', () => {
|
2022-02-11 10:02:30 +00:00
|
|
|
expect(sampleSize(array, undefined as never)).toEqual(array);
|
2020-06-26 09:31:23 +00:00
|
|
|
});
|
2022-04-12 14:49:49 +00:00
|
|
|
|
2020-06-26 09:31:23 +00:00
|
|
|
it('returns full array for null number', () => {
|
2022-06-19 21:17:46 +00:00
|
|
|
expect(sampleSize(array, null as never)).toBeEmptyArray();
|
2020-06-26 09:31:23 +00:00
|
|
|
});
|
2022-04-12 14:49:49 +00:00
|
|
|
|
2020-06-26 09:31:23 +00:00
|
|
|
it('returns full array for 0 number', () => {
|
2021-10-27 05:24:36 +00:00
|
|
|
expect(sampleSize(array, 0)).toBeEmptyArray();
|
2020-06-26 09:31:23 +00:00
|
|
|
});
|
2022-04-12 14:49:49 +00:00
|
|
|
|
2020-06-26 09:31:23 +00:00
|
|
|
it('returns empty array for null array', () => {
|
2022-06-19 21:17:46 +00:00
|
|
|
expect(sampleSize(null as never, 1)).toBeEmptyArray();
|
2020-06-26 09:31:23 +00:00
|
|
|
});
|
2022-04-12 14:49:49 +00:00
|
|
|
|
2020-06-26 09:31:23 +00:00
|
|
|
it('returns empty array for undefined array', () => {
|
2022-06-19 21:17:46 +00:00
|
|
|
expect(sampleSize(undefined as never, 1)).toBeEmptyArray();
|
2020-06-26 09:31:23 +00:00
|
|
|
});
|
2022-04-12 14:49:49 +00:00
|
|
|
|
2020-06-26 09:31:23 +00:00
|
|
|
it('returns empty array for empty array', () => {
|
2021-10-27 05:24:36 +00:00
|
|
|
expect(sampleSize([], 1)).toBeEmptyArray();
|
2020-06-26 09:31:23 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|