-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStormTest.java
More file actions
269 lines (233 loc) · 6.21 KB
/
StormTest.java
File metadata and controls
269 lines (233 loc) · 6.21 KB
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
package stormPath;
import static org.junit.Assert.*;
import org.junit.Test;
public class StormTest {
@Test
public void testStormGetName() {
Storm s = new Storm("Danielle", 2016);
assertEquals("Danielle", s.getName());
}
@Test
public void testStormGetYear() {
Storm s = new Storm("Danielle", 2016);
assertEquals(2016, s.getYear());
}
@Test
public void testCityGetName() {
City c = new City("Veracruz");
assertEquals("Veracruz", c.getName());
}
@Test
public void testCityWasHit() {
Storm s = new Storm("Danielle", 2016);
City c = new City("Veracruz");
s.addCity(c);
assertTrue(c.wasHit(s));
}
@Test
public void testCityWasNotHit() {
Storm s = new Storm("Danielle", 2016);
City c = new City("Veracruz");
assertFalse(c.wasHit(s));
}
@Test
public void testGetCitiesOneStormNoCity() {
Storm s = new Storm("Danielle", 2016);
assertTrue(s.getCities().size() == 0);
}
private void assertTrue(boolean b) {
// TODO Auto-generated method stub
}
@Test
public void testOneStormAddCityGetCities() {
Storm s = new Storm("Danielle", 2016);
City c = new City("Veracruz");
s.addCity(c);
assertTrue(s.getCities().size() == 1);
assertTrue(s.getCities().contains(c));
}
@Test
public void testOneStormAddStormGetCities() {
Storm s = new Storm("Danielle", 2016);
City c = new City("Veracruz");
c.addStorm(s);
assertTrue(s.getCities().size() == 1);
assertTrue(s.getCities().contains(c));
assertTrue(c.wasHit(s));
}
@Test
public void testAddCityOnSamePath() {
Storm s = new Storm("Danielle", 2016);
City c1 = new City("Veracruz");
City c2 = new City("Tamiahua");
s.addCity(c1);
s.addCity(c2);
assertTrue(c1.onSamePath(c2));
}
@Test
public void testNotOnSamePath() {
City c1 = new City("Veracruz");
City c2 = new City("Tamiahua");
assertFalse(c1.onSamePath(c2));
}
@Test
public void testOneStormTwoCities() {
Storm s = new Storm("Danielle", 2016);
City c1 = new City("Veracruz");
City c2 = new City("Tamiahua");
s.addCity(c1);
c2.addStorm(s);
// Does s contain both Cities?
assertTrue(s.getCities().size() == 2);
assertTrue(s.getCities().contains(c1));
assertTrue(s.getCities().contains(c2));
// Was each City in the path of the Storm?
assertTrue(c1.wasHit(s));
assertTrue(c2.wasHit(s));
// Was c1 and c2 hit by the same storm?
assertTrue(c1.onSamePath(c2));
assertTrue(c2.onSamePath(c1));
}
@Test
public void testStormEquals() {
Storm s1 = new Storm("Danielle", 2016);
Storm s2 = new Storm("Danielle", 2016);
assertTrue(s1.equals(s2));
}
@Test
public void testStormEqualsDifferentCities() {
Storm s1 = new Storm("Danielle", 2016);
Storm s2 = new Storm("Danielle", 2016);
City c = new City("Veracruz");
s1.addCity(c);
assertTrue(s1.equals(s2));
}
@Test
public void testStormNotEqualsName() {
Storm s1 = new Storm("Danielle", 2016);
Storm s2 = new Storm("Fred", 2015);
assertFalse(s1.equals(s2));
}
@Test
public void testStormNotEqualsYear() {
Storm s1 = new Storm("Danielle", 2016);
Storm s2 = new Storm("Bonnie", 2016);
assertFalse(s1.equals(s2));
}
@Test
public void testCityEqualsNoStorms() {
City c1 = new City("Veracruz");
City c2 = new City("Veracruz");
assertTrue(c1.equals(c2));
}
@Test
public void testCityNotEqualsTwoCities() {
City c1 = new City("Veracruz");
City c2 = new City("Tamiahua");
assertFalse(c1.equals(c2));
}
@Test
public void testCityNotEqualsNonCity() {
City c1 = new City("Veracruz");
assertFalse(c1.equals("Veracruz"));
}
@Test
public void testCityEqualsTwoStorms() {
City c1 = new City("Veracruz");
City c2 = new City("Veracruz");
Storm s1 = new Storm("Danielle", 2016);
Storm s2 = new Storm("Fred", 2015);
c1.addStorm(s1);
c1.addStorm(s2);
c2.addStorm(s1);
c2.addStorm(s2);
assertTrue(c1.equals(c2));
}
@Test
public void testCityEqualsTwoStormsDifferentOrder() {
City c1 = new City("Veracruz");
City c2 = new City("Veracruz");
Storm s1 = new Storm("Danielle", 2016);
Storm s2 = new Storm("Fred", 2015);
c1.addStorm(s1);
c1.addStorm(s2);
c2.addStorm(s2);
c2.addStorm(s1);
assertTrue(c1.equals(c2));
}
@Test
public void testCityNotEqualsExtraStorm() {
City c1 = new City("Veracruz");
City c2 = new City("Veracruz");
Storm s1 = new Storm("Danielle", 2016);
Storm s2 = new Storm("Fred", 2015);
Storm s3 = new Storm("Dolly", 2014);
c1.addStorm(s1);
c1.addStorm(s2);
c2.addStorm(s2);
c2.addStorm(s1);
c2.addStorm(s3);
assertFalse(c1.equals(c2));
}
@Test
public void testCityToStringNoStorms() {
City c1 = new City("Veracruz");
String res = c1.toString();
String exp = "Veracruz ()";
assertEquals(exp, res);
}
@Test
public void testCityToStringOneStorm() {
City c1 = new City("Veracruz");
Storm s1 = new Storm("Danielle", 2016);
c1.addStorm(s1);
String res = c1.toString();
String exp = "Veracruz (Danielle)";
assertEquals(exp, res);
}
@Test
public void testCityToStringThreeStorms() {
City c1 = new City("Veracruz");
Storm s1 = new Storm("Danielle", 2016);
Storm s2 = new Storm("Fred", 2015);
Storm s3 = new Storm("Dolly", 2014);
c1.addStorm(s1);
c1.addStorm(s2);
c1.addStorm(s3);
String res = c1.toString();
String exp = "Veracruz (Danielle, Fred, Dolly)";
assertEquals(exp, res);
}
@Test
public void testStormToStringNoCities() {
Storm s1 = new Storm("Danielle", 2016);
String res = s1.toString();
String exp = "Danielle, 2016";
assertEquals(exp, res);
}
@Test
public void testStormToStringOneStorm() {
City c1 = new City("Veracruz");
Storm s1 = new Storm("Danielle", 2016);
s1.addCity(c1);
String res = s1.toString();
String exp = "Danielle, 2016" + System.lineSeparator() + c1.getName();
assertEquals(exp, res);
}
@Test
public void testStormToStringFourCities() {
City c1 = new City("Veracruz");
City c2 = new City("Tamiahua");
City c3 = new City("Toronto");
City c4 = new City("Shanghai");
Storm s1 = new Storm("Danielle", 2016);
s1.addCity(c1);
s1.addCity(c2);
s1.addCity(c3);
s1.addCity(c4);
String res = s1.toString();
String exp = "Danielle, 2016" + System.lineSeparator() + c1.getName() + System.lineSeparator() + c2.getName()
+ System.lineSeparator() + c3.getName() + System.lineSeparator() + c4.getName();
assertEquals(exp, res);
}
}