Skip to content

Commit 2dadab4

Browse files
committed
Fix automated tests (Building city houses now requires a city)
git-svn-id: svn://tron.homeunix.org/simutrans/simutrans/trunk@11712 8aca7d54-2c30-db11-9de9-000461428c89
1 parent 5e7983d commit 2dadab4

File tree

3 files changed

+81
-23
lines changed

3 files changed

+81
-23
lines changed

tests/tests/test_building.nut

Lines changed: 73 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,16 @@ function test_building_build_house_invalid_param()
7373

7474
function test_building_build_house_random()
7575
{
76-
local public_pl = player_x(1)
76+
local pl = player_x(0);
77+
local public_pl = player_x(1);
78+
79+
{
80+
// a city is required for the building
81+
ASSERT_EQUAL(command_x(tool_build_house).work(pl, coord3d(0, 0, 0)), "No suitable ground!")
82+
}
83+
84+
// add the required city
85+
ASSERT_EQUAL(command_x(tool_add_city).work(public_pl, coord3d(8, 8, 0), "0"), null)
7786

7887
// no default_param: random building
7988
// built by player, owned by pubic player
@@ -91,13 +100,21 @@ function test_building_build_house_random()
91100
ASSERT_TRUE(tile_x(1, 0, 0).is_empty())
92101
ASSERT_TRUE(tile_x(1, 1, 0).is_empty())
93102
}
103+
104+
// clean up
105+
ASSERT_EQUAL(command_x(tool_remover).work(public_pl, coord3d(8, 8, 0)), null); // remove city
106+
ASSERT_EQUAL(command_x(tool_remove_way).work(public_pl, coord3d(7, 9, 0), coord3d(9, 9, 0), "" + wt_road), null);
107+
RESET_ALL_PLAYER_FUNDS();
94108
}
95109

96110

97111
function test_building_build_house_valid_desc()
98112
{
99113
local public_pl = player_x(1)
100114

115+
// add the required city
116+
ASSERT_EQUAL(command_x(tool_add_city).work(public_pl, coord3d(8, 8, 0), "0"), null)
117+
101118
// Valid default_param: Build specific building
102119
{
103120
ASSERT_EQUAL(command_x(tool_build_house).work(public_pl, coord3d(0, 0, 0), "1#RUIN_0"), null)
@@ -115,29 +132,39 @@ function test_building_build_house_valid_desc()
115132
}
116133

117134
// clean up
118-
RESET_ALL_PLAYER_FUNDS()
135+
ASSERT_EQUAL(command_x(tool_remover).work(public_pl, coord3d(8, 8, 0)), null); // remove city
136+
ASSERT_EQUAL(command_x(tool_remove_way).work(public_pl, coord3d(7, 9, 0), coord3d(9, 9, 0), "" + wt_road), null);
137+
RESET_ALL_PLAYER_FUNDS();
119138
}
120139

121140

122141
function test_building_build_house_invalid_desc()
123142
{
124143
local public_pl = player_x(1)
125144

145+
// add the required city
146+
ASSERT_EQUAL(command_x(tool_add_city).work(public_pl, coord3d(8, 8, 0), "0"), null)
147+
126148
// Valid default_param: Build specific building
127149
{
128150
ASSERT_EQUAL(command_x(tool_build_house).work(public_pl, coord3d(0, 0, 0), "1#nonexistent"), "")
129151
ASSERT_EQUAL(tile_x(0,0,0).find_object(mo_building), null)
130152
}
131153

132154
// clean up
133-
RESET_ALL_PLAYER_FUNDS()
155+
ASSERT_EQUAL(command_x(tool_remover).work(public_pl, coord3d(8, 8, 0)), null); // remove city
156+
ASSERT_EQUAL(command_x(tool_remove_way).work(public_pl, coord3d(7, 9, 0), coord3d(9, 9, 0), "" + wt_road), null);
157+
RESET_ALL_PLAYER_FUNDS();
134158
}
135159

136160

