Test cleanup and fixes [s-t]

This commit is contained in:
Angelos Chalaris
2018-06-18 18:37:35 +03:00
parent ba3e684a27
commit 9cf2c4680c
53 changed files with 286 additions and 409 deletions

View File

@ -1,25 +1,22 @@
const expect = require('expect');
const sampleSize = require('./sampleSize.js');
test('sampleSize is a Function', () => {
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, 1).toBe()
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', () => {
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, 4).toBe()
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 original array is empty', () => {
expect(sampleSize([], 2)).toEqual([]);
});
test('Returns an empty array if n = 0', () => {
expect(sampleSize(arr, 0), []).toEqual()
test('Returns an empty array if n = 0', () => {
expect(sampleSize(arr, 0)).toEqual([]);
});