Skip to content

Commit 685f3f3

Browse files
committed
test: fixed test suites PR comments
1 parent 2ef946b commit 685f3f3

File tree

1 file changed

+21
-14
lines changed

1 file changed

+21
-14
lines changed

maths/test/square_root.test.ts

+21-14
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,28 @@
1-
import { SquareRoot } from "../square_root";
1+
import { squareRoot } from "../square_root";
22

3-
describe("SquareRoot", () => {
3+
describe("squareRoot", () => {
44
test.each([-1, -10, -2.4])(
55
"should throw an error for negative numbers",
6-
(n) => {
7-
expect(() => SquareRoot(n)).toThrow(
8-
"number must be non-negative number > 0"
9-
);
6+
(n: number) => {
7+
expect(() => squareRoot(n)).toThrow("number must be non-negative number");
108
}
119
);
1210

13-
test("should return correct square root value", () => {
14-
expect(SquareRoot(0)).toBe(0);
15-
expect(SquareRoot(1)).toBe(1);
16-
expect(SquareRoot(4)).toBe(2);
17-
expect(SquareRoot(9)).toBe(3);
18-
expect(SquareRoot(16)).toBe(4);
19-
expect(SquareRoot(25)).toBe(4);
20-
});
11+
test.each([0, 1, 4, 9, 16, 25])(
12+
"should return correct rational square root value",
13+
() => {
14+
(n: number) => {
15+
expect(() => squareRoot(n)).toBeCloseTo(Math.sqrt(n));
16+
};
17+
}
18+
);
19+
20+
test.each([2, 15, 20, 40, 99, 10032])(
21+
"should return correct irrational square root value",
22+
() => {
23+
(n: number) => {
24+
expect(() => squareRoot(n)).toBeCloseTo(Math.sqrt(n));
25+
};
26+
}
27+
);
2128
});

0 commit comments

Comments
 (0)