137161
function test_building_build_house_auto_rotation_attraction()
138162
{
139163
local public_pl = player_x(1)
140164

165+
// add the required city
166+
ASSERT_EQUAL(command_x(tool_add_city).work(public_pl, coord3d(8, 8, 0), "0"), null)
167+
141168
// TODO: Actually check rotation
142169
{
143170
ASSERT_EQUAL(command_x(tool_build_house).work(public_pl, coord3d(0, 0, 0), "1ARUIN_0"), null)
@@ -155,14 +182,19 @@ function test_building_build_house_auto_rotation_attraction()
155182
}
156183

157184
// clean up
158-
RESET_ALL_PLAYER_FUNDS()
185+
ASSERT_EQUAL(command_x(tool_remover).work(public_pl, coord3d(8, 8, 0)), null); // remove city
186+
ASSERT_EQUAL(command_x(tool_remove_way).work(public_pl, coord3d(7, 9, 0), coord3d(9, 9, 0), "" + wt_road), null);
187+
RESET_ALL_PLAYER_FUNDS();
159188
}
160189

161190

162191
function test_building_build_house_auto_rotation_citybuilding()
163192
{
164193
local public_pl = player_x(1)
165194

195+
// add the required city
196+
ASSERT_EQUAL(command_x(tool_add_city).work(public_pl, coord3d(8, 8, 0), "0"), null)
197+
166198
// TODO: Actually check rotation
167199
{
168200
ASSERT_EQUAL(command_x(tool_build_house).work(public_pl, coord3d(0, 0, 0), "1ARES_01_23"), null)
@@ -172,34 +204,42 @@ function test_building_build_house_auto_rotation_citybuilding()
172204
}
173205

174206
// clean up
175-
ASSERT_EQUAL(command_x(tool_remover).work(public_pl, coord3d(0, 0, 0)), null)
176-
RESET_ALL_PLAYER_FUNDS()
207+
ASSERT_EQUAL(command_x(tool_remover).work(public_pl, coord3d(0, 0, 0)), null); // remove house
208+
ASSERT_EQUAL(command_x(tool_remover).work(public_pl, coord3d(8, 8, 0)), null); // remove city
209+
ASSERT_EQUAL(command_x(tool_remove_way).work(public_pl, coord3d(7, 9, 0), coord3d(9, 9, 0), "" + wt_road), null);
210+
RESET_ALL_PLAYER_FUNDS();
177211
}
178212

179213

180214
function test_building_build_multi_tile_sloped()
181215
{
182-
local pl = player_x(1)
216+
local public_pl = player_x(1)
183217
local remover = command_x(tool_remover)
184218
local builder = command_x(tool_build_house)
185219

186220
local building_desc = building_desc_x("STADIUM2") // 3x2 size
187221

188-
ASSERT_EQUAL(command_x.grid_raise(pl, coord3d(4, 2, 0)), null)
222+
ASSERT_EQUAL(command_x.grid_raise(public_pl, coord3d(4, 2, 0)), null)
223+
224+
// add the required city
225+
ASSERT_EQUAL(command_x(tool_add_city).work(public_pl, coord3d(8, 8, 0), "0"), null)
189226

190227
{
191-
ASSERT_EQUAL(builder.work(pl, coord3d(3, 1, 0), "11" + building_desc.get_name()), null)
192-
ASSERT_EQUAL(remover.work(pl, coord3d(3, 1, 0)), null)
228+
ASSERT_EQUAL(builder.work(public_pl, coord3d(3, 1, 0), "11" + building_desc.get_name()), null)
229+
ASSERT_EQUAL(remover.work(public_pl, coord3d(3, 1, 0)), null)
193230

194231
ASSERT_EQUAL(tile_x(3, 1, 0).get_slope(), slope.southeast)
195232
ASSERT_EQUAL(tile_x(4, 1, 0).get_slope(), slope.southwest)
196233
ASSERT_EQUAL(tile_x(3, 2, 0).get_slope(), slope.northeast)
197234
ASSERT_EQUAL(tile_x(4, 2, 0).get_slope(), slope.northwest)
198235
}
199236

200-
ASSERT_EQUAL(command_x.grid_lower(pl, coord3d(4, 2, 1)), null)
237+
ASSERT_EQUAL(command_x.grid_lower(public_pl, coord3d(4, 2, 1)), null)
201238

202-
RESET_ALL_PLAYER_FUNDS()
239+
// clean up
240+
ASSERT_EQUAL(command_x(tool_remover).work(public_pl, coord3d(8, 8, 0)), null); // remove city
241+
ASSERT_EQUAL(command_x(tool_remove_way).work(public_pl, coord3d(7, 9, 0), coord3d(9, 9, 0), "" + wt_road), null);
242+
RESET_ALL_PLAYER_FUNDS();
203243
}
204244

