-
Notifications
You must be signed in to change notification settings - Fork 0
/
Task22.java
130 lines (106 loc) · 3.78 KB
/
Task22.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
package st;
import static org.junit.Assert.*;
import java.util.ArrayList;
import static org.hamcrest.CoreMatchers.*;
import org.junit.Before;
import org.junit.Test;
import st.EntryMap;
import st.TemplateEngine;
public class Task1 {
private st.EntryMap map;
private st.TemplateEngine engine;
@Before
public void setUp() throws Exception {
map = new EntryMap();
engine = new TemplateEngine();
}
// For M_0
@Test
public void deletesunmatchedempty(){
map.store("d", "Adam", true);
String result = engine.evaluate("${}${d}", map,"delete-unmatched");
assertEquals("Adam",result);
}
//For M_1
@Test
public void booleannotReset(){
map.store("d", "Adam", true);
String result = engine.evaluate("$A{d}", map,"delete-unmatched");
assertEquals("$A{d}",result);
}
//For M_2
@Test
public void doesntcatchafterTemplateDeleted(){
map.store("d", "Adam", true);
String result = engine.evaluate("${}e", map,"delete-unmatched");
assertEquals("e",result);
}
// For M_3
@Test
public void Spec4(){
// Everything should be between ${ and }
// Templates boundaries are omitted
map.store("$", "loves", true);
map.store("hahahaha hohohohoho", "cheesy", true);
map.store("\n", "bangos", false);
String result = engine.evaluate("${$} ${hahahaha hohohohoho} ${\n}", map,"keep-unmatched");
assertEquals("loves cheesy bangos",result);
}
//for M_4
@Test
public void TestDuplicateEntriesF() {
map.store("name", "Adam", false);
map.store("name", "Adam", false);
assertEquals(map.getEntries().size(), 1);
}
// for M_5
@Test
public void Spec4_2(){
// Everything should be between ${ and }
// Templates boundaries are omitted
map.store("name", "Adam", true);
map.store("Name", "Dykes", false);
String result = engine.evaluate("Hello ${name} ${Name}", map,"keep-unmatched");
assertEquals("Hello Adam Dykes",result);
}
//For M_6
@Test
public void Spec3MatchEmpty(){
// Matching mode cannot be EMPTY -> default = delete-unmatched
map.store("name", "Adam", true);
map.store("Name", "Dykes", true);
String result = engine.evaluate("Hello ${name} ${Name ${type}}", map,"");
assertEquals("Hello Adam Dykes",result);
}
//For M_7
@Test
public void Spec8DeleteUnmatched(){
// Engine processes one template at a time and attempts to match it against the keys of the entry map
// until there is a match or the entry list is exhausted
map.store("name", "Adam", true);
map.store("sur Brown", "Dykes", true);
map.store("type","Brown", false);
String result = engine.evaluate("Hello ${name} ${sur ${type}} ${type} ${tt}", map,"delete-unmatched");
assertEquals("Hello Adam Dykes Brown ",result);
}
//For M_8
@Test
public void Stringooboundserror(){
map.store("d", "Adam", true);
map.store("de", "Adam", true);
map.store("dAdam", "hey!", true);
String result = engine.evaluate("${d${${dAdam}}}", map,"delete-unmatched");
assertEquals("Adam",result);
}
//For M_9
@Test
public void Spec8KeepUnmatched(){
// Engine processes one template at a time and attempts to match it against the keys of the entry map
// until there is a match or the entry list is exhausted
map.store("name", "Adam", true);
map.store("sur Brown", "Dykes", true);
map.store("type","Brown", false);
String result = engine.evaluate("Hello ${name} ${sur ${type}} ${type} ${tt}", map,"keep-unmatched");
assertEquals("Hello Adam Dykes Brown ${tt}",result);
}
}