|
1 | | -import { sqrt } from '../SquareRoot' |
| 1 | +import { squareRoot } from '../SquareRoot.js' |
2 | 2 |
|
3 | | -test('Check SquareRoot of 4 is 2', () => { |
4 | | - const res = sqrt(4, 10) |
5 | | - expect(res).toBeCloseTo(2) |
6 | | -}) |
| 3 | +describe('squareRoot', () => { |
| 4 | + test('squareRoot(0) returns 0', () => { |
| 5 | + expect(squareRoot(0)).toBe(0) |
| 6 | + }) |
7 | 7 |
|
8 | | -test('Check SquareRoot of 2 is 1.4142135', () => { |
9 | | - const res = sqrt(2, 10) |
10 | | - expect(res).toBeCloseTo(1.4142135) |
11 | | -}) |
| 8 | + test('squareRoot(1) returns 1', () => { |
| 9 | + expect(squareRoot(1)).toBe(1) |
| 10 | + }) |
12 | 11 |
|
13 | | -test('Check SquareRoot of 3.2 is 1.788854381999832', () => { |
14 | | - const res = sqrt(3.2, 10) |
15 | | - expect(res).toBeCloseTo(1.788854381999832) |
16 | | -}) |
| 12 | + test('squareRoot(4) returns 2', () => { |
| 13 | + expect(squareRoot(4)).toBe(2) |
| 14 | + }) |
17 | 15 |
|
18 | | -test('Check SquareRoot of 1 is 1', () => { |
19 | | - const res = sqrt(1, 10) |
20 | | - expect(res).toBe(1) |
21 | | -}) |
| 16 | + test('squareRoot(9) returns 3', () => { |
| 17 | + expect(squareRoot(9)).toBe(3) |
| 18 | + }) |
22 | 19 |
|
23 | | -test('Check SquareRoot of 144 is 12', () => { |
24 | | - const res = sqrt(144, 10) |
25 | | - expect(res).toBeCloseTo(12) |
26 | | -}) |
| 20 | + test('squareRoot(16) returns 4', () => { |
| 21 | + expect(squareRoot(16)).toBe(4) |
| 22 | + }) |
27 | 23 |
|
28 | | -test('Check SquareRoot of 0 is 0', () => { |
29 | | - const res = sqrt(0, 10) |
30 | | - expect(res).toBeCloseTo(0) |
31 | | -}) |
| 24 | + test('squareRoot(100) returns 10', () => { |
| 25 | + expect(squareRoot(100)).toBe(10) |
| 26 | + }) |
| 27 | + |
| 28 | + test('squareRoot(2) returns approximately 1.4142135624', () => { |
| 29 | + expect(squareRoot(2)).toBeCloseTo(1.4142135624, 5) |
| 30 | + }) |
| 31 | + |
| 32 | + test('squareRoot(0.25) returns 0.5', () => { |
| 33 | + expect(squareRoot(0.25)).toBeCloseTo(0.5, 5) |
| 34 | + }) |
| 35 | + |
| 36 | + test('throws TypeError for negative input', () => { |
| 37 | + expect(() => squareRoot(-1)).toThrow(TypeError) |
| 38 | + }) |
| 39 | + |
| 40 | + test('throws TypeError for non-number input', () => { |
| 41 | + expect(() => squareRoot('4')).toThrow(TypeError) |
| 42 | + }) |
32 | 43 |
|
33 | | -test('Check SquareRoot of 1000 is 31.62277', () => { |
34 | | - const res = sqrt(1000, 10) |
35 | | - expect(res).toBeCloseTo(31.62277) |
| 44 | + test('throws TypeError for NaN', () => { |
| 45 | + expect(() => squareRoot(NaN)).toThrow(TypeError) |
| 46 | + }) |
36 | 47 | }) |
0 commit comments