-
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
package com.thealgorithms.searches;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;
class SquareRootBinarySearchTest {
@Test
void testPerfectSquare() {
long input = 16;
long expected = 4;
assertEquals(expected, SquareRootBinarySearch.squareRoot(input), "Square root of 16 should be 4");
}
@Test
void testNonPerfectSquare() {
long input = 15;
long expected = 3;
assertEquals(expected, SquareRootBinarySearch.squareRoot(input), "Square root of 15 should be 3");
}
@Test
void testZero() {
long input = 0;
long expected = 0;
assertEquals(expected, SquareRootBinarySearch.squareRoot(input), "Square root of 0 should be 0");
}
@Test
void testOne() {
long input = 1;
long expected = 1;
assertEquals(expected, SquareRootBinarySearch.squareRoot(input), "Square root of 1 should be 1");
}
@Test
void testLargeNumberPerfectSquare() {
long input = 1000000;
long expected = 1000;
assertEquals(expected, SquareRootBinarySearch.squareRoot(input), "Square root of 1000000 should be 1000");
}
@Test
void testLargeNumberNonPerfectSquare() {
long input = 999999;
long expected = 999;
assertEquals(expected, SquareRootBinarySearch.squareRoot(input), "Square root of 999999 should be 999");
}
@Test
void testNegativeInput() {
long input = -4;
long expected = 0; // Assuming the implementation should return 0 for negative input
assertEquals(expected, SquareRootBinarySearch.squareRoot(input), "Square root of negative number should return 0");
}
}