server/scripts/tests/pool.lua

80 lines
2.4 KiB
Lua
Raw Permalink Normal View History

local tcname = 'tests.pool'
local lunit = require('lunit')
2020-04-19 21:35:48 +02:00
if _VERSION >= 'Lua 5.2' then
_ENV = module(tcname, 'seeall')
2020-04-19 21:35:48 +02:00
else
module(tcname, lunit.testcase, package.seeall)
2020-04-19 21:35:48 +02:00
end
function setup()
eressea.game.reset()
eressea.config.reset()
eressea.settings.set("rules.food.flags", "0")
eressea.settings.set("nmr.timeout", "0")
eressea.settings.set("rules.magic.playerschools", "")
conf = [[{
"races": {
"human" : { "flags" : [ "giveitem", "getitem" ] }
},
"terrains" : {
"plain": { "flags" : [ "land" ] }
},
"keywords" : {
"de" : {
"give" : "GIB",
"contact" : "KONTAKTIERE"
}
},
"strings" : {
"de" : {
"money" : "Silber"
}
}
}]]
assert(eressea.config.parse(conf)==0)
end
function test_give_nopool()
local r = region.create(1, 1, "plain")
local f = faction.create("human", "test@example.com", "de")
local u1 = unit.create(f, r, 1)
local u2 = unit.create(f, r, 1)
u1:add_item("money", 100)
u1:add_order("GIB " .. itoa36(u2.id) .. " 50 SILBER")
process_orders()
assert_equal(50, u1:get_item("money"))
assert_equal(50, u2:get_item("money"))
end
function test_give_from_faction()
local r = region.create(1, 1, "plain")
local f = faction.create("human", "test@example.com", "de")
local u1 = unit.create(f, r, 1)
local u2 = unit.create(f, r, 1)
local u3 = unit.create(f, r, 1)
u1:add_item("money", 50)
u2:add_item("money", 50)
u1:add_order("GIB " .. itoa36(u3.id) .. " 100 SILBER")
process_orders()
assert_equal(0, u1:get_item("money"))
assert_equal(0, u2:get_item("money"))
assert_equal(100, u3:get_item("money"))
end
function test_give_divisor()
eressea.settings.set("rules.items.give_divisor", 2)
eressea.settings.set("GiveRestriction", 0)
local r = region.create(1, 1, "plain")
local f1 = faction.create("human", "test@example.com", "de")
local f2 = faction.create("human", "test@example.com", "de")
local u1 = unit.create(f1, r, 1)
local u2 = unit.create(f2, r, 1)
u2:add_order("KONTAKTIERE " .. itoa36(u1.id))
u1:add_item("money", 100)
u1:add_order("GIB " .. itoa36(u2.id) .. " 100 SILBER")
process_orders()
assert_equal(0, u1:get_item("money"))
assert_equal(50, u2:get_item("money"))
end