forked from github/server
additional testing for production rules.
This commit is contained in:
parent
dcf1c7138b
commit
bd40de1142
|
@ -0,0 +1,115 @@
|
|||
require "lunit"
|
||||
|
||||
module("tests.e2.items", package.seeall, lunit.testcase )
|
||||
|
||||
function setup()
|
||||
eressea.free_game()
|
||||
eressea.settings.set("nmr.timeout", "0")
|
||||
eressea.settings.set("rules.food.flags", "4")
|
||||
eressea.settings.set("rules.ship.storms", "0")
|
||||
eressea.settings.set("rules.encounters", "0")
|
||||
eressea.settings.set("magic.regeneration.enable", "0")
|
||||
end
|
||||
|
||||
function test_meow()
|
||||
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("aoc", 1)
|
||||
u:clear_orders()
|
||||
u:add_order("BENUTZEN 1 Katzenamulett")
|
||||
turn_begin()
|
||||
turn_process()
|
||||
assert_equal(1, u:get_item("aoc"))
|
||||
assert_equal(1, r:count_msg_type('meow'))
|
||||
turn_end()
|
||||
end
|
||||
|
||||
function test_aurapotion50()
|
||||
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("aurapotion50", 1)
|
||||
u:set_skill('magic', 10);
|
||||
u.magic = 'gwyrrd'
|
||||
u.aura = 0
|
||||
u:clear_orders()
|
||||
u:add_order("BENUTZEN 1 Auratrank")
|
||||
turn_begin()
|
||||
turn_process()
|
||||
assert_equal(0, u:get_item("aurapotion50"))
|
||||
assert_equal(1, f:count_msg_type('aurapotion50'))
|
||||
assert_equal(50, u.aura)
|
||||
turn_end()
|
||||
end
|
||||
|
||||
function test_bagpipe()
|
||||
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("bagpipeoffear", 1)
|
||||
u:clear_orders()
|
||||
u:add_order("BENUTZEN 1 Dudelsack")
|
||||
process_orders()
|
||||
assert_equal(1, u:get_item("bagpipeoffear"))
|
||||
assert_equal(1, f:count_msg_type('bagpipeoffear_faction'))
|
||||
assert_equal(1, r:count_msg_type('bagpipeoffear_region'))
|
||||
end
|
||||
|
||||
function test_speedsail()
|
||||
local r = region.create(0, 0, "plain")
|
||||
local f = faction.create("noreply@eressea.de", "human", "de")
|
||||
local u = unit.create(f, r, 1)
|
||||
u.ship = ship.create(r, "boat")
|
||||
u:add_item("speedsail", 2)
|
||||
u:clear_orders()
|
||||
u:add_order("BENUTZEN 1 Sonnensegel")
|
||||
process_orders()
|
||||
assert_equal(1, u:get_item("speedsail"))
|
||||
assert_equal(1, f:count_msg_type('use_speedsail'))
|
||||
end
|
||||
|
||||
function test_foolpotion()
|
||||
local r = region.create(0, 0, "plain")
|
||||
local f = faction.create("noreply@eressea.de", "human", "de")
|
||||
local u = unit.create(f, r, 1)
|
||||
turn_begin()
|
||||
u:add_item("p7", 1)
|
||||
u:clear_orders()
|
||||
u:add_order("BENUTZEN 1 Dumpfbackenbrot 4242")
|
||||
turn_process()
|
||||
assert_equal(1, u:get_item("p7"))
|
||||
assert_equal(1, f:count_msg_type('feedback_unit_not_found'))
|
||||
local u2 = unit.create(f, r, 1)
|
||||
|
||||
u:clear_orders()
|
||||
u:add_order("BENUTZEN 1 Dumpfbackenbrot " .. itoa36(u2.id))
|
||||
turn_process()
|
||||
assert_equal(1, u:get_item("p7"))
|
||||
assert_equal(1, f:count_msg_type('error64'))
|
||||
|
||||
u:set_skill("stealth", 1);
|
||||
turn_process()
|
||||
assert_equal(0, u:get_item("p7"))
|
||||
assert_equal(1, f:count_msg_type('givedumb'))
|
||||
turn_end()
|
||||
end
|
||||
|
||||
function test_snowman()
|
||||
local r = region.create(0, 0, "glacier")
|
||||
local f = faction.create("noreply@eressea.de", "human", "de")
|
||||
local u = unit.create(f, r, 1)
|
||||
u:add_item("snowman", 1)
|
||||
u:clear_orders()
|
||||
u:add_order("BENUTZEN 1 Schneemann")
|
||||
process_orders()
|
||||
for u2 in r.units do
|
||||
if u2.id~=u.id then
|
||||
assert_equal("snowman", u2.race)
|
||||
assert_equal(1000, u2.hp)
|
||||
u = nil
|
||||
break
|
||||
end
|
||||
end
|
||||
assert_equal(nil, u)
|
||||
end
|
|
@ -1,3 +1,4 @@
|
|||
require 'tests.e3.production'
|
||||
require 'tests.e3.castles'
|
||||
require 'tests.e3.stealth'
|
||||
require 'tests.e3.spells'
|
||||
|
|
|
@ -0,0 +1,179 @@
|
|||
require "lunit"
|
||||
|
||||
module("tests.e3.production", package.seeall, lunit.testcase )
|
||||
|
||||
function setup()
|
||||
eressea.game.reset()
|
||||
eressea.settings.set("rules.food.flags", "4") -- food is free
|
||||
eressea.settings.set("NewbieImmunity", "0")
|
||||
end
|
||||
|
||||
local function create_faction(race)
|
||||
return faction.create(race .. '@eressea.de', race, "de")
|
||||
end
|
||||
|
||||
function test_laen_needs_mine()
|
||||
-- some resources require a building
|
||||
-- i.e. you cannot create laen without a mine
|
||||
local r = region.create(0, 0, "mountain")
|
||||
local f = create_faction('human')
|
||||
local u = unit.create(f, r, 1)
|
||||
|
||||
turn_begin()
|
||||
r:set_resource('laen', 100)
|
||||
u:add_order("MACHE Laen")
|
||||
u:set_skill('mining', 7)
|
||||
turn_process()
|
||||
assert_equal(0, u:get_item('laen'))
|
||||
assert_equal(100, r:get_resource('laen'))
|
||||
assert_equal(1, f:count_msg_type("error104")) -- requires building
|
||||
|
||||
u.building = building.create(u.region, "mine")
|
||||
u.building.working = true
|
||||
u.building.size = 10
|
||||
turn_process()
|
||||
assert_equal(1, u:get_item('laen'))
|
||||
assert_equal(99, r:get_resource('laen'))
|
||||
|
||||
turn_end()
|
||||
end
|
||||
|
||||
function bad_test_mine_laen_bonus()
|
||||
-- some buildings grant a bonus on the production skill
|
||||
-- i.e. a mine adds +1 to mining
|
||||
local r = region.create(0, 0, 'mountain')
|
||||
local f = create_faction('human')
|
||||
local u = unit.create(f, r, 1)
|
||||
|
||||
turn_begin()
|
||||
r:set_resource('laen', 100)
|
||||
assert_equal(100, r:get_resource('laen'))
|
||||
u:add_order("MACHE Laen")
|
||||
u:set_skill('mining', 6)
|
||||
u.building = building.create(u.region, "mine")
|
||||
u.building.working = true
|
||||
u.building.size = 10
|
||||
u.number = 2
|
||||
turn_process() -- T6 is not enough for laen
|
||||
assert_equal(0, u:get_item('laen'))
|
||||
assert_equal(100, r:get_resource('laen'))
|
||||
assert_equal(1, f:count_msg_type("manufacture_skills"))
|
||||
|
||||
u:set_skill('mining', 13)
|
||||
turn_process() -- T13 is enough, the +1 produces one extra Laen
|
||||
assert_equal(4, u:get_item('laen')) -- FAIL (3)
|
||||
assert_equal(96, r:get_resource('laen'))
|
||||
|
||||
turn_end()
|
||||
end
|
||||
|
||||
function test_mine_iron_bonus()
|
||||
-- some buildings grant a bonus on the production skill
|
||||
-- i.e. a mine adds +1 to mining iron
|
||||
--
|
||||
local r = region.create(0, 0, 'mountain')
|
||||
local f = create_faction('human')
|
||||
local u = unit.create(f, r, 1)
|
||||
|
||||
turn_begin()
|
||||
r:set_resource('iron', 100)
|
||||
assert_equal(100, r:get_resource('iron'))
|
||||
u:add_order("MACHE Eisen")
|
||||
u:set_skill('mining', 1)
|
||||
u.building = building.create(u.region, "mine")
|
||||
u.building.working = false
|
||||
u.building.size = 10
|
||||
u.number = 2
|
||||
turn_process() -- iron can be made without a working mine
|
||||
assert_equal(2, u:get_item('iron'))
|
||||
assert_equal(98, r:get_resource('iron'))
|
||||
|
||||
u.building.working = true
|
||||
turn_process()
|
||||
assert_equal(6, u:get_item('iron'))
|
||||
assert_equal(96, r:get_resource('iron'))
|
||||
|
||||
turn_end()
|
||||
end
|
||||
|
||||
function test_quarry_bonus()
|
||||
-- a quarry grants +1 to quarrying, and saves 50% stone
|
||||
--
|
||||
local r = region.create(0, 0, 'mountain')
|
||||
local f = create_faction('human')
|
||||
local u = unit.create(f, r, 1)
|
||||
|
||||
turn_begin()
|
||||
r:set_resource('stone', 100)
|
||||
assert_equal(100, r:get_resource('stone'))
|
||||
u:add_order("MACHE Stein")
|
||||
u:set_skill('quarrying', 1)
|
||||
u.number = 2
|
||||
u.building = building.create(u.region, 'quarry')
|
||||
u.building.working = false
|
||||
u.building.size = 10
|
||||
turn_process()
|
||||
assert_equal(2, u:get_item('stone'))
|
||||
assert_equal(98, r:get_resource('stone'))
|
||||
|
||||
u.building.working = true
|
||||
turn_process()
|
||||
assert_equal(6, u:get_item('stone'))
|
||||
assert_equal(96, r:get_resource('stone'))
|
||||
|
||||
turn_end()
|
||||
end
|
||||
|
||||
function test_smithy_bonus_iron()
|
||||
-- a smithy adds +1 to weaponsmithing, and saves 50% iron
|
||||
local r = region.create(0, 0, 'mountain')
|
||||
local f = create_faction('human')
|
||||
local u = unit.create(f, r, 1)
|
||||
|
||||
turn_begin()
|
||||
u.building = building.create(u.region, 'smithy')
|
||||
u.building.working = false
|
||||
u.building.size = 10
|
||||
u:set_skill('weaponsmithing', 5) -- needs 3
|
||||
u:add_item('iron', 100)
|
||||
u:add_order("MACHE Schwert")
|
||||
turn_process() -- building disabled
|
||||
assert_equal(1, u:get_item('sword'))
|
||||
assert_equal(99, u:get_item('iron'))
|
||||
|
||||
u.building.working = true
|
||||
turn_process() -- building active
|
||||
assert_equal(3, u:get_item('sword'))
|
||||
assert_equal(98, u:get_item('iron'))
|
||||
|
||||
turn_end()
|
||||
end
|
||||
|
||||
function test_smithy_bonus_mixed()
|
||||
-- a smithy adds +1 to weaponsmithing, and saves 50% iron
|
||||
-- it does not save any other resource, though.
|
||||
local r = region.create(0, 0, 'mountain')
|
||||
local f = create_faction('human')
|
||||
local u = unit.create(f, r, 1)
|
||||
|
||||
turn_begin()
|
||||
u.building = building.create(u.region, 'smithy')
|
||||
u.building.working = false
|
||||
u.building.size = 10
|
||||
u:set_skill('weaponsmithing', 5) -- needs 3
|
||||
u:add_item('iron', 100)
|
||||
u:add_item('log', 100)
|
||||
u:add_order("MACHE Kriegsaxt")
|
||||
turn_process() -- building disabled
|
||||
assert_equal(1, u:get_item('axe'))
|
||||
assert_equal(99, u:get_item('iron'))
|
||||
assert_equal(99, u:get_item('log'))
|
||||
|
||||
u.building.working = true
|
||||
turn_process() -- building active
|
||||
assert_equal(3, u:get_item('axe'))
|
||||
assert_equal(98, u:get_item('iron'))
|
||||
assert_equal(97, u:get_item('log'))
|
||||
|
||||
turn_end()
|
||||
end
|
|
@ -0,0 +1,140 @@
|
|||
require "lunit"
|
||||
|
||||
module("tests.items", package.seeall, lunit.testcase )
|
||||
|
||||
function setup()
|
||||
eressea.free_game()
|
||||
eressea.settings.set("nmr.timeout", "0")
|
||||
eressea.settings.set("rules.food.flags", "4")
|
||||
eressea.settings.set("rules.ship.storms", "0")
|
||||
eressea.settings.set("rules.encounters", "0")
|
||||
eressea.settings.set("magic.regeneration.enable", "0")
|
||||
end
|
||||
|
||||
function test_mistletoe()
|
||||
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('mistletoe', 2)
|
||||
u:clear_orders()
|
||||
u:add_order("BENUTZEN 1 Mistelzweig")
|
||||
process_orders()
|
||||
assert_equal(1, u:get_item('mistletoe'))
|
||||
assert_equal(1, f:count_msg_type('use_item'))
|
||||
u.number = 2
|
||||
process_orders()
|
||||
assert_equal(1, u:get_item('mistletoe'))
|
||||
assert_equal(1, f:count_msg_type('use_singleperson'))
|
||||
end
|
||||
|
||||
function test_dreameye()
|
||||
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("dreameye", 2)
|
||||
u:clear_orders()
|
||||
u:add_order("BENUTZEN 1 Traumauge")
|
||||
assert_false(u:is_cursed('skillmod'))
|
||||
turn_begin()
|
||||
turn_process()
|
||||
assert_true(u:is_cursed('skillmod'))
|
||||
assert_equal(1, u:get_item("dreameye"))
|
||||
assert_equal(1, f:count_msg_type('use_tacticcrystal'))
|
||||
turn_end()
|
||||
assert_false(u:is_cursed('skillmod'))
|
||||
end
|
||||
|
||||
function test_manacrystal()
|
||||
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("manacrystal", 2)
|
||||
u:clear_orders()
|
||||
u.magic = "gwyrrd"
|
||||
u:set_skill('magic', 1)
|
||||
u.aura = 0
|
||||
u:add_order("BENUTZEN 1 Astralkristall")
|
||||
turn_begin()
|
||||
turn_process()
|
||||
assert_equal(1, u:get_item("manacrystal"))
|
||||
assert_equal(25, u.aura)
|
||||
assert_equal(1, f:count_msg_type('manacrystal_use'))
|
||||
turn_end()
|
||||
end
|
||||
|
||||
function test_skillpotion()
|
||||
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("skillpotion", 2)
|
||||
u:clear_orders()
|
||||
u:add_order("BENUTZEN 1 Talenttrunk")
|
||||
process_orders()
|
||||
assert_equal(1, u:get_item("skillpotion"))
|
||||
assert_equal(1, f:count_msg_type('skillpotion_use'))
|
||||
end
|
||||
|
||||
function test_studypotion()
|
||||
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("studypotion", 2)
|
||||
u:clear_orders()
|
||||
u:add_order("LERNE Unterhaltung")
|
||||
u:add_order("BENUTZEN 1 Lerntrank")
|
||||
process_orders()
|
||||
assert_equal(1, u:get_item("studypotion"))
|
||||
end
|
||||
|
||||
function test_antimagic()
|
||||
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("antimagic", 2)
|
||||
u:clear_orders()
|
||||
u:add_order("BENUTZEN 1 Antimagiekristall")
|
||||
process_orders()
|
||||
assert_equal(1, r:count_msg_type('use_antimagiccrystal'))
|
||||
assert_equal(1, u:get_item("antimagic"))
|
||||
end
|
||||
|
||||
function test_ointment()
|
||||
local r = region.create(0, 0, "plain")
|
||||
local f = faction.create("noreply@eressea.de", "human", "de")
|
||||
local u = unit.create(f, r, 1)
|
||||
local hp = u.hp
|
||||
u.hp = 1
|
||||
u:add_item("ointment", 1)
|
||||
u:clear_orders()
|
||||
u:add_order("BENUTZEN 1 Wundsalbe")
|
||||
process_orders()
|
||||
assert_equal(0, u:get_item("ointment"))
|
||||
assert_equal(1, f:count_msg_type('usepotion'))
|
||||
assert_equal(hp, u.hp)
|
||||
end
|
||||
|
||||
function test_bloodpotion_demon()
|
||||
local r = region.create(0, 0, "plain")
|
||||
local f = faction.create("noreply@eressea.de", "demon", "de")
|
||||
local u = unit.create(f, r, 1)
|
||||
u:add_item("peasantblood", 1)
|
||||
u:clear_orders()
|
||||
u:add_order("BENUTZEN 1 Bauernblut")
|
||||
process_orders()
|
||||
assert_equal(0, u:get_item("peasantblood"))
|
||||
assert_equal(1, f:count_msg_type('usepotion'))
|
||||
assert_equal("demon", u.race)
|
||||
end
|
||||
|
||||
function test_bloodpotion_other()
|
||||
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("peasantblood", 1)
|
||||
u:clear_orders()
|
||||
u:add_order("BENUTZEN 1 Bauernblut")
|
||||
process_orders()
|
||||
assert_equal(0, u:get_item("peasantblood"))
|
||||
assert_equal(1, f:count_msg_type('usepotion'))
|
||||
assert_equal("smurf", u.race)
|
||||
end
|
Loading…
Reference in New Issue