|
1 |
| -import { SquareRoot } from "../square_root"; |
| 1 | +import { squareRoot } from "../square_root"; |
2 | 2 |
|
3 |
| -describe("SquareRoot", () => { |
| 3 | +describe("squareRoot", () => { |
4 | 4 | test.each([-1, -10, -2.4])(
|
5 | 5 | "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"); |
10 | 8 | }
|
11 | 9 | );
|
12 | 10 |
|
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 | + ); |
21 | 28 | });
|
0 commit comments