-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathInterpolationSearchTest.java
32 lines (26 loc) · 1.02 KB
/
InterpolationSearchTest.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
package by.andd3dfx.search;
import org.junit.Test;
import static org.assertj.core.api.Assertions.assertThat;
public class InterpolationSearchTest {
@Test
public void perform() {
assertThat(InterpolationSearch.perform(new int[]{1, 2, 3, 4, 5}, 4))
.isEqualTo(3);
assertThat(InterpolationSearch.perform(new int[]{1, 2, 2, 3, 4, 8}, 2))
.isEqualTo(1);
assertThat(InterpolationSearch.perform(new int[]{-2, -1, 1, 2, 5, 8, 9, 12, 15}, 12))
.isEqualTo(7);
}
@Test
public void performWhenNothingFound() {
assertThat(InterpolationSearch.perform(new int[]{1, 2, 3, 4, 5}, 41))
.isEqualTo(-1);
}
@Test
public void determineMid() {
assertThat(InterpolationSearch.determineMid(new int[]{0, 1, 2, 3, 4, 5}, 3, 0, 5))
.isEqualTo(3);
assertThat(InterpolationSearch.determineMid(new int[]{0, 1, 2, 3, 4, 25}, 3, 0, 5))
.isEqualTo(0);
}
}