-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathFindAmountOfElementsLessThanTest.java
59 lines (53 loc) · 2.57 KB
/
FindAmountOfElementsLessThanTest.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package by.andd3dfx.search;
import org.junit.Test;
import static by.andd3dfx.search.FindAmountOfElementsLessThan.usingBinarySearch;
import static by.andd3dfx.search.FindAmountOfElementsLessThan.usingInterpolationSearch;
import static by.andd3dfx.search.FindAmountOfElementsLessThan.usingPrimitiveIteration;
import static org.assertj.core.api.Assertions.assertThat;
public class FindAmountOfElementsLessThanTest {
@Test
public void testUsingPrimitiveIteration() {
assertThat(usingPrimitiveIteration(new int[]{1, 2, 3, 5, 7}, 4))
.as("When array doesn't contain target item")
.isEqualTo(3);
assertThat(usingPrimitiveIteration(new int[]{1, 3, 4, 4, 5, 7}, 4))
.as("When array contains target item")
.isEqualTo(2);
assertThat(usingPrimitiveIteration(new int[]{5, 6, 7, 8}, 4))
.as("When all items are greater than target item")
.isEqualTo(0);
assertThat(usingPrimitiveIteration(new int[]{1, 2, 3, 3}, 4))
.as("When all items are less than target item")
.isEqualTo(4);
}
@Test
public void testUsingBinarySearch() {
assertThat(usingBinarySearch(new int[]{1, 2, 3, 5, 7}, 4))
.as("When array doesn't contain target item")
.isEqualTo(3);
assertThat(usingBinarySearch(new int[]{1, 3, 4, 4, 5, 7}, 4))
.as("When array contains target item")
.isEqualTo(2);
assertThat(usingBinarySearch(new int[]{5, 6, 7, 8}, 4))
.as("When all items are greater than target item")
.isEqualTo(0);
assertThat(usingBinarySearch(new int[]{1, 2, 3, 3}, 4))
.as("When all items are less than target item")
.isEqualTo(4);
}
@Test
public void testUsingInterpolationSearch() {
assertThat(usingInterpolationSearch(new int[]{1, 2, 3, 5, 7}, 4))
.as("When array doesn't contain target item")
.isEqualTo(3);
assertThat(usingInterpolationSearch(new int[]{1, 3, 4, 4, 5, 7}, 4))
.as("When array contains target item")
.isEqualTo(2);
assertThat(usingInterpolationSearch(new int[]{5, 6, 7, 8}, 4))
.as("When all items are greater than target item")
.isEqualTo(0);
assertThat(usingInterpolationSearch(new int[]{1, 2, 3, 3}, 4))
.as("When all items are less than target item")
.isEqualTo(4);
}
}