-
Notifications
You must be signed in to change notification settings - Fork 19.9k
/
Copy pathIterativeTernarySearchTest.java
26 lines (20 loc) · 1.16 KB
/
IterativeTernarySearchTest.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
package com.search;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
public class IterativeTernarySearchTest {
@Test
void testIterativeTernarySearch() {
Integer[] arr1 = {1, 2, 3, 5, 8, 13, 21, 34, 55};
Assertions.assertEquals(2, IterativeTernarySearch.find(arr1, 3), "Incorrect index");
Assertions.assertEquals(0, IterativeTernarySearch.find(arr1, 1), "Incorrect index");
Assertions.assertEquals(8, IterativeTernarySearch.find(arr1, 55), "Incorrect index");
Assertions.assertEquals(-1, IterativeTernarySearch.find(arr1, -2), "Incorrect index");
Assertions.assertEquals(-1, IterativeTernarySearch.find(arr1, 4), "Incorrect index");
String[] arr2 = {"A", "B", "C", "D"};
Assertions.assertEquals(2, IterativeTernarySearch.find(arr2, "C"), "Incorrect index");
Assertions.assertEquals(1, IterativeTernarySearch.find(arr2, "B"), "Incorrect index");
Assertions.assertEquals(-1, IterativeTernarySearch.find(arr2, "F"), "Incorrect index");
String[] arr3 = {};
Assertions.assertEquals(-1, IterativeTernarySearch.find(arr3, ""), "Incorrect index");
}
}