2020-04-19 21:35:48 +02:00
|
|
|
local tcname = 'tests.e2.allies'
|
2020-05-03 16:52:40 +02:00
|
|
|
local lunit = require('lunit')
|
2020-04-19 21:35:48 +02:00
|
|
|
if _VERSION >= 'Lua 5.2' then
|
|
|
|
_ENV = module(tcname, 'seeall')
|
|
|
|
else
|
2020-05-03 16:52:40 +02:00
|
|
|
module(tcname, lunit.testcase, package.seeall)
|
2020-04-19 21:35:48 +02:00
|
|
|
end
|
2019-09-14 21:51:13 +02:00
|
|
|
|
2020-01-26 12:32:31 +01:00
|
|
|
function setup()
|
|
|
|
eressea.free_game()
|
2019-09-14 21:51:13 +02:00
|
|
|
end
|
2019-09-15 13:08:50 +02:00
|
|
|
|
|
|
|
function test_get_allies()
|
|
|
|
local f1 = faction.create("human")
|
|
|
|
local f2 = faction.create("human")
|
|
|
|
|
|
|
|
local allies = f1.allies
|
|
|
|
assert_equal('table', type(allies))
|
|
|
|
assert_equal(0, #allies)
|
|
|
|
f1:set_ally(f2, "give", true)
|
|
|
|
allies = f1.allies
|
2019-09-15 13:37:04 +02:00
|
|
|
assert_not_nil(allies[f2.id])
|
2019-09-15 13:08:50 +02:00
|
|
|
assert_equal('table', type(allies[f2.id]))
|
|
|
|
assert_equal(1, #allies[f2.id])
|
|
|
|
assert_equal("give", allies[f2.id][1])
|
|
|
|
end
|
2020-01-26 12:32:31 +01:00
|
|
|
|
|
|
|
function test_get_set_ally()
|
|
|
|
local f1 = faction.create("human")
|
|
|
|
local f2 = faction.create("human")
|
|
|
|
|
|
|
|
assert_equal(false, f1:get_ally(f2, "guard"))
|
|
|
|
f1:set_ally(f2, "guard", true)
|
|
|
|
assert_equal(true, f1:get_ally(f2, "guard"))
|
|
|
|
assert_equal(false, f1:get_ally(f2, "give"))
|
|
|
|
f1:set_ally(f2, "give", true)
|
|
|
|
assert_equal(true, f1:get_ally(f2, "give"))
|
|
|
|
end
|
|
|
|
|