-
Notifications
You must be signed in to change notification settings - Fork 1
/
Test4.java
64 lines (50 loc) · 2.67 KB
/
Test4.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
61
62
63
64
class Test4 {
public static void main(String[] args) {
CS2030STest i = new CS2030STest();
SourceList<Integer> intList = new Pair<>(1, new Pair<>(2, new Pair<>(3,
new Pair<>(4, new EmptyList<>()))));
i.expect("filtering 1 2 3 4 for integers larger than 2 should give 3 4 only",
intList.filter(new GreaterThanTwo()).toString(), "3, 4, EmptyList");
intList = new Pair<>(1, new Pair<>(2, new Pair<>(3, new Pair<>(4, new EmptyList<>()))));
intList.filter(new GreaterThanTwo());
i.expect("filtering should not change the original list",
intList.toString(), "1, 2, 3, 4, EmptyList");
i.expect("filtering should return a new list",
intList.filter(new GreaterThanTwo()) == intList, false);
String intListStr = String.join("",
"SourceList<Integer> intList = new Pair<>(1,",
"new Pair<>(2,",
"new Pair<>(3,",
"new Pair<>(4,",
"new EmptyList<>()))));");
i.expectCompile("should be able to assign return value from the filter above " +
"to SourceList<Integer>",
intListStr + "SourceList<Integer> l = intList.filter(new GreaterThanTwo());", true);
i.expectCompile("should not be able to assign return value from the filter above " +
"to SourceList<String>",
intListStr + "SourceList<String> l = intList.filter(new GreaterThanTwo());", false);
i.expect("filtering an empty list should give another emptylist",
new EmptyList<Integer>().filter(new GreaterThanTwo()).toString(), "EmptyList");
i.expectCompile("should be able to assign return value from the filter above " +
"to SourceList<Integer>",
"SourceList<Integer> l = new EmptyList<Integer>().filter(new GreaterThanTwo());", true);
i.expectCompile("should not be able to assign return value from the filter above " +
"to SourceList<String>",
"SourceList<String> l = new EmptyList<Integer>().filter(new GreaterThanTwo());", false);
i.expectCompile("should be able to chain two filters (intList.filter(..).filter(..))",
intListStr + "intList.filter(new GreaterThanTwo()).filter(new GreaterThanTwo());", true);
i.expectCompile("should be able to chain two filters (emptyList.filter(..).filter(..))",
"new EmptyList<Integer>().filter(new GreaterThanTwo()).filter(new GreaterThanTwo());",
true);
String a = String.join("", intListStr,
"class A implements BooleanCondition<Object> { ",
" public boolean test(Object o) {",
" return false;",
" }",
"}",
"intList.filter(new A());"
);
i.expectCompile("should be able to filter a BooleanCondition<Object>",
a, true);
}
}