-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTest5.java
90 lines (71 loc) · 3.77 KB
/
Test5.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
class Test5 {
public static void main(String[] args) {
CS2030STest i = new CS2030STest();
SourceList<Integer> intList;
intList = new Pair<>(1, new Pair<>(2, new Pair<>(3, new Pair<>(4, new EmptyList<>()))));
i.expect("mapping 1 2 3 4 from integers to string",
intList.map(new IntegerToString()).toString(), "\"1\", \"2\", \"3\", \"4\", EmptyList");
intList = new Pair<>(1, new Pair<>(2, new Pair<>(3, new Pair<>(4, new EmptyList<>()))));
intList.map(new IntegerToString());
i.expect("mapping should not change the original list",
intList.toString(), "1, 2, 3, 4, EmptyList");
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 map above to SourceList<String>",
intListStr + "SourceList<String> l = intList.map(new IntegerToString());", true);
i.expectCompile(
"should not be able to assign return value from the map above to SourceList<Integer>",
intListStr + "SourceList<Integer> l = intList.map(new IntegerToString());", false);
i.expect("mapping an empty list should give another emptylist",
new EmptyList<Integer>().map(new IntegerToString()).toString(), "EmptyList");
i.expectCompile(
"should be able to assign return value from the map above to SourceList<String>",
"SourceList<String> l = new EmptyList<Integer>().map(new IntegerToString());", true);
i.expectCompile(
"should not be able to assign return value from the filter above to SourceList<Integer>",
"SourceList<Integer> l = new EmptyList<Integer>.map(new IntegerToString());", false);
SourceList<String> strList;
strList = new Pair<>("AA", new Pair<>("A", new Pair<>("", new EmptyList<>())));
String strListStr = String.join("",
"SourceList<String> strList = new Pair<>(\"AA\", ",
"new Pair<>(\"A\", ",
"new Pair<>(\"\", ",
"new EmptyList<>())));");
i.expect("mapping \"AA\" \"A\" \"\" from string to integer",
strList.map(new StringToLength()).toString(), "2, 1, 0, EmptyList");
i.expectCompile(
"should be able to assign return value from the map above to SourceList<Integer>",
strListStr + "SourceList<Integer> l = strList.map(new StringToLength());", true);
i.expectCompile(
"should not be able to assign return value from the map above to SourceList<String>",
strListStr + "SourceList<String> l = strList.map(new StringToLength());", false);
i.expectCompile(
"should be able to chain two maps (intList.map(..).map(..))",
intListStr + "intList.map(new IntegerToString()).map(new StringToLength())", true);
i.expectCompile(
"should be able to chain two maps (emptyList.map(..).map(..))",
"new EmptyList<Integer>().map(new IntegerToString()).map(new StringToLength())", true);
i.expectCompile(
"should be able to chain map and filter (strList.map(..).filter(..))",
strListStr + "strList.map(new StringToLength()).filter(new GreaterThanTwo())", true);
i.expectCompile(
"should be able to chain filter and map (intList.filter(..).map(..))",
intListStr + "intList.filter(new GreaterThanTwo()).map(new IntegerToString())", true);
String a = String.join("",
strListStr,
"class A implements Transformer<Object,Integer> { ",
" public Integer transform(Object o) {",
" return 0;",
" }",
"}",
"SourceList<Object> l = strList.map(new A());");
i.expectCompile(
"should be able to map Transformer<Object,Integer> and assign to SourceList<Object>",
a, true);
}
}