-
-
Notifications
You must be signed in to change notification settings - Fork 156
Expand file tree
/
Copy pathBinarySearchTest.java
More file actions
39 lines (27 loc) · 859 Bytes
/
Copy pathBinarySearchTest.java
File metadata and controls
39 lines (27 loc) · 859 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 util;
import org.junit.jupiter.api.Test;
import java.util.Arrays;
import static org.junit.jupiter.api.Assertions.*;
/**
* Created by nikoo28 on 1/17/21 10:14 PM
*/
class BinarySearchTest {
@Test
void testLinearSearch1() {
int[] arr = {7, 3, 9, 5, 4, 8, 0, 1};
Arrays.sort(arr);
int numberToSearch = 9;
assertTrue(BinarySearch.binarySearch(arr, numberToSearch));
numberToSearch = 10;
assertFalse(BinarySearch.binarySearch(arr, numberToSearch));
}
@Test
void testSortedLinearSearch1() {
int[] arr = {7, 3, 9, 5, 4, 8, 0, 1, -1, -2, -6, -7, -3, -5, -99, -100, 9999, 34, 12, 5653, 1213, 6563};
Arrays.sort(arr);
int numberToSearch = 9;
assertTrue(BinarySearch.binarySearch(arr, numberToSearch));
numberToSearch = 10;
assertFalse(BinarySearch.binarySearch(arr, numberToSearch));
}
}