forked from ucsd-cse15l-w23/lab3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ListTests.java
47 lines (41 loc) · 1.6 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
import static org.junit.Assert.*;
import org.junit.*;
import java.util.*;
public class ListTests {
@Test
public void testFilter(){
List<String> testList = new ArrayList<>();
testList.add("a");
testList.add("abc");
testList.add("abcdef");
List<String> expected = new ArrayList<>();
expected.add("abcdef");
List<String> filteredList = ListExamples.filter(testList, new implementedStringChecker());
assertEquals(filteredList.size(), expected.size());
assertEquals(filteredList.get(0), expected.get(0));
testList.add("abcdefg");
filteredList = ListExamples.filter(testList, new implementedStringChecker());
expected.add("abcdefg");
assertEquals(filteredList.size(), expected.size());
assertEquals(filteredList.get(0), expected.get(0));
assertEquals(filteredList.get(1), expected.get(1));
}
@Test
public void testMerge(){
List<String> testList1 = new ArrayList<>();
testList1.add("1");
testList1.add("3");
testList1.add("5");
List<String> testList2 = new ArrayList<>();
testList2.add("2");
testList2.add("4");
testList2.add("6");
List<String> mergedList = ListExamples.merge(testList1, testList2);
List<String> expectedList = new ArrayList<>();
for(int i = 1; i <= 6; i++) expectedList.add("" + i);
assertEquals(mergedList.size(), expectedList.size());
for(int i = 0; i < mergedList.size(); i++) {
assertEquals(mergedList.get(i), expectedList.get(i));
}
}
}