Skip to content

Commit a82c868

Browse files
committed
added basic-prefix-sum code
1 parent 08d8c6b commit a82c868

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { describe, it, expect } from "vitest";
2+
import { basicPrefixSum } from "../BasicPrefixSum.js";
3+
4+
describe("basicPrefixSum", () => {
5+
it("computes prefix sums correctly", () => {
6+
expect(basicPrefixSum([1, 2, 3, 4])).toEqual([1, 3, 6, 10]);
7+
});
8+
9+
it("returns an empty array for empty input", () => {
10+
expect(basicPrefixSum([])).toEqual([]);
11+
});
12+
13+
it("throws an error if input is not an array", () => {
14+
expect(() => basicPrefixSum("abc")).toThrow(TypeError);
15+
});
16+
17+
it("throws an error if array contains non-numeric elements", () => {
18+
expect(() => basicPrefixSum([1, "2", 3])).toThrow(TypeError);
19+
});
20+
});

0 commit comments

Comments
 (0)