205245

@@ -229,6 +269,9 @@ function test_building_buy_house_from_public_player()
229269
local old_cash = pl.get_cash()[0]
230270
local old_maint = pl.get_current_maintenance()
231271

272+
// add the required city
273+
ASSERT_EQUAL(command_x(tool_add_city).work(public_pl, coord3d(8, 8, 0), "0"), null)
274+
232275
ASSERT_EQUAL(command_x(tool_build_house).work(public_pl, coord3d(0,0,0), "11" + building_desc.get_name()), null)
233276
ASSERT_EQUAL(building_x(0,0,0).get_owner().nr, 16) // building is unowned
234277

@@ -260,7 +303,9 @@ function test_building_buy_house_from_public_player()
260303

261304
// clean up
262305
ASSERT_EQUAL(command_x(tool_remover).work(public_pl, coord3d(0,0,0)), null)
263-
RESET_ALL_PLAYER_FUNDS()
306+
ASSERT_EQUAL(command_x(tool_remover).work(public_pl, coord3d(8,8,0)), null); // remove city
307+
ASSERT_EQUAL(command_x(tool_remove_way).work(public_pl, coord3d(7, 9, 0), coord3d(9, 9, 0), "" + wt_road), null);
308+
RESET_ALL_PLAYER_FUNDS();
264309
}
265310

266311

@@ -269,6 +314,9 @@ function test_building_buy_house_attraction()
269314
local pl = player_x(0)
270315
local public_pl = player_x(1)
271316

317+
// add the required city
318+
ASSERT_EQUAL(command_x(tool_add_city).work(public_pl, coord3d(8, 8, 0), "0"), null)
319+
272320
local building_desc = building_desc_x("STADIUM2")
273321
local builder = command_x(tool_build_house)
274322

@@ -282,7 +330,9 @@ function test_building_buy_house_attraction()
282330

283331
// clean up
284332
ASSERT_EQUAL(command_x(tool_remover).work(public_pl, coord3d(0,0,0)), null)
285-
RESET_ALL_PLAYER_FUNDS()
333+
ASSERT_EQUAL(command_x(tool_remover).work(public_pl, coord3d(8,8,0)), null); // remove city
334+
ASSERT_EQUAL(command_x(tool_remove_way).work(public_pl, coord3d(7, 9, 0), coord3d(9, 9, 0), "" + wt_road), null);
335+
RESET_ALL_PLAYER_FUNDS();
286336
}
287337

288338

@@ -294,6 +344,9 @@ function test_building_rotate_house()
294344
local rotator = command_x(tool_rotate_building)
295345
local remover = command_x(tool_remover)
296346

347+
// add the required city
348+
ASSERT_EQUAL(command_x(tool_add_city).work(public_pl, coord3d(8, 8, 0), "0"), null)
349+
297350
// invalid coordinate
298351
{
299352
ASSERT_EQUAL(rotator.work(pl, coord3d(-1, -1, 0)), "")
@@ -326,7 +379,9 @@ function test_building_rotate_house()
326379

327380
// clean up
328381
ASSERT_EQUAL(command_x(tool_remover).work(public_pl, coord3d(0, 0, 0)), null)
329-
RESET_ALL_PLAYER_FUNDS()
382+
ASSERT_EQUAL(command_x(tool_remover).work(public_pl, coord3d(8, 8, 0)), null); // remove city
383+
ASSERT_EQUAL(command_x(tool_remove_way).work(public_pl, coord3d(7, 9, 0), coord3d(9, 9, 0), "" + wt_road), null);
384+
RESET_ALL_PLAYER_FUNDS();
330385
}
331386

332387

