-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstringCalculator.test.ts
More file actions
48 lines (35 loc) · 1.29 KB
/
stringCalculator.test.ts
File metadata and controls
48 lines (35 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import { add } from "./stringCalculator";
import { NegativeNumberError } from "./util";
test("Testcase 1: support single number", () => {
expect(add("1")).toBe(1);
});
test("Testcase 2: supports two comma(,) separated numbers", () => {
expect(add("1,34")).toBe(35);
});
test("Testcase 3: supports empty string", () => {
expect(add("")).toBe(0);
});
test("Testcase 4: supports newline character(\n) as delimiter", () => {
expect(add("23\n34")).toBe(57);
});
test("Testcase 5: supports newline character(\n) and comma(,) as delimiter", () => {
expect(add("2,3\n3,4")).toBe(12);
});
test("Testcase 6: supports newline character delimiter and no numbers", () => {
expect(add("\n")).toBe(0);
});
test("Testcase 7: supports throw exception/error when negative number", () => {
expect(() => add("-1,3")).toThrow(NegativeNumberError);
});
test("Testcase 8: supports throws error for negative numbers", () => {
expect(() => add("1,-2,3,-4")).toThrow("negative numbers not allowed -2,-4");
});
test("Testcase 9: supports semicolon (;) as delimiter", () => {
expect(add("//;\n1;2;3")).toBe(6);
});
test("Testcase 10: supports hyphen (-) as delimiter", () => {
expect(add("//-\n1-2-3")).toBe(6);
});
test("Testcase 11: supports pipe (|) as delimiter", () => {
expect(add("//|\n1|2|3|4")).toBe(10);
});