forked from ucsd-cse15l-s23/list-examples-grader
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestListExamples.java
More file actions
50 lines (44 loc) · 1.43 KB
/
TestListExamples.java
File metadata and controls
50 lines (44 loc) · 1.43 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
import static org.junit.Assert.*;
import org.junit.*;
import java.util.Arrays;
import java.util.List;
class IsA implements StringChecker {
public boolean checkString(String s) {
return s.equalsIgnoreCase("a");
}
}
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(timeout=500)
public void testMergeEmpty() {
List<String> a = Arrays.asList();
List<String> b = Arrays.asList();
List<String> merged = ListExamples.merge(a, b);
List<String> expected = Arrays.asList();
assertEquals(expected, merged);
}
@Test(timeout=500)
public void testFilter() {
List<String> a = Arrays.asList("a", "b", "c");
List<String> b = Arrays.asList("b", "c", "d");
List<String> aExpected = Arrays.asList("a");
List<String> bExpected = Arrays.asList();
List<String> c = ListExamples.filter(a, new IsA());
List<String> d = ListExamples.filter(b, new IsA());
assertEquals(aExpected, c);
assertEquals(bExpected, d);
}
@Test(timeout=500)
public void testFilerEmpty() {
List<String> a = Arrays.asList();
List<String> aExpected = ListExamples.filter(a, new IsA());
assertEquals(aExpected, a);
}
}