forked from ucsd-cse15l-w23/lab3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ListTests.java
58 lines (48 loc) · 1.38 KB
/
ListTests.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
import static org.junit.Assert.*;
import java.util.*;
import java.beans.Transient;
import org.junit.*;
public class ListTests {
@Test
public void testFilter() {
List<String> ref = new ArrayList<>();
ref.add("hello");
ref.add("hellicious");
ref.add("helicopter");
ref.add("world");
ref.add("computers");
List<String> answer = new ArrayList<>();
answer.add("hello");
answer.add("hellicious");
answer.add("helicopter");
StringChecker sc = new StringChecker() {
public boolean checkString(String s) {
if (s.contains("hel")) {
return true;
} else {
return false;
}
}
};
assertEquals(answer, ListExamples.filter(ref, sc));
}
@Test
public void testMerge() {
List<String> list1 = new ArrayList<>();
list1.add("a");
list1.add("b");
list1.add("c");
List<String> list2 = new ArrayList<>();
list2.add("b");
list2.add("d");
list2.add("e");
List<String> answer = new ArrayList<>();
answer.add("a");
answer.add("b");
answer.add("b");
answer.add("c");
answer.add("d");
answer.add("e");
assertEquals(answer, ListExamples.merge(list1, list2));
}
}