|
| 1 | +import { standardDeviation } from '../StandardDeviation.js' |
| 2 | + |
| 3 | +test('Calculate STD of 3,5,6,10,23,12,19', () => { |
| 4 | + expect(standardDeviation([3, 5, 6, 10, 23, 12, 19])).toBeCloseTo( |
| 5 | + 6.9164105353773 |
| 6 | + ) |
| 7 | +}) |
| 8 | + |
| 9 | +test('Calculate STD of -2,-5,1,12,23,-81,-23', () => { |
| 10 | + expect(standardDeviation([-2, -5, 1, 12, 23, -81, -23])).toBeCloseTo( |
| 11 | + 31.598889156399 |
| 12 | + ) |
| 13 | +}) |
| 14 | + |
| 15 | +test('Calculate STD of 0,0,0', () => { |
| 16 | + expect(standardDeviation([0, 0, 0])).toBeCloseTo(0) |
| 17 | +}) |
| 18 | + |
| 19 | +test('Calculate STD of -7,7', () => { |
| 20 | + expect(standardDeviation([-7, 7])).toBeCloseTo(7) |
| 21 | +}) |
| 22 | + |
| 23 | +test('Throw error - array has less than two items', () => { |
| 24 | + expect(() => standardDeviation([])).toThrow() |
| 25 | + expect(() => standardDeviation([7])).toThrow() |
| 26 | +}) |
| 27 | + |
| 28 | +test('Throw type error - not an array', () => { |
| 29 | + expect(() => standardDeviation(2)).toThrow() |
| 30 | + expect(() => standardDeviation('not an array')).toThrow() |
| 31 | +}) |
| 32 | + |
| 33 | +test('Throw type error - not a number inside array', () => { |
| 34 | + expect(() => standardDeviation([5, 'not a number', 2])).toThrow() |
| 35 | + expect(() => standardDeviation([1, [2], 3])).toThrow() |
| 36 | +}) |
0 commit comments