|
| 1 | +import { scale, sample } from './helpers'; |
| 2 | + |
| 3 | +describe('scale function', () => { |
| 4 | + it('should scale the array values between 0 and 1', () => { |
| 5 | + const inputArray = [1, 2, 3, 4, 5]; |
| 6 | + const scaledArray = scale(inputArray); |
| 7 | + |
| 8 | + expect(scaledArray).toEqual([0, 0.25, 0.5, 0.75, 1]); |
| 9 | + }); |
| 10 | + |
| 11 | + it('should handle an empty array', () => { |
| 12 | + const inputArray: number[] = []; |
| 13 | + const scaledArray = scale(inputArray); |
| 14 | + |
| 15 | + expect(scaledArray).toEqual([]); |
| 16 | + }); |
| 17 | + |
| 18 | + it('should handle an array with one element', () => { |
| 19 | + const inputArray = [42]; |
| 20 | + const scaledArray = scale(inputArray); |
| 21 | + |
| 22 | + expect(scaledArray).toEqual([0]); |
| 23 | + }); |
| 24 | +}); |
| 25 | + |
| 26 | +describe('sample function', () => { |
| 27 | + it('should sample the array to the specified size', () => { |
| 28 | + const inputArray = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; |
| 29 | + const newSize = 5; |
| 30 | + const sampledArray = sample(inputArray, newSize); |
| 31 | + |
| 32 | + expect(sampledArray.length).toBe(newSize); |
| 33 | + expect(sampledArray).toEqual([1, 3, 5, 7, 9]); |
| 34 | + }); |
| 35 | + |
| 36 | + it('should handle an empty array', () => { |
| 37 | + const inputArray: number[] = []; |
| 38 | + const newSize = 0; |
| 39 | + const sampledArray = sample(inputArray, newSize); |
| 40 | + |
| 41 | + expect(sampledArray).toEqual([]); |
| 42 | + }); |
| 43 | + |
| 44 | + it('should handle an array with one element', () => { |
| 45 | + const inputArray = [42]; |
| 46 | + const newSize = 5; |
| 47 | + const sampledArray = sample(inputArray, newSize); |
| 48 | + |
| 49 | + expect(sampledArray).toEqual([42, 42, 42, 42, 42]); // The result will be an array with the same element repeated |
| 50 | + }); |
| 51 | + |
| 52 | + it('should handle newSize greater than the original size', () => { |
| 53 | + const inputArray = [1, 2, 3]; |
| 54 | + const newSize = 5; |
| 55 | + const sampledArray = sample(inputArray, newSize); |
| 56 | + |
| 57 | + expect(sampledArray).toEqual([1, 1, 2, 2, 3]); // The result will include elements from the original array with repetition |
| 58 | + }); |
| 59 | +}); |
0 commit comments