|
| 1 | +package src.test.java.com.search; |
| 2 | + |
| 3 | +import org.junit.Assert; |
| 4 | +import org.junit.Test; |
| 5 | +import src.main.java.com.search.ExponentialSearch; |
| 6 | + |
| 7 | +public class ExponentialSearchTest { |
| 8 | + @Test |
| 9 | + public void testExponentialSearch() { |
| 10 | + ExponentialSearch expSearch = new ExponentialSearch(); |
| 11 | + |
| 12 | + Integer[] arr = {11, 14, 23, 29, 36, 40, 42, 52}; |
| 13 | + int x = 36; |
| 14 | + int index = expSearch.findIndex(arr, x); |
| 15 | + Assert.assertEquals("Incorrect index", 4, index); |
| 16 | + |
| 17 | + Integer[] arrTwo = {-210, -190, -180, -160, -130, -120, -100}; |
| 18 | + x = -120; |
| 19 | + index = expSearch.findIndex(arrTwo, x); |
| 20 | + Assert.assertEquals("Incorrect index", 5, index); |
| 21 | + |
| 22 | + String[] arrString = {"101", "122", "136", "165", "225", "251", "291"}; |
| 23 | + String stringX = "122"; |
| 24 | + index = expSearch.findIndex(arrString, stringX); |
| 25 | + Assert.assertEquals("Incorrect index", 1, index); |
| 26 | + |
| 27 | + String[] arrThree = {}; |
| 28 | + Assert.assertEquals("Incorrect index", -1, expSearch.findIndex(arrThree, "")); |
| 29 | + } |
| 30 | + |
| 31 | +} |
0 commit comments