From df96589ea6e024e01ec775ce2e2dadd2b927b765 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 30 Apr 2017 17:25:24 +0200 Subject: [PATCH] add tests for earn_silver. this is an odd one, don't want to break it. --- scripts/tests/e2/spells.lua | 43 ++++++++++++++++++++++++++++++++++ scripts/tests/e3/spells.lua | 46 ++++++++++++++++++++++++++++++++++--- 2 files changed, 86 insertions(+), 3 deletions(-) diff --git a/scripts/tests/e2/spells.lua b/scripts/tests/e2/spells.lua index 107b20232..4a45d7bc2 100644 --- a/scripts/tests/e2/spells.lua +++ b/scripts/tests/e2/spells.lua @@ -26,3 +26,46 @@ function test_shapeshift() s = u2:show() assert_equal("1 Goblin", string.sub(s, string.find(s, "1 Goblin"))) end + +-- E3: earn 50 per level of spell +function test_earn_silber() + local r = region.create(0, 0, "plain") + local f = faction.create("human") + local u = unit.create(f, r) + + eressea.settings.set("rules.food.flags", "4") + eressea.settings.set("magic.fumble.enable", "0") + eressea.settings.set("rules.peasants.growth", "0") + eressea.settings.set("rules.economy.repopulate_maximum", "0") + + u.magic = "gwyrrd" + u.race = "elf" + u:set_skill("magic", 10) + u.aura = 100 + local err = u:add_spell("earn_silver#gwyrrd") + assert_equal(0, err) + + u:clear_orders() + u:add_order("ZAUBERE STUFE 1 Viehheilung") + r:set_resource("money", 350) + r:set_resource("peasant", 0) + process_orders() -- get 50 silver + assert_equal(50, u:get_item("money")) + assert_equal(300, r:get_resource("money")) + + u:clear_orders() -- get 100 silver + u:add_order("ZAUBERE STUFE 2 Viehheilung") + process_orders() + assert_equal(150, u:get_item("money")) + assert_equal(200, r:get_resource("money")) + + u:clear_orders() -- get 150 silver + u:add_order("ZAUBERE STUFE 3 Viehheilung") + process_orders() + assert_equal(300, u:get_item("money")) + assert_equal(50, r:get_resource("money")) + + process_orders() -- not enough + assert_equal(350, u:get_item("money")) + assert_equal(0, r:get_resource("money")) +end diff --git a/scripts/tests/e3/spells.lua b/scripts/tests/e3/spells.lua index df9408fbd..b7d89c3e0 100644 --- a/scripts/tests/e3/spells.lua +++ b/scripts/tests/e3/spells.lua @@ -29,9 +29,6 @@ function test_blessedharvest_lasts_n_turn() 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() @@ -64,3 +61,46 @@ function test_magic() -- there used to be a SEGFAULT when writing reports here: -- write_reports() end + +-- E3: earn 50 per every TWO levels of spell +function test_earn_silber() + local r = region.create(0, 0, "plain") + local f = faction.create("human") + local u = unit.create(f, r) + + eressea.settings.set("rules.food.flags", "4") + eressea.settings.set("magic.fumble.enable", "0") + eressea.settings.set("rules.peasants.growth", "0") + eressea.settings.set("rules.economy.repopulate_maximum", "0") + + u.magic = "gwyrrd" + u.race = "elf" + u:set_skill("magic", 10) + u.aura = 100 + local err = u:add_spell("earn_silver#gwyrrd") + assert_equal(0, err) + + u:clear_orders() + u:add_order("ZAUBERE STUFE 1 Viehheilung") + r:set_resource("money", 250) + r:set_resource("peasant", 0) + process_orders() -- get 50 silver + assert_equal(50, u:get_item("money")) + assert_equal(200, r:get_resource("money")) + + u:clear_orders() -- get 75 silver + u:add_order("ZAUBERE STUFE 2 Viehheilung") + process_orders() + assert_equal(125, u:get_item("money")) + assert_equal(125, r:get_resource("money")) + + u:clear_orders() -- get 100 silver + u:add_order("ZAUBERE STUFE 3 Viehheilung") + process_orders() + assert_equal(225, u:get_item("money")) + assert_equal(25, r:get_resource("money")) + + process_orders() -- not enough + assert_equal(250, u:get_item("money")) + assert_equal(0, r:get_resource("money")) +end