-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Expand file tree
/
Copy pathBasicPrefixSum.test.js
More file actions
21 lines (18 loc) · 812 Bytes
/
BasicPrefixSum.test.js
File metadata and controls
21 lines (18 loc) · 812 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import { prefixSum } from '../BasicPrefixSum.js'
import { describe, it, expect } from 'vitest'
describe('prefixSum', () => {
it(`Should return computed prefix sum array for a passed input array`, () => {
expect(prefixSum([3, 6, 9, 15])).toEqual([3, 9, 18, 33])
expect(prefixSum([0, 5, -2, 4])).toEqual([0, 5, 3, 7])
})
it(`Should return empty array when passed input array is empty`, () => {
expect(prefixSum([])).toEqual([])
})
it(`should throw TypeError if input is not an array of numbers`, () => {
expect(() => prefixSum('array')).toThrow(TypeError)
expect(() => prefixSum(1)).toThrow(TypeError)
expect(() => prefixSum([1, '2'])).toThrow(TypeError)
expect(() => prefixSum([1, true])).toThrow(TypeError)
expect(() => prefixSum([{}, 2])).toThrow(TypeError)
})
})