-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathabs.test.ts
More file actions
33 lines (26 loc) · 931 Bytes
/
abs.test.ts
File metadata and controls
33 lines (26 loc) · 931 Bytes
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
import abs from "../src/abs";
describe("abs function", () => {
test("should return absolute value of positive number", () => {
expect(abs("123.456")).toBe("123.456");
});
test("should return absolute value of negative number", () => {
expect(abs("-123.456")).toBe("123.456");
});
test("should handle positive sign", () => {
expect(abs("+123.456")).toBe("123.456");
});
test("should handle zero", () => {
expect(abs("0")).toBe("0");
expect(abs("-0")).toBe("0");
expect(abs("+0")).toBe("0");
});
test("should handle very large numbers", () => {
expect(abs("-999999999999999999999999.123456789")).toBe("999999999999999999999999.123456789");
});
test("should handle whitespace", () => {
expect(abs(" -123.456 ")).toBe("123.456");
});
test("should throw error for non-string input", () => {
expect(() => abs(123 as any)).toThrow("Input must be a string");
});
});