- Notifications
You must be signed in to change notification settings - Fork 19.9k
/
Copy pathSquareRootBinarySearchTest.java
57 lines (47 loc) · 1.7 KB
/
SquareRootBinarySearchTest.java
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
48
49
50
51
52
53
54
55
56
57
packagecom.thealgorithms.searches;
importstaticorg.junit.jupiter.api.Assertions.assertEquals;
importorg.junit.jupiter.api.Test;
classSquareRootBinarySearchTest {
@Test
voidtestPerfectSquare() {
longinput = 16;
longexpected = 4;
assertEquals(expected, SquareRootBinarySearch.squareRoot(input), "Square root of 16 should be 4");
}
@Test
voidtestNonPerfectSquare() {
longinput = 15;
longexpected = 3;
assertEquals(expected, SquareRootBinarySearch.squareRoot(input), "Square root of 15 should be 3");
}
@Test
voidtestZero() {
longinput = 0;
longexpected = 0;
assertEquals(expected, SquareRootBinarySearch.squareRoot(input), "Square root of 0 should be 0");
}
@Test
voidtestOne() {
longinput = 1;
longexpected = 1;
assertEquals(expected, SquareRootBinarySearch.squareRoot(input), "Square root of 1 should be 1");
}
@Test
voidtestLargeNumberPerfectSquare() {
longinput = 1000000;
longexpected = 1000;
assertEquals(expected, SquareRootBinarySearch.squareRoot(input), "Square root of 1000000 should be 1000");
}
@Test
voidtestLargeNumberNonPerfectSquare() {
longinput = 999999;
longexpected = 999;
assertEquals(expected, SquareRootBinarySearch.squareRoot(input), "Square root of 999999 should be 999");
}
@Test
voidtestNegativeInput() {
longinput = -4;
longexpected = 0; // Assuming the implementation should return 0 for negative input
assertEquals(expected, SquareRootBinarySearch.squareRoot(input), "Square root of negative number should return 0");
}
}