- Notifications
You must be signed in to change notification settings - Fork 19.9k
/
Copy pathRecursiveBinarySearchTest.java
41 lines (33 loc) · 1.41 KB
/
RecursiveBinarySearchTest.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
// Created by Pronay Debnath
// Date:- 1/10/2023
// Test file updated with JUnit tests
packagecom.thealgorithms.searches;
importstaticorg.junit.jupiter.api.Assertions.assertEquals;
importorg.junit.jupiter.api.Test; // Import the JUnit 5 Test annotation
publicclassRecursiveBinarySearchTest {
@Test
publicvoidtestBinarySearch() {
// Create an instance of GenericBinarySearch
RecursiveBinarySearch<Integer> searcher = newRecursiveBinarySearch<>();
// Test case 1: Element found in the array
Integer[] arr1 = {1, 2, 3, 4, 5};
inttarget1 = 3;
intresult1 = searcher.binsear(arr1, 0, arr1.length - 1, target1);
assertEquals(2, result1);
// Test case 2: Element not found in the array
Integer[] arr2 = {1, 2, 3, 4, 5};
inttarget2 = 6;
intresult2 = searcher.binsear(arr2, 0, arr2.length - 1, target2);
assertEquals(-1, result2);
// Test case 3: Element found at the beginning of the array
Integer[] arr3 = {10, 20, 30, 40, 50};
inttarget3 = 10;
intresult3 = searcher.binsear(arr3, 0, arr3.length - 1, target3);
assertEquals(0, result3);
// Test case 4: Element found at the end of the array
Integer[] arr4 = {10, 20, 30, 40, 50};
inttarget4 = 50;
intresult4 = searcher.binsear(arr4, 0, arr4.length - 1, target4);
assertEquals(4, result4);
}
}