forked from github/server
Eressea tests, rewritten
This commit is contained in:
parent
7d9442d360
commit
9cb0deb4f9
|
@ -0,0 +1,53 @@
|
|||
require "lunit"
|
||||
|
||||
module("tests.eressea.attrib", package.seeall, lunit.testcase)
|
||||
|
||||
function has_attrib(u, value)
|
||||
for a in u.attribs do
|
||||
if (a.data==value) then return true end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
function test_attrib_global()
|
||||
a = attrib.create('global', {})
|
||||
eressea.write_game('attrib.dat')
|
||||
eressea.free_game()
|
||||
eressea.read_game('attrib.dat')
|
||||
end
|
||||
|
||||
function test_attrib()
|
||||
local r = region.create(0,0, "plain")
|
||||
local f = faction.create("noreply@eressea.de", "human", "de")
|
||||
local u = unit.create(f, r, 1)
|
||||
local u2 = unit.create(f, r, 1)
|
||||
data = { arr = { 'a', 'b', 'c' }, name = 'familiar', events = { die = 'familiar_died' }, data = { mage = u2 } }
|
||||
a = { 'a' }
|
||||
b = { 'a' }
|
||||
uno = u.id
|
||||
u2no = u2.id
|
||||
a = attrib.create(u, 12)
|
||||
a = attrib.create(u, "enno")
|
||||
a = attrib.create(u, u2)
|
||||
a = attrib.create(u, data)
|
||||
eressea.write_game("attrib.dat")
|
||||
eressea.free_game()
|
||||
eressea.read_game("attrib.dat")
|
||||
u = get_unit(uno)
|
||||
u2 = get_unit(u2no)
|
||||
assert_false(has_attrib(u, 42))
|
||||
assert_true(has_attrib(u, "enno"))
|
||||
assert_true(has_attrib(u, 12))
|
||||
|
||||
for a in u.attribs do
|
||||
x = a.data
|
||||
if (type(x)=="table") then
|
||||
assert_equal('a', x.arr[1])
|
||||
assert_equal('familiar', x.name)
|
||||
assert_equal('familiar_died', x.events.die)
|
||||
assert_equal(u2, x.data.mage)
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,61 @@
|
|||
require "lunit"
|
||||
|
||||
local eressea = eressea
|
||||
local _G = _G
|
||||
|
||||
module("tests.bindings", lunit.testcase)
|
||||
|
||||
function test_eressea()
|
||||
assert_equal("function", _G.type(eressea.free_game))
|
||||
assert_equal("function", _G.type(eressea.read_game))
|
||||
assert_equal("function", _G.type(eressea.write_game))
|
||||
assert_equal("function", _G.type(eressea.read_orders))
|
||||
end
|
||||
|
||||
function test_process()
|
||||
assert_equal("function", _G.type(eressea.process.update_long_order))
|
||||
assert_equal("function", _G.type(eressea.process.markets))
|
||||
assert_equal("function", _G.type(eressea.process.produce))
|
||||
|
||||
assert_equal("function", _G.type(eressea.process.make_temp))
|
||||
assert_equal("function", _G.type(eressea.process.settings))
|
||||
assert_equal("function", _G.type(eressea.process.set_allies))
|
||||
assert_equal("function", _G.type(eressea.process.set_prefix))
|
||||
assert_equal("function", _G.type(eressea.process.set_stealth))
|
||||
assert_equal("function", _G.type(eressea.process.set_status))
|
||||
assert_equal("function", _G.type(eressea.process.set_name))
|
||||
assert_equal("function", _G.type(eressea.process.set_group))
|
||||
assert_equal("function", _G.type(eressea.process.set_origin))
|
||||
assert_equal("function", _G.type(eressea.process.quit))
|
||||
assert_equal("function", _G.type(eressea.process.study))
|
||||
assert_equal("function", _G.type(eressea.process.movement))
|
||||
assert_equal("function", _G.type(eressea.process.use))
|
||||
assert_equal("function", _G.type(eressea.process.battle))
|
||||
assert_equal("function", _G.type(eressea.process.siege))
|
||||
assert_equal("function", _G.type(eressea.process.leave))
|
||||
assert_equal("function", _G.type(eressea.process.promote))
|
||||
assert_equal("function", _G.type(eressea.process.renumber))
|
||||
assert_equal("function", _G.type(eressea.process.restack))
|
||||
assert_equal("function", _G.type(eressea.process.set_spells))
|
||||
assert_equal("function", _G.type(eressea.process.set_help))
|
||||
assert_equal("function", _G.type(eressea.process.contact))
|
||||
assert_equal("function", _G.type(eressea.process.enter))
|
||||
assert_equal("function", _G.type(eressea.process.magic))
|
||||
assert_equal("function", _G.type(eressea.process.give_control))
|
||||
assert_equal("function", _G.type(eressea.process.regeneration))
|
||||
assert_equal("function", _G.type(eressea.process.guard_on))
|
||||
assert_equal("function", _G.type(eressea.process.guard_off))
|
||||
assert_equal("function", _G.type(eressea.process.explain))
|
||||
assert_equal("function", _G.type(eressea.process.messages))
|
||||
assert_equal("function", _G.type(eressea.process.reserve))
|
||||
assert_equal("function", _G.type(eressea.process.claim))
|
||||
assert_equal("function", _G.type(eressea.process.follow))
|
||||
assert_equal("function", _G.type(eressea.process.alliance))
|
||||
assert_equal("function", _G.type(eressea.process.idle))
|
||||
assert_equal("function", _G.type(eressea.process.set_default))
|
||||
end
|
||||
|
||||
function test_settings()
|
||||
assert_equal("function", _G.type(eressea.settings.set))
|
||||
assert_equal("function", _G.type(eressea.settings.get))
|
||||
end
|
|
@ -0,0 +1,65 @@
|
|||
require "lunit"
|
||||
|
||||
module("tests.eressea.bson", package.seeall, lunit.testcase)
|
||||
|
||||
function setup()
|
||||
eressea.free_game()
|
||||
end
|
||||
|
||||
function test_bson_create()
|
||||
local a = attrib.create("global", 12)
|
||||
assert_not_equal(nil, a)
|
||||
for a in attrib.get("global") do
|
||||
assert_equal(a.data, 12)
|
||||
end
|
||||
end
|
||||
|
||||
function test_illegal_arg()
|
||||
local a = attrib.create(nil, 42)
|
||||
assert_equal(nil, a)
|
||||
a = attrib.create("fred", 42)
|
||||
assert_equal(nil, a)
|
||||
end
|
||||
|
||||
function test_bson_readwrite()
|
||||
local i, r = region.create(0, 0, "mountain")
|
||||
attrib.create(r, 42)
|
||||
i = eressea.write_game("test_read_write.dat")
|
||||
assert_equal(0, i)
|
||||
eressea.free_game()
|
||||
r = get_region(0, 0)
|
||||
assert_equal(nil, r)
|
||||
i = eressea.read_game("test_read_write.dat")
|
||||
assert_equal(0, i)
|
||||
r = get_region(0, 0)
|
||||
assert_not_equal(nil, r)
|
||||
for a in attrib.get(r) do
|
||||
assert_equal(a.data, 42)
|
||||
end
|
||||
end
|
||||
|
||||
function test_bson()
|
||||
local r = region.create(0, 0, "mountain")
|
||||
local f = faction.create("noreply@eressea.de", "human", "de")
|
||||
local u = unit.create(f, r, 1)
|
||||
assert_not_equal(nil, u)
|
||||
assert_not_equal(nil, r)
|
||||
assert_not_equal(nil, f)
|
||||
attrib.create(r, 1)
|
||||
assert_equal(attrib.get(r)().data, 1)
|
||||
attrib.create(u, 3)
|
||||
assert_equal(attrib.get(u)().data, 3)
|
||||
attrib.create(f, 5)
|
||||
assert_equal(attrib.get(f)().data, 5)
|
||||
end
|
||||
|
||||
function test_bson_with_multiple_attribs()
|
||||
local r = region.create(0, 0, "mountain")
|
||||
attrib.create(r, { a=1})
|
||||
attrib.create(r, { a=5})
|
||||
local total = 0
|
||||
for a in attrib.get(r) do
|
||||
total = total + a.data.a;
|
||||
end
|
||||
assert_equal(6, total)
|
||||
end
|
|
@ -0,0 +1,27 @@
|
|||
require "lunit"
|
||||
|
||||
module('tests.eressea.castles', package.seeall, lunit.testcase )
|
||||
|
||||
function setup()
|
||||
eressea.free_game()
|
||||
end
|
||||
|
||||
function test_small_castles()
|
||||
local r = region.create(0, 0, "plain")
|
||||
local f1 = faction.create("noreply@eressea.de", "human", "de")
|
||||
local u1 = unit.create(f1, r, 1)
|
||||
local f2 = faction.create("noreply@eressea.de", "halfling", "de")
|
||||
local u2 = unit.create(f2, r, 1)
|
||||
u1:add_item("money", 10000)
|
||||
|
||||
local b = building.create(r, "castle")
|
||||
u2.building = b
|
||||
u1.building = b
|
||||
|
||||
b.owner = u2
|
||||
assert_equal("site", b:get_typename(7))
|
||||
assert_equal("fortification", b:get_typename(8))
|
||||
b.owner = u1
|
||||
assert_equal("site", b:get_typename(9))
|
||||
assert_equal("fortification", b:get_typename(10))
|
||||
end
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,39 @@
|
|||
require "lunit"
|
||||
|
||||
module("tests.eressea.config", package.seeall, lunit.testcase )
|
||||
|
||||
function setup()
|
||||
eressea.free_game()
|
||||
end
|
||||
|
||||
function test_read_race()
|
||||
local f
|
||||
eressea.free_game()
|
||||
f = faction.create("orc@example.com", "orc", "en")
|
||||
assert_equal(nil, f)
|
||||
assert_not_nil(eressea.config)
|
||||
eressea.config.parse('{ "races": { "orc" : {}}}')
|
||||
f = faction.create("orc@example.com", "orc", "en")
|
||||
assert_not_nil(f)
|
||||
end
|
||||
|
||||
function test_read_ship()
|
||||
local s
|
||||
eressea.free_game()
|
||||
s = ship.create(nil, "boat")
|
||||
assert_equal(nil, s)
|
||||
assert_not_nil(eressea.config)
|
||||
conf = [[{
|
||||
"ships": {
|
||||
"boat" : {
|
||||
"construction" : {
|
||||
"maxsize" : 20
|
||||
}
|
||||
}
|
||||
}
|
||||
}]]
|
||||
eressea.config.parse(conf);
|
||||
s = ship.create(nil, "boat")
|
||||
assert_not_nil(s)
|
||||
end
|
||||
|
|
@ -0,0 +1,735 @@
|
|||
require "lunit"
|
||||
|
||||
module("tests.e3.e3features", package.seeall, lunit.testcase)
|
||||
|
||||
function setup()
|
||||
eressea.free_game()
|
||||
eressea.settings.set("rules.economy.food", "4")
|
||||
end
|
||||
|
||||
function test_no_stealth()
|
||||
local r = region.create(0,0, "plain")
|
||||
local f = faction.create("noreply@eressea.de", "human", "de")
|
||||
local u = unit.create(f, r, 1)
|
||||
|
||||
u:set_skill("stealth", 1)
|
||||
assert_equal(-1, u:get_skill("stealth"))
|
||||
u:clear_orders()
|
||||
u:add_order("LERNEN TARNUNG")
|
||||
process_orders()
|
||||
assert_equal(-1, u:get_skill("stealth"))
|
||||
end
|
||||
|
||||
--[[
|
||||
function test_analyze_magic()
|
||||
local r1 = region.create(0,0, "plain")
|
||||
local r2 = region.create(1,0, "plain")
|
||||
local f = faction.create("noreply@eressea.de", "human", "de")
|
||||
|
||||
local u = unit.create(f, r2, 1)
|
||||
|
||||
u.race = "elf"
|
||||
u:set_skill("magic", 6)
|
||||
u.magic = "gwyrrd"
|
||||
u.aura = 60
|
||||
u:add_spell("analyze_magic")
|
||||
u:clear_orders()
|
||||
u:add_order("Zaubere stufe 2 'Magie analysieren' REGION 1,0")
|
||||
process_orders()
|
||||
end
|
||||
]]--
|
||||
|
||||
function test_seecast()
|
||||
local r = region.create(0,0, "plain")
|
||||
for i = 1,10 do
|
||||
-- this prevents storms (only high seas have storms)
|
||||
region.create(i, 1, "plain")
|
||||
end
|
||||
for i = 1,10 do
|
||||
region.create(i, 0, "ocean")
|
||||
end
|
||||
local f = faction.create("noreply@eressea.de", "human", "de")
|
||||
local s1 = ship.create(r, "cutter")
|
||||
local u1 = unit.create(f, r, 2)
|
||||
u1:set_skill("sailing", 3)
|
||||
u1:add_item("money", 1000)
|
||||
u1.ship = s1
|
||||
local u2 = unit.create(f, r, 1)
|
||||
u2.race = "elf"
|
||||
u2:set_skill("magic", 6)
|
||||
u2.magic = "gwyrrd"
|
||||
u2.aura = 60
|
||||
u2.ship = s1
|
||||
u2:add_spell("stormwinds")
|
||||
update_owners()
|
||||
u2:clear_orders()
|
||||
u2:add_order("Zaubere stufe 2 'Beschwoere einen Sturmelementar' " .. itoa36(s1.id))
|
||||
u1:clear_orders()
|
||||
u1:add_order("NACH O O O O")
|
||||
process_orders()
|
||||
assert_equal(4, u2.region.x)
|
||||
|
||||
u2:clear_orders()
|
||||
u2:add_order("Zaubere stufe 2 'Beschwoere einen Sturmelementar' " .. itoa36(s1.id))
|
||||
u1:clear_orders()
|
||||
u1:add_order("NACH O O O O")
|
||||
process_orders()
|
||||
assert_equal(8, u2.region.x)
|
||||
end
|
||||
|
||||
local function use_tree(terrain)
|
||||
local r = region.create(0,0, terrain)
|
||||
local f = faction.create("noreply@eressea.de", "human", "de")
|
||||
local u1 = unit.create(f, r, 5)
|
||||
r:set_resource("tree", 0)
|
||||
u1:add_item("xmastree", 1)
|
||||
u1:clear_orders()
|
||||
u1:add_order("BENUTZEN 1 Weihnachtsbaum")
|
||||
process_orders()
|
||||
return r
|
||||
end
|
||||
|
||||
function test_xmas2009()
|
||||
local r = region.create(0,0, "plain")
|
||||
local f = faction.create("noreply@eressea.de", "human", "de")
|
||||
local u1 = unit.create(f, r, 1)
|
||||
process_orders()
|
||||
xmas2009()
|
||||
assert_equal("xmastree", f.items())
|
||||
end
|
||||
|
||||
function test_xmastree()
|
||||
local r
|
||||
r = use_tree("ocean")
|
||||
assert_equal(0, r:get_resource("tree"))
|
||||
eressea.free_game()
|
||||
r = use_tree("plain")
|
||||
assert_equal(10, r:get_resource("tree"))
|
||||
end
|
||||
|
||||
function test_fishing()
|
||||
eressea.settings.set("rules.economy.food", "0")
|
||||
local r = region.create(0,0, "ocean")
|
||||
local r2 = region.create(1,0, "plain")
|
||||
local f = faction.create("noreply@eressea.de", "human", "de")
|
||||
local s1 = ship.create(r, "cutter")
|
||||
local u1 = unit.create(f, r, 3)
|
||||
u1.ship = s1
|
||||
u1:set_skill("sailing", 10)
|
||||
u1:add_item("money", 100)
|
||||
u1:clear_orders()
|
||||
u1:add_order("NACH O")
|
||||
update_owners()
|
||||
|
||||
process_orders()
|
||||
assert_equal(r2, u1.region)
|
||||
assert_equal(90, u1:get_item("money"))
|
||||
|
||||
u1:clear_orders()
|
||||
u1:add_order("NACH W")
|
||||
|
||||
process_orders()
|
||||
assert_equal(r, u1.region)
|
||||
assert_equal(60, u1:get_item("money"))
|
||||
end
|
||||
|
||||
function test_ship_capacity()
|
||||
eressea.settings.set("rules.ship.drifting", "0")
|
||||
eressea.settings.set("rules.ship.storms", "0")
|
||||
local r = region.create(0,0, "ocean")
|
||||
region.create(1,0, "ocean")
|
||||
local r2 = region.create(2,0, "ocean")
|
||||
local f = faction.create("noreply@eressea.de", "human", "de")
|
||||
local f2 = faction.create("noreply@eressea.de", "goblin", "de")
|
||||
|
||||
-- u1 is at the limit and moves
|
||||
local s1 = ship.create(r, "cutter")
|
||||
local u1 = unit.create(f, r, 5)
|
||||
u1.ship = s1
|
||||
u1:set_skill("sailing", 10)
|
||||
u1:add_item("sword", 55)
|
||||
u1:clear_orders()
|
||||
u1:add_order("NACH O O")
|
||||
|
||||
-- u2 has too many people
|
||||
local s2 = ship.create(r, "cutter")
|
||||
local u2 = unit.create(f, r, 6)
|
||||
u2.ship = s2
|
||||
u2:set_skill("sailing", 10)
|
||||
u2:clear_orders()
|
||||
u2:add_order("NACH O O")
|
||||
|
||||
-- u3 has goblins, they weigh 40% less
|
||||
local s3 = ship.create(r, "cutter")
|
||||
local u3 = unit.create(f2, r, 8)
|
||||
u3.ship = s3
|
||||
u3:set_skill("sailing", 10)
|
||||
u3:add_item("sword", 55)
|
||||
u3:clear_orders()
|
||||
u3:add_order("NACH O O")
|
||||
|
||||
-- u4 has too much stuff
|
||||
local s4 = ship.create(r, "cutter")
|
||||
local u4 = unit.create(f, r, 5)
|
||||
u4.ship = s4
|
||||
u4:set_skill("sailing", 10)
|
||||
u4:add_item("sword", 56)
|
||||
u4:clear_orders()
|
||||
u4:add_order("NACH O O")
|
||||
|
||||
update_owners()
|
||||
process_orders()
|
||||
if r2~=u1.region then
|
||||
print(get_turn(), u1, u1.faction)
|
||||
write_reports()
|
||||
end
|
||||
assert_equal(r2, u1.region)
|
||||
assert_not_equal(r2.id, u2.region.id)
|
||||
if r2~=u3.region then
|
||||
print(get_turn(), u3, u3.faction)
|
||||
write_reports()
|
||||
end
|
||||
assert_equal(r2, u3.region)
|
||||
assert_not_equal(r2.id, u4.region.id)
|
||||
end
|
||||
|
||||
function test_owners()
|
||||
local r = region.create(0, 0, "plain")
|
||||
local f1 = faction.create("noreply@eressea.de", "human", "de")
|
||||
local u1 = unit.create(f1, r, 1)
|
||||
local f2 = faction.create("noreply@eressea.de", "human", "de")
|
||||
local u2 = unit.create(f2, r, 1)
|
||||
local u3 = unit.create(f2, r, 1)
|
||||
|
||||
local b3 = building.create(r, "castle")
|
||||
b3.size = 2
|
||||
u3.building = b3
|
||||
local b1 = building.create(r, "castle")
|
||||
b1.size = 1
|
||||
u1.building = b1
|
||||
local b2 = building.create(r, "castle")
|
||||
b2.size = 2
|
||||
u2.building = b2
|
||||
|
||||
update_owners()
|
||||
assert(r.owner==u3.faction)
|
||||
b1.size=3
|
||||
b2.size=3
|
||||
update_owners()
|
||||
assert(r.owner==u2.faction)
|
||||
b1.size=4
|
||||
update_owners()
|
||||
assert(r.owner==u1.faction)
|
||||
end
|
||||
|
||||
function test_taxes()
|
||||
local r = region.create(0, 0, "plain")
|
||||
r:set_resource("peasant", 1000)
|
||||
r:set_resource("money", 5000)
|
||||
local f = faction.create("noreply@eressea.de", "human", "de")
|
||||
local u = unit.create(f, r, 1)
|
||||
u:clear_orders()
|
||||
u:add_order("LERNE Holzfaellen") -- do not work
|
||||
local b = building.create(r, "watch")
|
||||
b.size = 10
|
||||
u.building = b
|
||||
update_owners()
|
||||
assert_equal(1, r.morale)
|
||||
process_orders()
|
||||
assert_equal(1, r.morale)
|
||||
assert_equal(25, u:get_item("money"))
|
||||
end
|
||||
|
||||
function test_region_owner_cannot_leave_castle()
|
||||
eressea.settings.set("rules.move.owner_leave", "1")
|
||||
local r = region.create(0, 0, "plain")
|
||||
local f = faction.create("noreply@eressea.de", "human", "de")
|
||||
f.id = 42
|
||||
local b1 = building.create(r, "castle")
|
||||
b1.size = 10
|
||||
local b2 = building.create(r, "lighthouse")
|
||||
b2.size = 10
|
||||
local u = unit.create(f, r, 1)
|
||||
u.building = b1
|
||||
u:add_item("money", u.number * 100)
|
||||
u:clear_orders()
|
||||
u:add_order("BETRETE BURG " .. itoa36(b2.id))
|
||||
process_orders()
|
||||
init_reports()
|
||||
write_report(u.faction)
|
||||
assert_equal(b1, u.building, "region owner has left the building") -- region owners may not leave
|
||||
end
|
||||
|
||||
function test_market()
|
||||
-- if i am the only trader around, i should be getting all the herbs from all 7 regions
|
||||
local herb_multi = 500 -- from rc_herb_trade()
|
||||
local r, idx
|
||||
local herbnames = { 'h0', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'h7', 'h8' }
|
||||
idx = 1
|
||||
for x = -1, 1 do for y = -1, 1 do
|
||||
r = region.create(x, y, "plain")
|
||||
r:set_resource("peasant", herb_multi * 9 + 50) -- 10 herbs per region
|
||||
r.herb = herbnames[idx]
|
||||
idx = idx+1
|
||||
end end
|
||||
r = get_region(0, 0)
|
||||
local b = building.create(r, "market")
|
||||
b.size = 10
|
||||
local f = faction.create("noreply@eressea.de", "human", "de")
|
||||
f.id = 42
|
||||
local u = unit.create(f, r, 1)
|
||||
u.building = b
|
||||
u:add_item("money", u.number * 10000)
|
||||
for i = 0, 5 do
|
||||
local rn = r:next(i)
|
||||
end
|
||||
b.working = true
|
||||
eressea.process.markets()
|
||||
u:add_item("money", -u:get_item("money")) -- now we only have herbs
|
||||
local len = 0
|
||||
for i in u.items do
|
||||
len = len + 1
|
||||
end
|
||||
assert_not_equal(0, len, "trader did not get any herbs")
|
||||
for idx, name in pairs(herbnames) do
|
||||
local n = u:get_item(name)
|
||||
if n>0 then
|
||||
assert_equal(10, n, 'trader did not get exaxtly 10 herbs')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function test_market_gives_items()
|
||||
local r
|
||||
for x = -1, 1 do for y = -1, 1 do
|
||||
r = region.create(x, y, "plain")
|
||||
r:set_resource("peasant", 5000)
|
||||
end end
|
||||
r = get_region(0, 0)
|
||||
local b = building.create(r, "market")
|
||||
b.size = 10
|
||||
local f = faction.create("noreply@eressea.de", "human", "de")
|
||||
f.id = 42
|
||||
local u = unit.create(f, r, 1)
|
||||
u.building = b
|
||||
u:add_item("money", u.number * 10000)
|
||||
for i = 0, 5 do
|
||||
local rn = r:next(i)
|
||||
end
|
||||
process_orders()
|
||||
local len = 0
|
||||
for i in u.items do
|
||||
len = len + 1
|
||||
end
|
||||
assert(len>1)
|
||||
end
|
||||
|
||||
function test_spells()
|
||||
local r = region.create(0, 0, "plain")
|
||||
local f = faction.create("noreply@eressea.de", "human", "de")
|
||||
local u = unit.create(f, r, 1)
|
||||
u.race = "elf"
|
||||
u:clear_orders()
|
||||
u:add_item("money", 10000)
|
||||
u:set_skill("magic", 5)
|
||||
u:add_order("LERNE MAGIE Illaun")
|
||||
process_orders()
|
||||
local sp
|
||||
local nums = 0
|
||||
if f.spells~=nil then
|
||||
for sp in f.spells do
|
||||
nums = nums + 1
|
||||
end
|
||||
assert(nums>0)
|
||||
for sp in u.spells do
|
||||
nums = nums - 1
|
||||
end
|
||||
assert(nums==0)
|
||||
elseif u.spells~=nil then
|
||||
for sp in u.spells do
|
||||
nums = nums + 1
|
||||
end
|
||||
assert(nums>0)
|
||||
end
|
||||
end
|
||||
|
||||
function test_alliance()
|
||||
local r = region.create(0, 0, "plain")
|
||||
local f1 = faction.create("noreply@eressea.de", "human", "de")
|
||||
local u1 = unit.create(f1, r, 1)
|
||||
u1:add_item("money", u1.number * 100)
|
||||
local f2 = faction.create("info@eressea.de", "human", "de")
|
||||
local u2 = unit.create(f2, r, 1)
|
||||
u2:add_item("money", u2.number * 100)
|
||||
assert(f1.alliance==nil)
|
||||
assert(f2.alliance==nil)
|
||||
u1:clear_orders()
|
||||
u2:clear_orders()
|
||||
u1:add_order("ALLIANZ NEU pink")
|
||||
u1:add_order("ALLIANZ EINLADEN " .. itoa36(f2.id))
|
||||
u2:add_order("ALLIANZ BEITRETEN pink")
|
||||
process_orders()
|
||||
assert(f1.alliance~=nil)
|
||||
assert(f2.alliance~=nil)
|
||||
assert(f2.alliance==f1.alliance)
|
||||
u1:clear_orders()
|
||||
u2:clear_orders()
|
||||
u1:add_order("ALLIANZ KOMMANDO " .. itoa36(f2.id))
|
||||
process_orders()
|
||||
assert(f1.alliance~=nil)
|
||||
assert(f2.alliance~=nil)
|
||||
assert(f2.alliance==f1.alliance)
|
||||
for f in f1.alliance.factions do
|
||||
assert_true(f.id==f1.id or f.id==f2.id)
|
||||
end
|
||||
u1:clear_orders()
|
||||
u2:clear_orders()
|
||||
u2:add_order("ALLIANZ AUSSTOSSEN " .. itoa36(f1.id))
|
||||
process_orders()
|
||||
assert(f1.alliance==nil)
|
||||
assert(f2.alliance~=nil)
|
||||
u1:clear_orders()
|
||||
u2:clear_orders()
|
||||
u2:add_order("ALLIANZ NEU zing")
|
||||
u1:add_order("ALLIANZ BEITRETEN zing") -- no invite!
|
||||
process_orders()
|
||||
assert(f1.alliance==nil)
|
||||
assert(f2.alliance~=nil)
|
||||
u1:clear_orders()
|
||||
u2:clear_orders()
|
||||
u1:add_order("ALLIANZ NEU zack")
|
||||
u1:add_order("ALLIANZ EINLADEN " .. itoa36(f2.id))
|
||||
u2:add_order("ALLIANZ BEITRETEN zack")
|
||||
process_orders()
|
||||
assert(f1.alliance==f2.alliance)
|
||||
assert(f2.alliance~=nil)
|
||||
end
|
||||
|
||||
function test_canoe_passes_through_land()
|
||||
local f = faction.create("noreply@eressea.de", "human", "de")
|
||||
local src = region.create(0, 0, "ocean")
|
||||
local land = region.create(1, 0, "plain")
|
||||
region.create(2, 0, "ocean")
|
||||
local dst = region.create(3, 0, "ocean")
|
||||
local sh = ship.create(src, "canoe")
|
||||
local u1 = unit.create(f, src, 1)
|
||||
local u2 = unit.create(f, src, 1)
|
||||
u1.ship = sh
|
||||
u2.ship = sh
|
||||
u1:set_skill("sailing", 10)
|
||||
u1:clear_orders()
|
||||
u1:add_order("NACH O O O")
|
||||
process_orders()
|
||||
assert_equal(land, u2.region, "canoe did not stop at coast")
|
||||
u1:add_order("NACH O O O")
|
||||
process_orders()
|
||||
assert_equal(dst, sh.region, "canoe could not leave coast")
|
||||
assert_equal(dst, u1.region, "canoe could not leave coast")
|
||||
assert_equal(dst, u2.region, "canoe could not leave coast")
|
||||
end
|
||||
|
||||
function test_give_50_percent_of_money()
|
||||
local r = region.create(0, 0, "plain")
|
||||
local u1 = unit.create(faction.create("noreply@eressea.de", "human", "de"), r, 1)
|
||||
local u2 = unit.create(faction.create("noreply@eressea.de", "orc", "de"), r, 1)
|
||||
u1.faction.age = 10
|
||||
u2.faction.age = 10
|
||||
u1:add_item("money", 500)
|
||||
u2:add_item("money", 500)
|
||||
local m1, m2 = u1:get_item("money"), u2:get_item("money")
|
||||
u1:clear_orders()
|
||||
u1:add_order("GIB " .. itoa36(u2.id) .. " 221 Silber")
|
||||
u2:clear_orders()
|
||||
u2:add_order("LERNEN Hiebwaffen")
|
||||
process_orders()
|
||||
assert_equal(m1, u1:get_item("money"))
|
||||
assert_equal(m2, u2:get_item("money"))
|
||||
|
||||
m1, m2 = u1:get_item("money"), u2:get_item("money")
|
||||
u1:clear_orders()
|
||||
u1:add_order("GIB " .. itoa36(u2.id) .. " 221 Silber")
|
||||
u2:clear_orders()
|
||||
u2:add_order("HELFEN " .. itoa36(u1.faction.id) .. " GIB")
|
||||
u2:add_item("horse", 100)
|
||||
u2:add_order("GIB 0 ALLES PFERD")
|
||||
local h = r:get_resource("horse")
|
||||
process_orders()
|
||||
assert_true(r:get_resource("horse")>=h+100)
|
||||
assert_equal(m1-221, u1:get_item("money"))
|
||||
assert_equal(m2+110, u2:get_item("money"))
|
||||
end
|
||||
|
||||
function test_give_100_percent_of_items()
|
||||
r = region.create(0, 0, "plain")
|
||||
local u1 = unit.create(faction.create("noreply@eressea.de", "human", "de"), r, 1)
|
||||
local u2 = unit.create(faction.create("noreply@eressea.de", "orc", "de"), r, 1)
|
||||
u1.faction.age = 10
|
||||
u2.faction.age = 10
|
||||
u1:add_item("money", 500)
|
||||
u1:add_item("log", 500)
|
||||
local m1, m2 = u1:get_item("log"), u2:get_item("log")
|
||||
u1:clear_orders()
|
||||
u1:add_order("GIB " .. itoa36(u2.id) .. " 332 Holz")
|
||||
u2:clear_orders()
|
||||
u2:add_order("LERNEN Hiebwaffen")
|
||||
u2:add_order("HELFEN " .. itoa36(u1.faction.id) .. " GIB")
|
||||
process_orders()
|
||||
assert_equal(m1-332, u1:get_item("log"))
|
||||
assert_equal(m2+332, u2:get_item("log"))
|
||||
end
|
||||
|
||||
function test_cannot_give_person()
|
||||
local r = region.create(0, 0, "plain")
|
||||
local f1 = faction.create("noreply@eressea.de", "human", "de")
|
||||
local f2 = faction.create("noreply@eressea.de", "human", "de")
|
||||
local u1 = unit.create(f1, r, 10)
|
||||
local u2 = unit.create(f2, r, 10)
|
||||
u1.faction.age = 10
|
||||
u2.faction.age = 10
|
||||
u1:add_item("money", 500)
|
||||
u2:add_item("money", 500)
|
||||
u2:clear_orders()
|
||||
u2:add_order("GIB ".. itoa36(u1.id) .. " 1 PERSON")
|
||||
u2:add_order("HELFE ".. itoa36(f1.id) .. " GIB")
|
||||
u1:add_order("HELFE ".. itoa36(f2.id) .. " GIB")
|
||||
process_orders()
|
||||
assert_equal(10, u2.number)
|
||||
assert_equal(10, u1.number)
|
||||
end
|
||||
|
||||
function test_cannot_give_unit()
|
||||
local r = region.create(0, 0, "plain")
|
||||
local f1 = faction.create("noreply@eressea.de", "human", "de")
|
||||
local f2 = faction.create("noreply@eressea.de", "human", "de")
|
||||
local u1 = unit.create(f1, r, 10)
|
||||
local u2 = unit.create(f2, r, 10)
|
||||
u1.faction.age = 10
|
||||
u2.faction.age = 10
|
||||
u1:add_item("money", 500)
|
||||
u2:add_item("money", 500)
|
||||
u2:clear_orders()
|
||||
u2:add_order("GIB ".. itoa36(u1.id) .. " EINHEIT")
|
||||
u2:add_order("HELFE ".. itoa36(f1.id) .. " GIB")
|
||||
u1:add_order("HELFE ".. itoa36(f2.id) .. " GIB")
|
||||
process_orders()
|
||||
assert_not_equal(u2.faction.id, u1.faction.id)
|
||||
end
|
||||
|
||||
function test_guard_by_owners()
|
||||
-- http://bugs.eressea.de/view.php?id=1756
|
||||
local r = region.create(0,0, "mountain")
|
||||
local f1 = faction.create("noreply@eressea.de", "human", "de")
|
||||
f1.age=20
|
||||
local f2 = faction.create("noreply@eressea.de", "human", "de")
|
||||
f2.age=20
|
||||
local u1 = unit.create(f1, r, 1)
|
||||
local b = building.create(r, "castle")
|
||||
b.size = 10
|
||||
u1.building = b
|
||||
u1:add_item("money", 100)
|
||||
|
||||
local u2 = unit.create(f2, r, 1)
|
||||
u2:add_item("money", 100)
|
||||
u2:set_skill("mining", 3)
|
||||
u2:clear_orders()
|
||||
u2:add_order("MACHEN EISEN")
|
||||
|
||||
process_orders()
|
||||
local iron = u2:get_item("iron")
|
||||
process_orders()
|
||||
assert_equal(iron, u2:get_item("iron"))
|
||||
end
|
||||
|
||||
function test_market_action()
|
||||
local f = faction.create("noreply@eressea.de", "human", "de")
|
||||
local x, y, r
|
||||
for x=0,2 do
|
||||
for y=0,2 do
|
||||
r = region.create(x, y, "plain")
|
||||
r.luxury = "balm"
|
||||
r.herb = "h2"
|
||||
r:set_resource("peasant", 5000)
|
||||
end
|
||||
end
|
||||
r = get_region(1, 1)
|
||||
local u = unit.create(f, r, 1)
|
||||
b = building.create(r, "market")
|
||||
b.size = 10
|
||||
u.building = b
|
||||
update_owners()
|
||||
for r in regions() do
|
||||
market_action(r)
|
||||
end
|
||||
assert_equal(35, u:get_item("balm"))
|
||||
assert_equal(70, u:get_item("h2"))
|
||||
end
|
||||
|
||||
local function setup_packice(x, onfoot)
|
||||
local f = faction.create("noreply@eressea.de", "human", "de")
|
||||
local plain = region.create(0,0, "plain")
|
||||
local ice = region.create(1,0, "packice")
|
||||
local ocean = region.create(2,0, "ocean")
|
||||
local u = unit.create(f, get_region(x, 0), 2)
|
||||
if not onfoot then
|
||||
local s = ship.create(u.region, "cutter")
|
||||
u:set_skill("sailing", 3)
|
||||
u.ship = s
|
||||
end
|
||||
u:add_item("money", 400)
|
||||
|
||||
return u
|
||||
end
|
||||
|
||||
function test_no_sailing_through_packice()
|
||||
local u = setup_packice(0)
|
||||
u:clear_orders()
|
||||
u:add_order("NACH O O")
|
||||
process_orders()
|
||||
assert_equal(0, u.region.x)
|
||||
end
|
||||
|
||||
function test_can_sail_from_packice_to_ocean()
|
||||
local u = setup_packice(1)
|
||||
|
||||
u:clear_orders()
|
||||
u:add_order("NACH W")
|
||||
process_orders()
|
||||
assert_equal(1, u.region.x)
|
||||
|
||||
u:clear_orders()
|
||||
u:add_order("NACH O")
|
||||
process_orders()
|
||||
assert_equal(2, u.region.x)
|
||||
end
|
||||
|
||||
function test_can_sail_into_packice()
|
||||
local u = setup_packice(2)
|
||||
u:clear_orders()
|
||||
u:add_order("NACH W W")
|
||||
process_orders()
|
||||
assert_equal(1, u.region.x)
|
||||
end
|
||||
|
||||
function test_can_walk_into_packice()
|
||||
local u = setup_packice(0, true)
|
||||
u:clear_orders()
|
||||
u:add_order("NACH O")
|
||||
process_orders()
|
||||
assert_equal(1, u.region.x)
|
||||
end
|
||||
|
||||
function test_cannot_walk_into_ocean()
|
||||
local u = setup_packice(1, true)
|
||||
u:clear_orders()
|
||||
u:add_order("NACH O")
|
||||
process_orders()
|
||||
assert_equal(1, u.region.x)
|
||||
end
|
||||
|
||||
function test_p2()
|
||||
local f = faction.create("noreply@eressea.de", "human", "de")
|
||||
local r = region.create(0, 0, "plain")
|
||||
local u = unit.create(f, r, 1)
|
||||
r:set_resource("tree", 0)
|
||||
u:clear_orders()
|
||||
u:add_order("BENUTZE 'Wasser des Lebens'")
|
||||
u:add_item("p2", 1)
|
||||
u:add_item("log", 10)
|
||||
u:add_item("mallorn", 10)
|
||||
process_orders()
|
||||
assert_equal(5, r:get_resource("tree"))
|
||||
assert_equal(0, u:get_item("p2"))
|
||||
assert_equal(15, u:get_item("log") + u:get_item("mallorn"))
|
||||
end
|
||||
|
||||
function test_p2_move()
|
||||
-- http://bugs.eressea.de/view.php?id=1855
|
||||
local f = faction.create("noreply@eressea.de", "human", "de")
|
||||
local r = region.create(0, 0, "plain")
|
||||
region.create(1, 0, "plain")
|
||||
local u = unit.create(f, r, 1)
|
||||
r:set_resource("tree", 0)
|
||||
u:clear_orders()
|
||||
u:add_order("BENUTZE 'Wasser des Lebens'")
|
||||
u:add_order("NACH OST")
|
||||
u:add_item("horse", 1)
|
||||
u:add_item("p2", 1)
|
||||
u:add_item("log", 1)
|
||||
u:add_item("mallorn", 1)
|
||||
process_orders()
|
||||
assert_equal(1, u.region.x)
|
||||
assert_equal(1, r:get_resource("tree"))
|
||||
end
|
||||
|
||||
function disabled_test_bug_1738_build_castle_e3()
|
||||
local r = region.create(0, 0, "plain")
|
||||
local f = faction.create("bug_1738@eressea.de", "human", "de")
|
||||
|
||||
local c = building.create(r, "castle")
|
||||
c.size = 228
|
||||
|
||||
local u1 = unit.create(f, r, 1)
|
||||
u1:set_skill("building", 5)
|
||||
u1:add_item("stone", 10000)
|
||||
|
||||
local u2 = unit.create(f, r, 32)
|
||||
u2:set_skill("building", 3)
|
||||
u2:add_item("stone", 10000)
|
||||
|
||||
u1:clear_orders()
|
||||
u1:add_order("MACHE BURG " .. itoa36(c.id))
|
||||
-- castle now has size 229.
|
||||
u2:clear_orders()
|
||||
u2:add_order("MACHE BURG " .. itoa36(c.id))
|
||||
-- 32 * 3 makes 96 skill points.
|
||||
-- from size 229 to size 250 needs 21 * 3 = 63 points, rest 33.
|
||||
-- 33/4 makes 8 points, resulting size is 258.
|
||||
|
||||
process_orders()
|
||||
--[[
|
||||
init_reports()
|
||||
write_report(f)
|
||||
]]--
|
||||
-- resulting size should be 250 because unit 2
|
||||
-- does not have the needed minimum skill.
|
||||
assert_equal(c.size, 250)
|
||||
end
|
||||
|
||||
function test_golem_use_four_iron()
|
||||
local r0 = region.create(0, 0, "plain")
|
||||
local f1 = faction.create("noreply@eressea.de", "halfling", "de")
|
||||
local u1 = unit.create(f1, r0, 3)
|
||||
u1.race = "irongolem"
|
||||
u1:set_skill("weaponsmithing", 1)
|
||||
u1:set_skill("armorer", 1)
|
||||
u1:clear_orders()
|
||||
u1:add_order("Mache 4 Turmschild")
|
||||
|
||||
process_orders()
|
||||
|
||||
assert_equal(2, u1.number)
|
||||
assert_equal(4, u1:get_item("towershield"))
|
||||
end
|
||||
|
||||
function test_building_owner_can_enter_ship()
|
||||
local r1 = region.create(1, 2, "plain")
|
||||
local f1 = faction.create("noreply@tteessttiinngg.de", "human", "de")
|
||||
local b1 = building.create(r1, "castle")
|
||||
b1.size = 10
|
||||
local s1 = ship.create(r1, "cutter")
|
||||
|
||||
local u1 = unit.create(f1, r1, 10)
|
||||
u1.building = b1
|
||||
u1:add_item("money", u1.number * 100)
|
||||
u1:clear_orders()
|
||||
u1:add_order("VERLASSEN")
|
||||
u1:add_order("BETRETE SCHIFF " .. itoa36(s1.id))
|
||||
|
||||
local u2 = unit.create(f1, r1, 10)
|
||||
u2.ship = s1
|
||||
u2:add_item("money", u1.number * 100)
|
||||
u2:clear_orders()
|
||||
process_orders()
|
||||
assert_equal(s1, u1.ship)
|
||||
assert_equal(null, u1.building, "owner of the building can not go into a ship")
|
||||
end
|
|
@ -0,0 +1,360 @@
|
|||
require "lunit"
|
||||
|
||||
module("tests.e3.e2features", package.seeall, lunit.testcase )
|
||||
|
||||
local function one_unit(r, f)
|
||||
local u = unit.create(f, r, 1)
|
||||
u:add_item("money", u.number * 100)
|
||||
u:clear_orders()
|
||||
return u
|
||||
end
|
||||
|
||||
local function two_factions()
|
||||
local f1 = faction.create("one@eressea.de", "human", "de")
|
||||
local f2 = faction.create("two@eressea.de", "human", "de")
|
||||
return f1, f2
|
||||
end
|
||||
|
||||
local function two_units(r, f1, f2)
|
||||
return one_unit(r, f1), one_unit(r, f2)
|
||||
end
|
||||
|
||||
function setup()
|
||||
eressea.free_game()
|
||||
eressea.settings.set("nmr.timeout", "0")
|
||||
eressea.settings.set("rules.economy.food", "4")
|
||||
end
|
||||
|
||||
function test_learn()
|
||||
eressea.settings.set("study.random_progress", "0")
|
||||
local r = region.create(0, 0, "plain")
|
||||
local f = faction.create("noreply@eressea.de", "human", "de")
|
||||
f.age = 20
|
||||
local u = unit.create(f, r)
|
||||
u:clear_orders()
|
||||
u:add_order("@LERNEN Reiten")
|
||||
process_orders()
|
||||
assert_equal(1, u:get_skill("riding"))
|
||||
process_orders()
|
||||
process_orders()
|
||||
assert_equal(2, u:get_skill("riding"))
|
||||
process_orders()
|
||||
process_orders()
|
||||
process_orders()
|
||||
assert_equal(3, u:get_skill("riding"))
|
||||
end
|
||||
|
||||
function test_teach()
|
||||
eressea.settings.set("study.random_progress", "0")
|
||||
local r = region.create(0, 0, "plain")
|
||||
local f = faction.create("noreply@eressea.de", "human", "de")
|
||||
f.age = 20
|
||||
local u = unit.create(f, r, 10)
|
||||
local u2 = unit.create(f, r)
|
||||
u:clear_orders()
|
||||
u:add_order("@LERNEN reiten")
|
||||
u2:clear_orders()
|
||||
u2:add_order("LEHREN " .. itoa36(u.id))
|
||||
u2:set_skill("riding", 4)
|
||||
process_orders()
|
||||
assert_equal(1, u:get_skill("riding"))
|
||||
process_orders()
|
||||
assert_equal(2, u:get_skill("riding"))
|
||||
end
|
||||
|
||||
function test_rename()
|
||||
local r = region.create(0, 0, "plain")
|
||||
local f = faction.create("noreply@eressea.de", "human", "de")
|
||||
local u = unit.create(f, r)
|
||||
u:add_item("aoh", 1)
|
||||
assert_equal(u:get_item("ao_healing"), 1)
|
||||
end
|
||||
|
||||
function DISABLE_test_alp()
|
||||
local r = region.create(0,0, "plain")
|
||||
local f = faction.create("noreply@eressea.de", "human", "de")
|
||||
local u = unit.create(f, r, 1)
|
||||
local u2 = unit.create(f, r, 1)
|
||||
u.race = "elf"
|
||||
u:set_skill("magic", 10)
|
||||
u:add_item("money", 3010)
|
||||
u.magic = "illaun"
|
||||
u.aura = 200
|
||||
u.ship = s1
|
||||
u:add_spell("summon_alp")
|
||||
u:clear_orders()
|
||||
u:add_order("ZAUBERE 'Alp' " .. itoa36(u2.id))
|
||||
process_orders()
|
||||
print(get_turn(), f)
|
||||
write_reports()
|
||||
end
|
||||
|
||||
function test_unit_limit_is_1500()
|
||||
local r = region.create(0,0, "plain")
|
||||
local f = faction.create("noreply@eressea.de", "human", "de")
|
||||
for i = 1,1500 do
|
||||
unit.create(f, r, 1)
|
||||
end
|
||||
local u = unit.create(f, r, 0)
|
||||
u:add_item("money", 20000)
|
||||
u:clear_orders()
|
||||
u:add_order("REKRUTIEREN 1")
|
||||
process_orders()
|
||||
assert_equal(1, u.number)
|
||||
end
|
||||
|
||||
function test_ship_capacity()
|
||||
local r = region.create(0,0, "ocean")
|
||||
region.create(1,0, "ocean")
|
||||
local r2 = region.create(2,0, "ocean")
|
||||
local f = faction.create("noreply@eressea.de", "human", "de")
|
||||
|
||||
-- u1 is at the limit and moves
|
||||
local s1 = ship.create(r, "boat")
|
||||
local u1 = unit.create(f, r, 5)
|
||||
u1.ship = s1
|
||||
u1:set_skill("sailing", 10)
|
||||
u1:clear_orders()
|
||||
u1:add_order("NACH O O")
|
||||
|
||||
-- u2 has too many people
|
||||
local s2 = ship.create(r, "boat")
|
||||
local u2 = unit.create(f, r, 6)
|
||||
u2.ship = s2
|
||||
u2:set_skill("sailing", 10)
|
||||
u2:clear_orders()
|
||||
u2:add_order("NACH O O")
|
||||
|
||||
-- u4 has too much stuff
|
||||
local s4 = ship.create(r, "boat")
|
||||
local u4 = unit.create(f, r, 5)
|
||||
u4.ship = s4
|
||||
u4:set_skill("sailing", 10)
|
||||
u4:add_item("sword", 1)
|
||||
u4:clear_orders()
|
||||
u4:add_order("NACH O O")
|
||||
|
||||
process_orders()
|
||||
|
||||
-- print(s.region, u.region, r2)
|
||||
assert_equal(r2, u1.region, "boat with 5 humans did not move")
|
||||
assert_not_equal(r2, u2.region, "boat with too many people has moved")
|
||||
assert_not_equal(r2, u4.region, "boat with too much cargo has moved")
|
||||
end
|
||||
|
||||
function test_levitate()
|
||||
local r = region.create(0,0, "plain")
|
||||
local f = faction.create("noreply@eressea.de", "human", "de")
|
||||
local u = unit.create(f, r, 2)
|
||||
local s = ship.create(r, "boat")
|
||||
u.ship = s
|
||||
u.age = 20
|
||||
u:set_skill("sailing", 5)
|
||||
u:add_item("money", 100)
|
||||
u:clear_orders()
|
||||
u:add_order("ARBEITE")
|
||||
levitate_ship(u.ship, u, 2, 1)
|
||||
assert_equal(32, u.ship.flags)
|
||||
process_orders()
|
||||
assert_equal(0, u.ship.flags)
|
||||
end
|
||||
|
||||
function test_terrains()
|
||||
local terrains = { "hell", "wall1", "corridor1" }
|
||||
for k,v in ipairs(terrains) do
|
||||
local r = region.create(k, k, v)
|
||||
assert_not_equal(nil, r)
|
||||
end
|
||||
end
|
||||
|
||||
function test_races()
|
||||
local races = { "wolf", "orc", "human", "demon" }
|
||||
for k,v in ipairs(races) do
|
||||
local f = faction.create("noreply@eressea.de", "human", "de")
|
||||
assert_not_equal(nil, f)
|
||||
end
|
||||
end
|
||||
|
||||
function test_can_give_person()
|
||||
local r = region.create(0, 0, "plain")
|
||||
local f1 = faction.create("noreply@eressea.de", "human", "de")
|
||||
local f2 = faction.create("noreply@eressea.de", "human", "de")
|
||||
local u1 = unit.create(f1, r, 10)
|
||||
local u2 = unit.create(f2, r, 10)
|
||||
u1.faction.age = 10
|
||||
u2.faction.age = 10
|
||||
u1:add_item("money", 500)
|
||||
u2:add_item("money", 500)
|
||||
u2:clear_orders()
|
||||
u2:add_order("GIB ".. itoa36(u1.id) .. " 1 PERSON")
|
||||
u2:add_order("HELFE ".. itoa36(f1.id) .. " GIB")
|
||||
u1:add_order("HELFE ".. itoa36(f2.id) .. " GIB")
|
||||
u1:add_order("KONTAKTIERE ".. itoa36(u2.id))
|
||||
process_orders()
|
||||
assert_equal(9, u2.number)
|
||||
assert_equal(11, u1.number)
|
||||
end
|
||||
|
||||
function test_no_uruk()
|
||||
local f1 = faction.create("noreply@eressea.de", "uruk", "de")
|
||||
assert_equal(f1.race, "orc")
|
||||
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(u2.race, "snowman")
|
||||
u = nil
|
||||
break
|
||||
end
|
||||
end
|
||||
assert_equal(nil, u)
|
||||
end
|
||||
|
||||
function test_block_movement()
|
||||
eressea.settings.set("rules.guard.base_stop_prob", "0.3")
|
||||
eressea.settings.set("rules.guard.amulet_stop_prob", "0.0")
|
||||
eressea.settings.set("rules.guard.skill_stop_prob", "0.1")
|
||||
|
||||
local r0 = region.create(0, 0, "plain")
|
||||
local r1 = region.create(1, 0, "plain")
|
||||
local r2 = region.create(2, 0, "plain")
|
||||
local f1, f2 = two_factions()
|
||||
f1.age=20
|
||||
f2.age=20
|
||||
|
||||
local u11 = one_unit(r1, f1)
|
||||
local u2 = { }
|
||||
for i = 1, 20 do
|
||||
u2[i] = one_unit(r0, f2)
|
||||
end
|
||||
|
||||
u11:add_item("sword", 1)
|
||||
u11:add_item("money", 1)
|
||||
u11:set_skill("melee", 1)
|
||||
u11:set_skill("perception", 7)
|
||||
u11:clear_orders()
|
||||
u11:add_order("BEWACHEN")
|
||||
|
||||
process_orders()
|
||||
|
||||
for i, u in ipairs(u2) do
|
||||
u:add_item("horse", 1)
|
||||
u:set_skill("riding", 1)
|
||||
u:clear_orders()
|
||||
u:add_order("NACH o o")
|
||||
end
|
||||
|
||||
u2[1]:set_skill("stealth", 8)
|
||||
|
||||
process_orders()
|
||||
|
||||
assert_equal(r2, u2[1].region, "nobody should see me")
|
||||
for i, u in ipairs(u2) do
|
||||
if i > 1 then
|
||||
assert_equal(r1, u.region, "perception +7 should always stop me")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
function test_block_movement_aots()
|
||||
eressea.settings.set("rules.guard.base_stop_prob", "0.0")
|
||||
eressea.settings.set("rules.guard.skill_stop_prob", "1.0")
|
||||
eressea.settings.set("rules.guard.amulet_stop_prob", "1.1")
|
||||
|
||||
local r0 = region.create(0, 0, "plain")
|
||||
local r1 = region.create(1, 0, "plain")
|
||||
local r2 = region.create(2, 0, "plain")
|
||||
local f1, f2 = two_factions()
|
||||
f1.age=20
|
||||
f2.age=20
|
||||
|
||||
local u11, u12 = two_units(r1, f1, f1)
|
||||
local u21, u22 = two_units(r0, f2, f2)
|
||||
|
||||
for i, u in ipairs ({ u11, u12 }) do
|
||||
u:add_item("sword", 1)
|
||||
u:add_item("money", 1)
|
||||
u:set_skill("melee", 1)
|
||||
u:clear_orders()
|
||||
u:add_order("BEWACHEN")
|
||||
end
|
||||
|
||||
process_orders()
|
||||
|
||||
for i, u in ipairs ({ u21, u22 }) do
|
||||
u:add_item("horse", 1)
|
||||
u:set_skill("riding", 1)
|
||||
u:clear_orders()
|
||||
u:add_order("NACH o o")
|
||||
end
|
||||
|
||||
u12:add_item("aots", 10)
|
||||
u22:set_skill("stealth", 1)
|
||||
|
||||
process_orders()
|
||||
|
||||
assert_equal(r1, u21.region, "unit with amulet should stop me")
|
||||
assert_equal(r2, u22.region, "nobody should see me")
|
||||
end
|
||||
|
||||
function test_stonegolems()
|
||||
local r0 = region.create(0, 0, "plain")
|
||||
local f1 = faction.create("noreply@eressea.de", "stonegolem", "de")
|
||||
local u1 = unit.create(f1, r0, 1)
|
||||
local u2 = unit.create(f1, r0, 2)
|
||||
local c1 = building.create(r0, "castle")
|
||||
|
||||
c1.size = 226
|
||||
|
||||
u1:set_skill("building", 1)
|
||||
u2:set_skill("building", 1)
|
||||
|
||||
-- test that no server crash occur
|
||||
u1:clear_orders()
|
||||
u1:add_order("Mache Burg")
|
||||
process_orders()
|
||||
assert_equal(0 ,u1.number, "There shoud be no Stone Golems")
|
||||
-- end test server crash
|
||||
|
||||
-- test that Stone Golems build for four stones
|
||||
u2:clear_orders()
|
||||
u2:add_order("MACHE 4 BURG " .. itoa36(c1.id))
|
||||
process_orders()
|
||||
assert_equal(230, c1.size, "resulting size should be 230")
|
||||
assert_equal(1 ,u2.number, "There shoud be one Stone Golems")
|
||||
-- end test Stone Golems four stones
|
||||
end
|
||||
|
||||
function test_only_building_owner_can_set_not_paid()
|
||||
local r = region.create(0, 0, "plain")
|
||||
local f = faction.create("noreply@eressea.de", "human", "de")
|
||||
local u1 = unit.create(f, r, 1)
|
||||
local u2 = unit.create(f, r, 1)
|
||||
local mine = building.create(r, "mine")
|
||||
mine.size = 2
|
||||
u1:add_item("money", 500)
|
||||
u1.building = mine
|
||||
u2.building = mine
|
||||
u1:clear_orders()
|
||||
u2:clear_orders()
|
||||
-- Test that Bezahle nicht is working
|
||||
u1:add_order("Bezahle nicht")
|
||||
process_orders()
|
||||
assert_equal(500, u1:get_item("money"))
|
||||
u1:clear_orders()
|
||||
-- Test that bug fix 0001976 is working
|
||||
-- Bezahle nicht is not working
|
||||
u2:add_order("Bezahle nicht")
|
||||
process_orders()
|
||||
assert_equal(0, u1:get_item("money"))
|
||||
end
|
|
@ -0,0 +1,16 @@
|
|||
-- require 'eressea.tests.spells'
|
||||
require 'eressea.tests.common'
|
||||
require 'eressea.tests.stealth'
|
||||
-- require 'eressea.tests.spells-e3'
|
||||
-- require 'eressea.tests.spells-e2'
|
||||
require 'eressea.tests.settings'
|
||||
-- require 'eressea.tests.morale'
|
||||
-- require 'eressea.tests.orders'
|
||||
-- require 'eressea.tests.eressea'
|
||||
-- require 'eressea.tests.e3a'
|
||||
-- require 'eressea.tests.config'
|
||||
-- require 'eressea.tests.common'
|
||||
require 'eressea.tests.castles'
|
||||
require 'eressea.tests.bindings'
|
||||
-- require 'eressea.tests.bson'
|
||||
-- require 'eressea.tests.attrib'
|
|
@ -0,0 +1,179 @@
|
|||
require "lunit"
|
||||
|
||||
module("tests.eressea.morale", package.seeall, lunit.testcase )
|
||||
|
||||
function setup()
|
||||
eressea.game.reset()
|
||||
eressea.settings.set('rules.region_owners', '1')
|
||||
end
|
||||
|
||||
function test_when_owner_returns_morale_drops_only_2()
|
||||
local r = region.create(0, 0, "plain")
|
||||
assert_equal(1, r.morale)
|
||||
local f1 = faction.create("noreply@eressea.de", "human", "de")
|
||||
local u1 = unit.create(f1, r, 1)
|
||||
u1:add_item("money", 10000)
|
||||
local b = building.create(r, "castle")
|
||||
b.size = 50
|
||||
|
||||
set_turn(get_turn()+10)
|
||||
f1.lastturn=get_turn()
|
||||
u1.building = b
|
||||
update_owners()
|
||||
r.morale = 6
|
||||
u1.building = nil
|
||||
process_orders()
|
||||
assert_equal(5, r.morale) -- no owner, fall by 1
|
||||
u1.building = b
|
||||
update_owners()
|
||||
set_key("test", 42)
|
||||
process_orders()
|
||||
assert_equal(3, r.morale) -- new owner, fall by 2
|
||||
end
|
||||
|
||||
function test_morale_alliance()
|
||||
local r = region.create(0, 0, "plain")
|
||||
assert_equal(1, r.morale)
|
||||
local f1 = faction.create("noreply@eressea.de", "human", "de")
|
||||
local u1 = unit.create(f1, r, 1)
|
||||
u1:add_item("money", 10000)
|
||||
local f2 = faction.create("noreply@eressea.de", "human", "de")
|
||||
local u2 = unit.create(f2, r, 1)
|
||||
u2:add_item("money", 10000)
|
||||
local f3 = faction.create("noreply@eressea.de", "human", "de")
|
||||
local u3 = unit.create(f3, r, 1)
|
||||
u3:add_item("money", 10000)
|
||||
|
||||
local al = alliance.create(42, "Die Antwoord")
|
||||
f1.alliance = al;
|
||||
f2.alliance = al;
|
||||
|
||||
local b = building.create(r, "castle")
|
||||
b.size = 50
|
||||
u1.building = b
|
||||
u2.building = b
|
||||
u3.building = b
|
||||
update_owners()
|
||||
r.morale = 6
|
||||
|
||||
local function run_a_turn()
|
||||
process_orders()
|
||||
f1.lastturn=get_turn()
|
||||
f2.lastturn=get_turn()
|
||||
f3.lastturn=get_turn()
|
||||
end
|
||||
|
||||
-- just checking everything's okay after setup.
|
||||
run_a_turn()
|
||||
assert_equal(6, r.morale)
|
||||
|
||||
-- change owner, new owner is in the same alliance
|
||||
u1.building = nil
|
||||
run_a_turn()
|
||||
assert_equal(4, r.morale)
|
||||
|
||||
-- change owner, new owner is not in the same alliance
|
||||
u2.building = nil
|
||||
run_a_turn()
|
||||
assert_equal(0, r.morale)
|
||||
end
|
||||
|
||||
function test_morale_change()
|
||||
local r = region.create(0, 0, "plain")
|
||||
assert_equal(1, r.morale)
|
||||
local f1 = faction.create("noreply@eressea.de", "human", "de")
|
||||
local u1 = unit.create(f1, r, 1)
|
||||
u1:add_item("money", 10000)
|
||||
local f2 = faction.create("noreply@eressea.de", "human", "de")
|
||||
local u2 = unit.create(f2, r, 1)
|
||||
u2:add_item("money", 10000)
|
||||
|
||||
local AVG_STEP = 6
|
||||
local b = building.create(r, "castle")
|
||||
b.size = 10
|
||||
u1.building = b
|
||||
|
||||
local function run_a_turn()
|
||||
process_orders()
|
||||
f1.lastturn=get_turn()
|
||||
f2.lastturn=get_turn()
|
||||
end
|
||||
|
||||
-- reinhardt-regel: nach 2*AVG_STEP ist moral mindestens einmal gestiegen.
|
||||
update_owners()
|
||||
assert_not_equal(r.owner, nil)
|
||||
for i=1,AVG_STEP*2 do
|
||||
run_a_turn()
|
||||
assert_not_equal(r.owner, nil)
|
||||
end
|
||||
assert_not_equal(1, r.morale)
|
||||
|
||||
-- regel: moral ist nie hoeher als 2 punkte ueber burgen-max.
|
||||
for i=1,AVG_STEP*4 do
|
||||
run_a_turn()
|
||||
end
|
||||
assert_equal(4, r.morale)
|
||||
|
||||
-- auch mit herrscher faellt moral um 1 pro woche, wenn moral > burgstufe
|
||||
r.morale = 6
|
||||
run_a_turn()
|
||||
assert_equal(5, r.morale)
|
||||
run_a_turn()
|
||||
assert_equal(4, r.morale)
|
||||
run_a_turn()
|
||||
assert_equal(4, r.morale)
|
||||
|
||||
-- regel: ohne herrscher fällt die moral jede woche um 1 punkt, bis sie 1 erreicht
|
||||
u1.building = nil
|
||||
update_owners()
|
||||
run_a_turn()
|
||||
assert_equal(3, r.morale)
|
||||
run_a_turn()
|
||||
assert_equal(2, r.morale)
|
||||
run_a_turn()
|
||||
assert_equal(1, r.morale)
|
||||
run_a_turn()
|
||||
assert_equal(1, r.morale)
|
||||
|
||||
-- ohne herrscher ändert sich auch beschissene Moral nicht:
|
||||
r.morale = 0
|
||||
run_a_turn()
|
||||
assert_equal(0, r.morale)
|
||||
end
|
||||
|
||||
function test_morale_old()
|
||||
local r = region.create(0, 0, "plain")
|
||||
assert_equal(1, r.morale)
|
||||
local f1 = faction.create("first@eressea.de", "human", "de")
|
||||
local u1 = unit.create(f1, r, 1)
|
||||
local f2 = faction.create("second@eressea.de", "human", "de")
|
||||
local u2 = unit.create(f2, r, 1)
|
||||
|
||||
local b = building.create(r, "castle")
|
||||
b.size = 10
|
||||
u1.building = b
|
||||
u2.building = b
|
||||
update_owners()
|
||||
assert_equal(1, r.morale)
|
||||
r.morale = 5
|
||||
assert_equal(u1.faction, r.owner)
|
||||
u1:clear_orders()
|
||||
u1:add_order("GIB " .. itoa36(u2.id) .. " KOMMANDO")
|
||||
process_orders()
|
||||
u1:clear_orders()
|
||||
assert_equal(r.owner, u2.faction)
|
||||
assert_equal(3, r.morale) -- 5-MORALE_TRANSFER
|
||||
for u in r.units do
|
||||
if u.faction.id==u2.faction.id then
|
||||
u.building = nil
|
||||
end
|
||||
end
|
||||
update_owners()
|
||||
assert_equal(r.owner, u1.faction)
|
||||
assert_equal(0, r.morale)
|
||||
end
|
||||
|
||||
function test_no_uruk()
|
||||
local f1 = faction.create("noreply@eressea.de", "uruk", "de")
|
||||
assert_equal(f1.race, "orc")
|
||||
end
|
|
@ -0,0 +1,268 @@
|
|||
require "lunit"
|
||||
|
||||
local _G = _G
|
||||
local eressea = eressea
|
||||
local default_ship = config.ships[1]
|
||||
local default_building = config.buildings[1]
|
||||
|
||||
module('tests.eressea.orders', package.seeall, lunit.testcase)
|
||||
|
||||
local r, f, u
|
||||
|
||||
function setup()
|
||||
eressea.free_game()
|
||||
r = _G.region.create(0, 0, "mountain")
|
||||
f = _G.faction.create("noreply@eressea.de", "human", "de")
|
||||
u = _G.unit.create(f, r, 1)
|
||||
u:clear_orders()
|
||||
eressea.settings.set("rules.economy.food", "4")
|
||||
eressea.settings.set("nmr.removenewbie", "0")
|
||||
eressea.settings.set("nmr.timeout", "0")
|
||||
eressea.settings.set("NewbieImmunity", "0")
|
||||
end
|
||||
|
||||
function test_learn()
|
||||
u:add_order("LERNEN Hiebwaffen")
|
||||
_G.process_orders()
|
||||
assert_not_equal(0, u:get_skill("melee"))
|
||||
end
|
||||
|
||||
function test_give()
|
||||
local u2 = _G.unit.create(f, r, 1)
|
||||
u:add_item("money", 10)
|
||||
u:add_order("GIB " .. u2.id .. "5 SILBER")
|
||||
_G.process_orders()
|
||||
assert_not_equal(5, u:get_item("money"))
|
||||
assert_not_equal(5, u2:get_item("money"))
|
||||
end
|
||||
|
||||
function test_make_temp()
|
||||
u:add_order("MACHE TEMP 123 'Herpderp'")
|
||||
u:add_order("// this comment will be copied")
|
||||
u:add_order("ENDE")
|
||||
eressea.process.make_temp()
|
||||
|
||||
for x in f.units do
|
||||
if x.name == 'Herpderp' then u=x end
|
||||
end
|
||||
assert_equal('Herpderp', u.name)
|
||||
assert_equal(0, u.number)
|
||||
local c = 0
|
||||
for o in u.orders do
|
||||
assert_equal('// this comment will be copied', o)
|
||||
c = c + 1
|
||||
end
|
||||
assert_equal(1, c)
|
||||
end
|
||||
|
||||
function test_give_temp()
|
||||
u.number = 2
|
||||
u:add_order("GIB TEMP 123 1 PERSON")
|
||||
u:add_order("MACHE TEMP 123 'Herpderp'")
|
||||
u:add_order("ENDE")
|
||||
_G.process_orders()
|
||||
assert_equal(1, u.number)
|
||||
|
||||
for x in f.units do
|
||||
if x.name == 'Herpderp' then u=x end
|
||||
end
|
||||
assert_equal('Herpderp', u.name)
|
||||
assert_equal(1, u.number)
|
||||
end
|
||||
|
||||
function test_process_settings()
|
||||
f.options = 0
|
||||
u:add_order("EMAIL herp@derp.com")
|
||||
u:add_order("BANNER 'Herpderp'")
|
||||
u:add_order("PASSWORT 'HerpDerp'")
|
||||
u:add_order("OPTION AUSWERTUNG")
|
||||
eressea.process.settings()
|
||||
assert_equal("herp@derp.com", f.email)
|
||||
assert_equal("Herpderp", f.info)
|
||||
assert_equal("HerpDerp", f.password)
|
||||
assert_equal(1, f.options)
|
||||
end
|
||||
|
||||
function test_process_group()
|
||||
u:add_order("GRUPPE herp")
|
||||
eressea.process.set_group()
|
||||
assert_equal('herp', u.group)
|
||||
end
|
||||
|
||||
function test_process_origin()
|
||||
u:add_order("URSPRUNG 1 2")
|
||||
eressea.process.set_origin()
|
||||
x, y = u.faction:get_origin()
|
||||
assert_equal(1, x)
|
||||
assert_equal(2, y)
|
||||
end
|
||||
|
||||
function test_process_quit()
|
||||
fno = f.id
|
||||
u:add_order("STIRB '" .. u.faction.password .. "'")
|
||||
assert_not_equal(nil, _G.get_faction(fno))
|
||||
eressea.process.quit()
|
||||
eressea.write_game('test.dat')
|
||||
eressea.free_game()
|
||||
eressea.read_game('test.dat')
|
||||
assert_equal(nil, _G.get_faction(fno))
|
||||
end
|
||||
|
||||
function test_process_make()
|
||||
u.region:set_resource('tree', 100)
|
||||
u:set_skill('forestry', 1)
|
||||
u:add_order('MACHE HOLZ')
|
||||
eressea.process.produce()
|
||||
assert_equal(1, u:get_item('log'))
|
||||
end
|
||||
|
||||
function test_process_study()
|
||||
u:add_order("LERNEN Holzfaellen")
|
||||
eressea.process.update_long_order()
|
||||
eressea.process.study()
|
||||
x, y = u.faction:get_origin()
|
||||
assert_equal(1, u:get_skill('forestry'))
|
||||
end
|
||||
|
||||
function test_process_teach()
|
||||
eressea.settings.set("study.random_progress", "0")
|
||||
u:set_skill('forestry', 3)
|
||||
u2 = _G.unit.create(f, r, 10)
|
||||
u2:clear_orders()
|
||||
u2:set_skill('forestry', 1)
|
||||
u2:add_order("LERNEN Holzfaellen")
|
||||
u:add_order("LEHREN " .. _G.itoa36(u2.id))
|
||||
eressea.process.update_long_order()
|
||||
eressea.process.study()
|
||||
assert_equal(2, u2:get_skill('forestry'))
|
||||
end
|
||||
|
||||
function test_process_move()
|
||||
r2 = _G.region.create(1, 0, 'plain')
|
||||
u:add_order('NACH O')
|
||||
assert_not_equal(r2.id, u.region.id)
|
||||
eressea.process.update_long_order()
|
||||
eressea.process.movement()
|
||||
assert_equal(r2, u.region)
|
||||
end
|
||||
|
||||
function test_process_leave()
|
||||
r2 = _G.region.create(1, 0, 'plain')
|
||||
b = _G.building.create(r, default_building)
|
||||
assert_not_nil(b)
|
||||
u.building = b
|
||||
assert_equal(b, u.building)
|
||||
u:add_order('VERLASSEN')
|
||||
eressea.process.leave()
|
||||
assert_not_equal(b, u.building)
|
||||
end
|
||||
|
||||
function test_process_name_unit()
|
||||
u:add_order("BENENNE EINHEIT 'Weasel'")
|
||||
u:add_order("BESCHREIBE EINHEIT 'Juanita'")
|
||||
eressea.process.set_name()
|
||||
assert_equal('Weasel', u.name)
|
||||
assert_equal('Juanita', u.info)
|
||||
end
|
||||
|
||||
function test_process_name_faction()
|
||||
u:add_order("BENENNE PARTEI 'Herpderp'")
|
||||
eressea.process.set_name()
|
||||
assert_equal('Herpderp', f.name)
|
||||
end
|
||||
|
||||
function test_process_name_building()
|
||||
u:add_order("BENENNE GEBAEUDE 'Herpderp'")
|
||||
u.building = _G.building.create(r, default_building)
|
||||
eressea.process.set_name()
|
||||
assert_equal('Herpderp', u.building.name)
|
||||
end
|
||||
|
||||
function test_process_name_ship()
|
||||
u:add_order("BENENNE SCHIFF 'Herpderp'")
|
||||
u.ship = _G.ship.create(r, default_ship)
|
||||
eressea.process.set_name()
|
||||
assert_equal('Herpderp', u.ship.name)
|
||||
end
|
||||
|
||||
function test_process_renumber()
|
||||
u:add_order("NUMMER EINHEIT 'ii'")
|
||||
eressea.process.renumber()
|
||||
assert_equal(666, u.id)
|
||||
end
|
||||
|
||||
function test_process_enter()
|
||||
b = _G.building.create(r, default_building)
|
||||
assert_not_nil(b)
|
||||
u:add_order("BETRETEN GEBAEUDE " .. _G.itoa36(b.id))
|
||||
eressea.process.enter(1)
|
||||
assert_equal(b, u.building)
|
||||
end
|
||||
|
||||
function test_process_restack()
|
||||
eressea.process.restack()
|
||||
end
|
||||
|
||||
function test_process_setspells()
|
||||
eressea.process.set_spells()
|
||||
end
|
||||
|
||||
function test_process_help()
|
||||
eressea.process.set_help()
|
||||
end
|
||||
|
||||
function test_process_contact()
|
||||
eressea.process.contact()
|
||||
end
|
||||
|
||||
function test_process_battle()
|
||||
eressea.process.battle()
|
||||
end
|
||||
|
||||
function test_process_magic()
|
||||
eressea.process.magic()
|
||||
end
|
||||
|
||||
function test_process_give_control()
|
||||
eressea.process.give_control()
|
||||
end
|
||||
|
||||
function test_process_regeneration()
|
||||
eressea.process.regeneration()
|
||||
end
|
||||
|
||||
function test_process_guard_on()
|
||||
eressea.process.guard_on()
|
||||
end
|
||||
|
||||
function test_process_guard_off()
|
||||
eressea.process.guard_off()
|
||||
end
|
||||
|
||||
function test_process_explain()
|
||||
eressea.process.explain()
|
||||
end
|
||||
|
||||
function test_process_messages()
|
||||
eressea.process.messages()
|
||||
end
|
||||
|
||||
function test_process_reserve()
|
||||
eressea.process.reserve()
|
||||
end
|
||||
|
||||
function test_process_claim()
|
||||
eressea.process.claim()
|
||||
end
|
||||
|
||||
function test_process_follow()
|
||||
eressea.process.follow()
|
||||
end
|
||||
|
||||
function test_process_idle()
|
||||
eressea.process.idle()
|
||||
end
|
||||
|
||||
function test_process_set_default()
|
||||
eressea.process.set_default()
|
||||
end
|
|
@ -0,0 +1,13 @@
|
|||
require "lunit"
|
||||
|
||||
module("tests.eressea.settings", package.seeall, lunit.testcase )
|
||||
|
||||
function setup()
|
||||
eressea.free_game()
|
||||
end
|
||||
|
||||
function test_settings()
|
||||
assert_equal(nil, eressea.settings.get("foo"))
|
||||
eressea.settings.set("foo", "bar")
|
||||
assert_equal("bar", eressea.settings.get("foo"))
|
||||
end
|
|
@ -0,0 +1,47 @@
|
|||
require "lunit"
|
||||
|
||||
module("eressea.tests.spells.e3", package.seeall, lunit.testcase)
|
||||
|
||||
function setup()
|
||||
eressea.free_game()
|
||||
eressea.settings.set("magic.fumble.enable", "0")
|
||||
eressea.settings.set("nmr.removenewbie", "0")
|
||||
eressea.settings.set("nmr.timeout", "0")
|
||||
eressea.settings.set("rules.peasants.growth", "0")
|
||||
end
|
||||
|
||||
function test_blessedharvest_lasts_n_turn()
|
||||
eressea.free_game()
|
||||
local r = region.create(0, 0, "plain")
|
||||
local f = faction.create("noreply@eressea.de", "halfling", "de")
|
||||
local u = unit.create(f, r)
|
||||
local err = 0
|
||||
r:set_resource("peasant", 100)
|
||||
r:set_resource("money", 0)
|
||||
u:add_item("money", 1000)
|
||||
u.magic = "gwyrrd"
|
||||
u.race = "dwarf"
|
||||
u:set_skill("magic", 20)
|
||||
u.aura = 200
|
||||
err = err + u:add_spell("raindance")
|
||||
err = err + u:add_spell("blessedharvest")
|
||||
assert_equal(0, err)
|
||||
|
||||
u:clear_orders()
|
||||
u:add_order("ZAUBERE STUFE 3 Regentanz")
|
||||
assert_equal(0, r:get_resource("money"), 0)
|
||||
|
||||
local m = 0
|
||||
local p = 100
|
||||
|
||||
process_orders()
|
||||
assert_equal(200, r:get_resource("money"))
|
||||
u:clear_orders()
|
||||
u:add_order("ARBEITEN")
|
||||
process_orders()
|
||||
process_orders()
|
||||
process_orders()
|
||||
assert_equal(800, r:get_resource("money"))
|
||||
process_orders()
|
||||
assert_equal(900, r:get_resource("money"))
|
||||
end
|
|
@ -0,0 +1,37 @@
|
|||
require "lunit"
|
||||
|
||||
module('eressea.tests.stealth', package.seeall, lunit.testcase)
|
||||
|
||||
local f
|
||||
local u
|
||||
|
||||
function setup()
|
||||
eressea.game.reset()
|
||||
eressea.settings.set('rules.economy.food', '4')
|
||||
eressea.settings.set('rules.magic.playerschools', '')
|
||||
|
||||
local r = region.create(0,0, "plain")
|
||||
f = faction.create("stealthy@eressea.de", "human", "de")
|
||||
u = unit.create(f, r, 1)
|
||||
f = faction.create("stealth@eressea.de", "human", "de")
|
||||
end
|
||||
|
||||
function test_stealth_faction_on()
|
||||
u:clear_orders()
|
||||
u:add_order("TARNEN PARTEI")
|
||||
|
||||
eressea.settings.set("rules.stealth.faction", 1)
|
||||
process_orders()
|
||||
assert_not_match("Partei", report.report_unit(u, f))
|
||||
assert_match("anonym", report.report_unit(u, f))
|
||||
end
|
||||
|
||||
function test_stealth_faction_off()
|
||||
u:clear_orders()
|
||||
u:add_order("TARNEN PARTEI")
|
||||
|
||||
eressea.settings.set("rules.stealth.faction", 0)
|
||||
process_orders()
|
||||
assert_match("Partei", report.report_unit(u, f))
|
||||
assert_not_match("anonym", report.report_unit(u, f))
|
||||
end
|
Loading…
Reference in New Issue