-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Expand file tree
/
Copy pathBasicPrefixSum.test.js
More file actions
22 lines (19 loc) · 885 Bytes
/
BasicPrefixSum.test.js
File metadata and controls
22 lines (19 loc) · 885 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import basicPrefixSum from '../BasicPrefixSum'
describe('basicPrefixSum', () => {
it('computes correct prefix sums for normal arrays', () => {
expect(basicPrefixSum([1, 2, 3, 4])).toEqual([1, 3, 6, 10])
expect(basicPrefixSum([0, 0, 0])).toEqual([0, 0, 0])
expect(basicPrefixSum([-1, 5, -3])).toEqual([-1, 4, 1])
expect(basicPrefixSum([100])).toEqual([100]) // single element array
})
it('returns an empty array for empty input', () => {
expect(basicPrefixSum([])).toEqual([])
})
it('throws TypeError for invalid inputs', () => {
expect(() => basicPrefixSum('not an array')).toThrow(TypeError)
expect(() => basicPrefixSum([1, 2, 'x'])).toThrow(TypeError)
expect(() => basicPrefixSum([{}, 3])).toThrow(TypeError)
expect(() => basicPrefixSum(null)).toThrow(TypeError)
expect(() => basicPrefixSum(undefined)).toThrow(TypeError)
})
})