forked from exercism/java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBinarySearchTest.java
More file actions
136 lines (119 loc) · 4.14 KB
/
Copy pathBinarySearchTest.java
File metadata and controls
136 lines (119 loc) · 4.14 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import static org.junit.Assert.assertEquals;
import org.junit.Ignore;
import org.junit.Test;
public class BinarySearchTest {
public static final List<Integer> EMPTY_LIST
= Collections.unmodifiableList(new ArrayList<Integer>(0));
public static final List<Integer> LIST_OF_UNIT_LENGTH
= Collections.unmodifiableList(
Arrays.asList(6)
);
private static final List<Integer> SORTED_LIST
= Collections.unmodifiableList(
Arrays.asList(1, 3, 4, 6, 8, 9, 11)
);
public static final List<Integer> SORTED_LIST_OF_ODD_LENGTH
= Collections.unmodifiableList(
Arrays.asList(1, 3, 5, 8, 13, 21, 34, 55,
89, 144, 233, 377, 634)
);
public static final List<Integer> SORTED_LIST_OF_EVEN_LENGTH
= Collections.unmodifiableList(
Arrays.asList(1, 3, 5, 8, 13, 21, 34, 55,
89, 144, 233, 377)
);
@Test
public void findsAValueInAnArrayWithOneElement() {
BinarySearch<Integer> sut = new BinarySearch<>(LIST_OF_UNIT_LENGTH);
final int value = 6;
final int actual = sut.indexOf(value);
final int expected = 0;
assertEquals(expected, actual);
}
@Ignore
@Test
public void findsAValueInTheMiddleOfAnArray() {
BinarySearch<Integer> sut = new BinarySearch<>(SORTED_LIST);
final int value = 6;
final int actual = sut.indexOf(value);
final int expected = 3;
assertEquals(expected, actual);
}
@Ignore
@Test
public void findsAValueAtTheBeginningOfAnArray() {
BinarySearch<Integer> sut = new BinarySearch<>(SORTED_LIST);
final int value = 1;
final int actual = sut.indexOf(value);
final int expected = 0;
assertEquals(expected, actual);
}
@Ignore
@Test
public void findsAValueAtTheEndOfAnArray() {
BinarySearch<Integer> sut = new BinarySearch<>(SORTED_LIST);
final int value = 11;
final int actual = sut.indexOf(value);
final int expected = 6;
assertEquals(expected, actual);
}
@Ignore
@Test
public void findsAValueInAnArrayOfOddLength() {
BinarySearch<Integer> sut = new BinarySearch<>(SORTED_LIST_OF_ODD_LENGTH);
final int value = 144;
final int actual = sut.indexOf(value);
final int expected = 9;
assertEquals(expected, actual);
}
@Ignore
@Test
public void findsAValueInAnArrayOfEvenLength() {
BinarySearch<Integer> sut
= new BinarySearch<>(SORTED_LIST_OF_EVEN_LENGTH);
final int value = 21;
final int actual = sut.indexOf(value);
final int expected = 5;
assertEquals(expected, actual);
}
@Ignore
@Test
public void identifiesThatAValueIsNotIncludedInTheArray() {
BinarySearch<Integer> sut = new BinarySearch<>(SORTED_LIST);
final int value = 7;
final int actual = sut.indexOf(value);
final int expected = -1;
assertEquals(expected, actual);
}
@Ignore
@Test
public void aValueSmallerThanTheArraysSmallestValueIsNotIncluded() {
BinarySearch<Integer> sut = new BinarySearch<>(SORTED_LIST);
final int value = 0;
final int actual = sut.indexOf(value);
final int expected = -1;
assertEquals(expected, actual);
}
@Ignore
@Test
public void aValueLargerThanTheArraysSmallestValueIsNotIncluded() {
BinarySearch<Integer> sut = new BinarySearch<>(SORTED_LIST);
final int value = 13;
final int actual = sut.indexOf(value);
final int expected = -1;
assertEquals(expected, actual);
}
@Ignore
@Test
public void nothingIsIncludedInAnEmptyArray() {
BinarySearch<Integer> sut = new BinarySearch<>(EMPTY_LIST);
final int value = 1;
final int actual = sut.indexOf(value);
final int expected = -1;
assertEquals(expected, actual);
}
}