-
-
Notifications
You must be signed in to change notification settings - Fork 991
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add unit tests for Lua API wesnoth.simulate_combat
- Loading branch information
1 parent
4dc923e
commit 25992e8
Showing
3 changed files
with
96 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# wmllint: no translatables | ||
|
||
##### | ||
# API(s) being tested: wesnoth.simulate_combat | ||
## | ||
# Actions: | ||
# Start with Alice and Bob on separate keeps (the GENERIC_UNIT_TEST macro). | ||
# Make a private-to-Lua clone of Alice, move her next to Bob. | ||
# Simulate combat. | ||
## | ||
# Expected end state: | ||
# The simulation with the original Alice shows that neither can reach the other. | ||
# The simulation with the cloned Alice shows combat stats. | ||
##### | ||
{GENERIC_UNIT_TEST simulate_combat_clone_adjacent ( | ||
[event] | ||
name=start | ||
|
||
[lua] | ||
code=<< | ||
local alice = wesnoth.units.find({id="alice"})[1] | ||
local bob = wesnoth.units.find({id="bob"})[1] | ||
local clone_alice = alice:clone() | ||
clone_alice.x = bob.x | ||
clone_alice.y = bob.y + 1 | ||
|
||
local att_stats, def_stats = wesnoth.simulate_combat(clone_alice, bob) | ||
unit_test.assert_approx_equal(att_stats.untouched, 1.0, 0.01, "Alice should have used her ranged attack") | ||
unit_test.assert_approx_equal(def_stats.untouched, 0.6 ^ 4, 0.01, "Bob should be on 60% def") | ||
|
||
att_stats, def_stats = wesnoth.simulate_combat(alice, bob) | ||
unit_test.assert_approx_equal(att_stats.untouched, 1.0, 0.01, "Alice should be out of reach of combat") | ||
unit_test.assert_approx_equal(def_stats.untouched, 1.0, 0.01, "Bob should be out of reach of combat") | ||
>> | ||
[/lua] | ||
|
||
{SUCCEED} | ||
[/event] | ||
)} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#textdomain wesnoth-test | ||
|
||
##### | ||
# API(s) being tested: wesnoth.simulate_combat | ||
## | ||
# Actions: | ||
# Start with Alice and Bob on separate keeps (the GENERIC_UNIT_TEST macro). | ||
# Spawn a unit called Dave on Bob's side next to Bob. | ||
# Make a private-to-Lua clone of Alice. | ||
# Simulate combat as if Alice was on the hex occupied by Dave. | ||
# While the units are in place, simulate combat between Dave and Bob too. | ||
## | ||
# Expected end state: | ||
# The simulation for Alice shows the same stats as if the hex was unoccupied. | ||
# | ||
# The simulation for Dave allows the fight to happen, and doesn't log any | ||
# errors. Possibly something that should change, but the test is included to | ||
# check for API changes in 1.16. | ||
##### | ||
{GENERIC_UNIT_TEST simulate_combat_occupied ( | ||
[event] | ||
name=start | ||
|
||
[unit] | ||
side=2 | ||
name=_ "Dave" | ||
type=Orcish Grunt | ||
id=dave | ||
placement=leader | ||
[/unit] | ||
|
||
[lua] | ||
code=<< | ||
local alice = wesnoth.units.find({id="alice"})[1] | ||
local bob = wesnoth.units.find({id="bob"})[1] | ||
local dave = wesnoth.units.find({id="dave"})[1] | ||
local clone_alice = alice:clone() | ||
clone_alice.x = dave.x | ||
clone_alice.y = dave.y | ||
|
||
local att_stats, def_stats = wesnoth.simulate_combat(clone_alice, bob) | ||
unit_test.assert_approx_equal(att_stats.untouched, 1.0, 0.01, "Alice should have used her ranged attack") | ||
unit_test.assert_approx_equal(def_stats.untouched, 0.6 ^ 4, 0.01, "Bob should be on 60% def") | ||
|
||
-- While the test is set up, check what happens if Dave attacks his own leader. | ||
-- In 1.16.x and at least 1.17.2 the attack gets simulated as if they were on different sides. | ||
att_stats, def_stats = wesnoth.simulate_combat(dave, bob) | ||
unit_test.assert_approx_equal(att_stats.untouched, 0.4 ^ 2, 0.01, "Dave should have attacked from 40% def") | ||
unit_test.assert_approx_equal(def_stats.untouched, 0.6 ^ 2, 0.01, "Bob should have retaliated from 60% def") | ||
>> | ||
[/lua] | ||
|
||
{SUCCEED} | ||
[/event] | ||
)} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters