-
Notifications
You must be signed in to change notification settings - Fork 16
/
TestListExamples.java
47 lines (41 loc) · 1.47 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
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", "c", "e");
List<String> right = Arrays.asList("b", "h");
List<String> merged = ListExamples.merge(left, right);
List<String> expected = Arrays.asList("a", "b", "c", "e", "h");
assertEquals(expected, merged);
}
@Test(timeout = 500)
public void testMergeLeftEnd() {
List<String> left = Arrays.asList("a", "c", "z");
List<String> right = Arrays.asList("b", "d");
List<String> merged = ListExamples.merge(left, right);
List<String> expected = Arrays.asList("a", "b", "c", "d", "z");
assertEquals(expected, merged);
}
@Test(timeout = 500)
public void testFilterSingle() {
List<String> input = Arrays.asList("Moon", "MOO", "moo");
List<String> expect = Arrays.asList("Moon");
List<String> filtered = ListExamples.filter(input, new IsMoon());
assertEquals(expect, filtered);
}
@Test(timeout = 500)
public void testFilterMulti() {
List<String> input = Arrays.asList("Moon", "MOO", "moon", "MOON");
List<String> expect = Arrays.asList("Moon", "moon", "MOON");
List<String> filtered = ListExamples.filter(input, new IsMoon());
assertEquals(expect, filtered);
}
}