|
| 1 | +const runningSum = require('.'); |
| 2 | + |
| 3 | +describe('Running Sum of 1d Array', () => { |
| 4 | + it('should return an empty array if given an empty array', () => { |
| 5 | + const result = runningSum([]); |
| 6 | + expect(result).toEqual([]); |
| 7 | + }); |
| 8 | + |
| 9 | + it('should return an array with the same length as the input array', () => { |
| 10 | + const input = [1, 2, 3, 4, 5]; |
| 11 | + const result = runningSum(input); |
| 12 | + expect(result.length).toEqual(input.length); |
| 13 | + }); |
| 14 | + |
| 15 | + it('should correctly calculate the running sum of the input array', () => { |
| 16 | + const input = [1, 2, 3, 4, 5]; |
| 17 | + const result = runningSum(input); |
| 18 | + expect(result).toEqual([1, 3, 6, 10, 15]); |
| 19 | + }); |
| 20 | + |
| 21 | + it('should work with arrays containing negative numbers', () => { |
| 22 | + const input = [-1, 2, -3, 4, -5]; |
| 23 | + const result = runningSum(input); |
| 24 | + expect(result).toEqual([-1, 1, -2, 2, -3]); |
| 25 | + }); |
| 26 | +}); |
0 commit comments