forked from ucsd-cse15l-s23/list-examples-grader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TestListExamples.java
60 lines (55 loc) · 1.76 KB
/
TestListExamples.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
60
import static org.junit.Assert.*;
import org.junit.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
// class IsMoon implements StringChecker {
// public boolean checkString(String s) {
// return s.equalsIgnoreCase("moon");
// }
// }
class StringChecker2 implements StringChecker {
public boolean checkString(String s) {
if (s.charAt(0) == 's') {
return true;
}
return false;
}
}
public class TestListExamples {
@Test(timeout = 500)
public void testMergeRightEnd() {
List<String> left = Arrays.asList("a", "b", "c");
List<String> right = Arrays.asList("a", "d");
List<String> merged = ListExamples.merge(left, right);
List<String> expected = Arrays.asList("a", "a", "b", "c", "d");
assertEquals(expected, merged);
}
@Test
public void testFilter() {
List<String> stringList = new ArrayList<String>();
stringList.add("string");
stringList.add("ey");
stringList.add("s2");
List<String> stringList2 = new ArrayList<String>();
stringList2.add("string");
stringList2.add("s2");
StringChecker2 sc = new StringChecker2();
assertEquals(stringList2, ListExamples.filter(stringList, sc));
}
@Test
public void testMerge() {
List<String> stringList = new ArrayList<String>();
stringList.add("a");
stringList.add("b");
List<String> stringList2 = new ArrayList<String>();
stringList2.add("a");
stringList2.add("d");
List<String> stringList3 = new ArrayList<String>();
stringList3.add("a");
stringList3.add("a");
stringList3.add("b");
stringList3.add("d");
assertEquals(stringList3, ListExamples.merge(stringList, stringList2));
}
}