@@ -338,20 +393,17 @@ function test_building_rotate_harbour()
338393
local harbours = building_desc_x.get_building_list(building_desc_x.harbour)
339394
harbours = harbours.filter(@(idx, val) val.get_type() == building_desc_x.harbour)
340395
local harbour = harbours[0]
341-
local stationbuilder = command_x(tool_build_station)
342-
local rotator = command_x(tool_rotate_building)
343-
local remover = command_x(tool_remover)
344396

345397
ASSERT_EQUAL(setclimate.work(pl, coord3d(4, 2, 0), coord3d(5, 2, 0), "" + cl_water), null)
346398
ASSERT_EQUAL(setslope(pl, coord3d(3, 2, 0), slope.east), null)
347-
ASSERT_EQUAL(stationbuilder.work(pl, coord3d(3, 2, 0), harbour.get_name()), null)
399+
ASSERT_EQUAL(command_x(tool_build_station).work(pl, coord3d(3, 2, 0), harbour.get_name()), null)
348400

349401
{
350-
ASSERT_EQUAL(rotator.work(pl, coord3d(3, 2, 0)), "Cannot rotate this building!")
402+
ASSERT_EQUAL(command_x(tool_rotate_building).work(pl, coord3d(3, 2, 0)), "Cannot rotate this building!")
351403
}
352404

353405
// clean up
354-
ASSERT_EQUAL(remover.work(pl, coord3d(3, 2, 0)), null)
406+
ASSERT_EQUAL(command_x(tool_remover).work(pl, coord3d(3, 2, 0)), null)
355407
ASSERT_EQUAL(setslope(pl, coord3d(3, 2, 0), slope.flat), null)
356408
ASSERT_EQUAL(setclimate.work(pl, coord3d(4, 2, 0), coord3d(5, 2, 0), "" + cl_mediterran), null)
357409

tests/tests/test_halt.nut

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@ function test_halt_build_flat_dock_in_water()
310310

311311
function test_halt_build_flat_dock_occupied()
312312
{
313+
ASSERT_EQUAL(command_x(tool_add_city).work(player_x(1), coord3d(8, 8, 0), "0"), null)
313314
ASSERT_EQUAL(command_x(tool_build_house).work(player_x(1), coord3d(4, 2, 0), "11RES_01_23"), null)
314315

315316
{
@@ -318,7 +319,9 @@ function test_halt_build_flat_dock_occupied()
318319

319320
// clean up
320321
ASSERT_EQUAL(command_x(tool_remover).work(player_x(1), coord3d(4, 2, 0)), null)
321-
RESET_ALL_PLAYER_FUNDS()
322+
ASSERT_EQUAL(command_x(tool_remover).work(player_x(1), coord3d(8, 8, 0)), null); // remove city
323+
ASSERT_EQUAL(command_x(tool_remove_way).work(player_x(1), coord3d(7, 9, 0), coord3d(9, 9, 0), "" + wt_road), null);
324+
RESET_ALL_PLAYER_FUNDS();
322325
}
323326

324327

tests/tests/test_slope.nut

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ function test_slope_restore_on_foundation()
194194
{
195195
local pl = player_x(0)
196196

197+
ASSERT_EQUAL(command_x(tool_add_city).work(player_x(1), coord3d(8, 8, 0), "0"), null)
197198
ASSERT_EQUAL(command_x(tool_build_house).work(pl, coord3d(4, 2, 0), "11RES_01_23"), null)
198199

199200
{
@@ -202,7 +203,9 @@ function test_slope_restore_on_foundation()
202203

203204
// clean up
204205
ASSERT_EQUAL(command_x(tool_remover).work(player_x(1), coord3d(4, 2, 0)), null)
205-
RESET_ALL_PLAYER_FUNDS()
206+
ASSERT_EQUAL(command_x(tool_remover).work(player_x(1), coord3d(8, 8, 0)), null); // remove city
207+
ASSERT_EQUAL(command_x(tool_remove_way).work(player_x(1), coord3d(7, 9, 0), coord3d(9, 9, 0), "" + wt_road), null);
208+
RESET_ALL_PLAYER_FUNDS();
206209
}
207210

208211

0 commit comments

Comments
 (0)