-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBinarySearchTest.java
More file actions
47 lines (40 loc) · 1.17 KB
/
BinarySearchTest.java
File metadata and controls
47 lines (40 loc) · 1.17 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
package cas2xb3.greenlightTests;
import cas2xb3.greenlight.*;
import static org.junit.Assert.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import edu.princeton.cs.algs4.BinarySearch;
public class BinarySearchTest {
public Comparable[] x = {1,3,5,6,7,8,9,11,23,44,46,56,77,102,302,404,505,600};
@Before// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
public void setUp() throws Exception {
}
@After
public void tearDown() throws Exception {
x=null;
}
@Test
public void test() {
boolean result = true;
if(cas2xb3.greenlight.BinarySearch.indexOf(x, -100, 0, x.length) != 0){
result = false;
}
if(cas2xb3.greenlight.BinarySearch.indexOf(x, 4, 0, x.length) != 2){
result = false;
}
if(cas2xb3.greenlight.BinarySearch.indexOf(x, 15, 0, x.length) != 8){
result = false;
}
if(cas2xb3.greenlight.BinarySearch.indexOf(x, 45, 0, x.length) != 10){
result = false;
}
if(cas2xb3.greenlight.BinarySearch.indexOf(x, 200, 0, x.length) != 14){
result = false;
}
if(cas2xb3.greenlight.BinarySearch.indexOf(x, 900, 0, x.length) != 18){
result = false;
}
assertTrue(result);
}
}