forked from TheAlgorithms/Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSentinelBinarySearchTest.java
More file actions
39 lines (31 loc) · 885 Bytes
/
Copy pathSentinelBinarySearchTest.java
File metadata and controls
39 lines (31 loc) · 885 Bytes
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
package com.thealgorithms.searches;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;
class SentinelBinarySearchTest {
private final SentinelBinarySearch search = new SentinelBinarySearch();
@Test
void testElementFound() {
int[] arr = {1, 3, 5, 7, 9};
assertEquals(2, search.find(arr, 5));
}
@Test
void testElementNotFound() {
int[] arr = {1, 3, 5, 7, 9};
assertEquals(-1, search.find(arr, 4));
}
@Test
void testFirstElement() {
int[] arr = {1, 3, 5, 7, 9};
assertEquals(0, search.find(arr, 1));
}
@Test
void testLastElement() {
int[] arr = {1, 3, 5, 7, 9};
assertEquals(4, search.find(arr, 9));
}
@Test
void testEmptyArray() {
int[] arr = {};
assertEquals(-1, search.find(arr, 5));
}
}