forked from ucsd-cse15l-s24/list-examples-grader
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestListExamples.java
More file actions
36 lines (29 loc) · 1.02 KB
/
TestListExamples.java
File metadata and controls
36 lines (29 loc) · 1.02 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
import static org.junit.Assert.*;
import org.junit.*;
import java.util.Arrays;
import java.util.List;
class IsMoon implements StringChecker {
public boolean checkString(String s) {
return s.equalsIgnoreCase("moon");
}
}
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 testFilter() {
List<String> input = Arrays.asList("star", "moon", "sun", "moon");
StringChecker checker = new IsMoon();
// Action
List<String> result = ListExamples.filter(input, checker);
// Assert
List<String> expected = Arrays.asList("moon", "moon");
assertEquals("The filtered list should only contain 'moon' elements", expected, result);
}
}