* clean up the test setup

* test horses, carts and their capacities
This commit is contained in:
Enno Rehling 2010-10-31 23:31:56 -07:00
parent c5418fc28b
commit 0472c35647
1 changed files with 91 additions and 42 deletions

View File

@ -8,25 +8,18 @@ local function _test_create_ship(r)
return s return s
end end
function setup() local function one_unit(r, f)
free_game()
settings.set("nmr.removenewbie", "0")
settings.set("nmr.timeout", "0")
settings.set("rules.economy.food", "4")
end
function one_unit(r, f)
local u = unit.create(f, r, 1) local u = unit.create(f, r, 1)
u:add_item("money", u.number * 100) u:add_item("money", u.number * 100)
u:clear_orders() u:clear_orders()
return u return u
end end
function two_units(r, f1, f2) local function two_units(r, f1, f2)
return one_unit(r, f1), one_unit(r, f2) return one_unit(r, f1), one_unit(r, f2)
end end
function two_factions() local function two_factions()
local f1 = faction.create("noreply@eressea.de", "human", "de") local f1 = faction.create("noreply@eressea.de", "human", "de")
local f2 = faction.create("noreply@eressea.de", "orc", "de") local f2 = faction.create("noreply@eressea.de", "orc", "de")
return f1, f2 return f1, f2
@ -34,6 +27,13 @@ end
module( "common", package.seeall, lunit.testcase ) module( "common", package.seeall, lunit.testcase )
function setup()
free_game()
settings.set("nmr.removenewbie", "0")
settings.set("nmr.timeout", "0")
settings.set("rules.economy.food", "4")
end
function DISABLE_test_eventbus_fire() function DISABLE_test_eventbus_fire()
local r = region.create(0, 0, "plain") local r = region.create(0, 0, "plain")
local f = faction.create("noreply@eressea.de", "human", "de") local f = faction.create("noreply@eressea.de", "human", "de")
@ -85,14 +85,12 @@ function test_plane()
end end
function test_pure() function test_pure()
free_game()
local r = region.create(0, 0, "plain") local r = region.create(0, 0, "plain")
assert_not_equal(nil, r) assert_not_equal(nil, r)
assert_equal(r, get_region(0, 0)) assert_equal(r, get_region(0, 0))
end end
function test_read_write() function test_read_write()
free_game()
local r = region.create(0, 0, "plain") local r = region.create(0, 0, "plain")
local f = faction.create("noreply@eressea.de", "human", "de") local f = faction.create("noreply@eressea.de", "human", "de")
local u = unit.create(f, r) local u = unit.create(f, r)
@ -118,11 +116,9 @@ function test_read_write()
assert_not_equal(nil, get_region(0, 0)) assert_not_equal(nil, get_region(0, 0))
assert_not_equal(nil, get_faction(fno)) assert_not_equal(nil, get_faction(fno))
assert_not_equal(nil, get_unit(uno)) assert_not_equal(nil, get_unit(uno))
free_game()
end end
function test_gmtool() function test_gmtool()
free_game()
local r1 = region.create(1, 0, "plain") local r1 = region.create(1, 0, "plain")
local r2 = region.create(1, 1, "plain") local r2 = region.create(1, 1, "plain")
local r3 = region.create(1, 2, "plain") local r3 = region.create(1, 2, "plain")
@ -147,7 +143,6 @@ function test_gmtool()
end end
function test_faction() function test_faction()
free_game()
local r = region.create(0, 0, "plain") local r = region.create(0, 0, "plain")
local f = faction.create("noreply@eressea.de", "human", "de") local f = faction.create("noreply@eressea.de", "human", "de")
assert(f) assert(f)
@ -171,7 +166,6 @@ function test_faction()
end end
function test_unit() function test_unit()
free_game()
local r = region.create(0, 0, "plain") local r = region.create(0, 0, "plain")
local f = faction.create("noreply@eressea.de", "human", "de") local f = faction.create("noreply@eressea.de", "human", "de")
local u = unit.create(f, r) local u = unit.create(f, r)
@ -188,7 +182,6 @@ function test_unit()
end end
function test_region() function test_region()
free_game()
local r = region.create(0, 0, "plain") local r = region.create(0, 0, "plain")
r:set_resource("horse", 42) r:set_resource("horse", 42)
r:set_resource("money", 45) r:set_resource("money", 45)
@ -206,7 +199,6 @@ function test_region()
end end
function test_building() function test_building()
free_game()
local u local u
local f = faction.create("noreply@eressea.de", "human", "de") local f = faction.create("noreply@eressea.de", "human", "de")
local r = region.create(0, 0, "plain") local r = region.create(0, 0, "plain")
@ -233,7 +225,6 @@ function test_building()
end end
function test_message() function test_message()
free_game()
local r = region.create(0, 0, "plain") local r = region.create(0, 0, "plain")
local f = faction.create("noreply@eressea.de", "human", "de") local f = faction.create("noreply@eressea.de", "human", "de")
local u = unit.create(f, r) local u = unit.create(f, r)
@ -248,7 +239,6 @@ function test_message()
end end
function test_hashtable() function test_hashtable()
free_game()
local f = faction.create("noreply@eressea.de", "human", "de") local f = faction.create("noreply@eressea.de", "human", "de")
f.objects:set("enno", "smart guy") f.objects:set("enno", "smart guy")
f.objects:set("age", 10) f.objects:set("age", 10)
@ -299,7 +289,6 @@ function test_events()
end end
function test_recruit2() function test_recruit2()
free_game()
local r = region.create(0, 0, "plain") local r = region.create(0, 0, "plain")
local f = faction.create("noreply@eressea.de", "human", "de") local f = faction.create("noreply@eressea.de", "human", "de")
local u = unit.create(f, r) local u = unit.create(f, r)
@ -314,7 +303,6 @@ function test_recruit2()
end end
function test_guard() function test_guard()
free_game()
region.create(1, 0, "plain") region.create(1, 0, "plain")
local r = region.create(0, 0, "plain") local r = region.create(0, 0, "plain")
local f1 = faction.create("noreply@eressea.de", "human", "de") local f1 = faction.create("noreply@eressea.de", "human", "de")
@ -343,7 +331,6 @@ function test_guard()
end end
function test_recruit() function test_recruit()
free_game()
local r = region.create(0, 0, "plain") local r = region.create(0, 0, "plain")
local f = faction.create("noreply@eressea.de", "human", "de") local f = faction.create("noreply@eressea.de", "human", "de")
local u = unit.create(f, r) local u = unit.create(f, r)
@ -361,7 +348,6 @@ function test_recruit()
end end
function test_produce() function test_produce()
free_game()
local r = region.create(0, 0, "plain") local r = region.create(0, 0, "plain")
local f = faction.create("noreply@eressea.de", "human", "de") local f = faction.create("noreply@eressea.de", "human", "de")
local u = unit.create(f, r, 1) local u = unit.create(f, r, 1)
@ -376,7 +362,6 @@ function test_produce()
end end
function test_work() function test_work()
free_game()
local r = region.create(0, 0, "plain") local r = region.create(0, 0, "plain")
local f = faction.create("noreply@eressea.de", "human", "de") local f = faction.create("noreply@eressea.de", "human", "de")
local u = unit.create(f, r, 1) local u = unit.create(f, r, 1)
@ -389,7 +374,7 @@ function test_work()
end end
function test_upkeep() function test_upkeep()
free_game() settings.set("rules.economy.food", "0")
local r = region.create(0, 0, "plain") local r = region.create(0, 0, "plain")
local f = faction.create("noreply@eressea.de", "human", "de") local f = faction.create("noreply@eressea.de", "human", "de")
local u = unit.create(f, r, 5) local u = unit.create(f, r, 5)
@ -401,7 +386,6 @@ function test_upkeep()
end end
function test_id() function test_id()
free_game()
local r = region.create(0, 0, "plain") local r = region.create(0, 0, "plain")
local f = faction.create("noreply@eressea.de", "human", "de") local f = faction.create("noreply@eressea.de", "human", "de")
@ -430,7 +414,6 @@ function test_id()
end end
function test_herbalism() function test_herbalism()
free_game()
local r = region.create(0, 0, "plain") local r = region.create(0, 0, "plain")
local f = faction.create("noreply@eressea.de", "human", "de") local f = faction.create("noreply@eressea.de", "human", "de")
local u = unit.create(f, r, 1) local u = unit.create(f, r, 1)
@ -442,7 +425,6 @@ function test_herbalism()
end end
function test_mallorn() function test_mallorn()
free_game()
local r = region.create(0, 0, "plain") local r = region.create(0, 0, "plain")
r:set_flag(1, false) -- not mallorn r:set_flag(1, false) -- not mallorn
r:set_resource("tree", 100) r:set_resource("tree", 100)
@ -512,7 +494,6 @@ function test_coordinate_translation()
end end
function test_control() function test_control()
free_game()
local u1, u2 = two_units(region.create(0, 0, "plain"), two_factions()) local u1, u2 = two_units(region.create(0, 0, "plain"), two_factions())
local r = u1.region local r = u1.region
local b = building.create(r, "castle") local b = building.create(r, "castle")
@ -527,7 +508,6 @@ function test_control()
end end
function test_store_unit() function test_store_unit()
free_game()
local r = region.create(0, 0, "plain") local r = region.create(0, 0, "plain")
local f = faction.create("noreply@eressea.de", "human", "de") local f = faction.create("noreply@eressea.de", "human", "de")
local u = unit.create(f, r, 1) local u = unit.create(f, r, 1)
@ -686,8 +666,6 @@ function test_swim_and_survive()
local f = faction.create("noreply@eressea.de", "human", "de") local f = faction.create("noreply@eressea.de", "human", "de")
f.nam = "chaos" f.nam = "chaos"
local u = unit.create(f, r, 1) local u = unit.create(f, r, 1)
f.age = 20
u:add_item("money", 100)
process_orders() process_orders()
r.terrain = "ocean" r.terrain = "ocean"
local s = _test_create_ship(r) local s = _test_create_ship(r)
@ -702,7 +680,6 @@ function test_swim_and_die()
local f = faction.create("noreply@eressea.de", "human", "de") local f = faction.create("noreply@eressea.de", "human", "de")
local u = unit.create(f, r, 1) local u = unit.create(f, r, 1)
local uid = u.id local uid = u.id
u:add_item("money", 100)
process_orders() process_orders()
r.terrain = "ocean" r.terrain = "ocean"
u = get_unit(uid) u = get_unit(uid)
@ -710,3 +687,75 @@ function test_swim_and_die()
process_orders() process_orders()
assert_equal(get_unit(uid), nil) assert_equal(get_unit(uid), nil)
end end
function test_ride_with_horse()
region.create(1, 0, "plain")
region.create(2, 0, "plain")
local r = region.create(0, 0, "plain")
local f = faction.create("noreply@eressea.de", "human", "de")
local u = unit.create(f, r, 1)
u:add_item("horse", 1)
u:add_item("sword", 10)
u:set_skill("riding", 2)
u:clear_orders()
u:add_order("NACH O O")
process_orders()
assert_equal(u.region.x, 2)
u:add_item("sword", 1)
u:clear_orders()
u:add_order("NACH W W")
process_orders()
assert_equal(u.region.x, 1)
end
function test_ride_with_horses_and_cart()
region.create(1, 0, "plain")
region.create(2, 0, "plain")
local r = region.create(0, 0, "plain")
local f = faction.create("noreply@eressea.de", "human", "de")
local u = unit.create(f, r, 1)
u:add_item("cart", 1)
u:add_item("horse", 2)
u:add_item("sword", 120)
u:set_skill("riding", 3)
-- ride
u:clear_orders()
u:add_order("NACH O O")
process_orders()
assert_equal(2, u.region.x)
-- walk
u:add_item("sword", 20)
r:get_key("eviL")
u:clear_orders()
u:add_order("NACH W W")
process_orders()
assert_equal(1, u.region.x)
-- too heavy
u:add_item("sword", 10)
r:get_key("eviL")
u:clear_orders()
u:add_order("NACH W W")
process_orders()
assert_equal(1, u.region.x)
end
function test_walk_and_carry_the_cart()
region.create(1, 0, "plain")
local r = region.create(2, 0, "plain")
local r = region.create(0, 0, "plain")
local f = faction.create("noreply@eressea.de", "human", "de")
local u = unit.create(f, r, 10)
u:add_item("cart", 1)
-- walk
u:clear_orders()
u:add_order("NACH O O")
process_orders()
assert_equal(1, u.region.x)
end