Skip to content

Commit

Permalink
Add a bunch of tests for heals.
Browse files Browse the repository at this point in the history
Covers only attributes, not filters.
  • Loading branch information
Pentarctagon committed Nov 27, 2023
1 parent 1fa8946 commit babc17e
Show file tree
Hide file tree
Showing 38 changed files with 1,947 additions and 2 deletions.
1 change: 1 addition & 0 deletions data/test/_main.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
{test/scenarios/wml_tests/TerrainWML}
{test/scenarios/wml_tests/UnitsWML}
{test/scenarios/wml_tests/UnitsWML/AbilitiesWML}
{test/scenarios/wml_tests/UnitsWML/AbilitiesWML/heals}
{test/scenarios/wml_tests/UnitsWML/Attacks}
{test/scenarios/wml_tests/WesnothFormulaLanguage}

Expand Down
9 changes: 9 additions & 0 deletions data/test/macros/start_position_common_keep_a_b_c_d.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@
# There is no free castle hex to recruit onto.
##
#define COMMON_KEEP_A_B_C_D_UNIT_TEST NAME CONTENT

#arg SIDE1_TEAM
"A"#endarg

#arg SIDE2_TEAM
"B"#endarg

[test]
name=_ "Unit Test " + {NAME}
map_file=test/maps/4p_single_castle.map
Expand All @@ -26,6 +33,7 @@
[side]
side=1
controller=human
team_name={SIDE1_TEAM}
[leader]
name = _ "Alice"
type = Orcish Grunt
Expand All @@ -35,6 +43,7 @@
[side]
side=2
controller=human
team_name={SIDE2_TEAM}
[leader]
name = _ "Bob"
type = Orcish Grunt
Expand Down
12 changes: 12 additions & 0 deletions data/test/macros/start_position_generic.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
#arg TURNS
-1#endarg

#arg VWED
yes#endarg

# side 1
#arg SIDE1_CONTROLLER
human#endarg
Expand All @@ -28,6 +31,9 @@ human#endarg
#arg SIDE1_LEADER
Elvish Archer#endarg

#arg SIDE1_TEAM
"A"#endarg

# side 2
#arg SIDE2_CONTROLLER
human#endarg
Expand All @@ -41,12 +47,16 @@ human#endarg
#arg SIDE2_LEADER
Orcish Grunt#endarg

#arg SIDE2_TEAM
"B"#endarg

[test]
name = _ "Unit Test " + {NAME}
map_file=test/maps/generic_unit_test.map
turns = {TURNS}
id = {NAME}
is_unit_test = yes
victory_when_enemies_defeated = {VWED}

{DAWN}

Expand All @@ -55,6 +65,7 @@ Orcish Grunt#endarg
controller={SIDE1_CONTROLLER}
recruit={SIDE1_RECRUIT}
gold={SIDE1_GOLD}
team_name={SIDE1_TEAM}
[leader]
name = _ "Alice"
type = {SIDE1_LEADER}
Expand All @@ -66,6 +77,7 @@ Orcish Grunt#endarg
controller={SIDE2_CONTROLLER}
recruit={SIDE2_RECRUIT}
gold={SIDE2_GOLD}
team_name={SIDE2_TEAM}
[leader]
name = _ "Bob"
type = {SIDE2_LEADER}
Expand Down
46 changes: 46 additions & 0 deletions data/test/macros/unit_setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#define SET_HP

#arg VALUE
1#endarg

[modify_unit]
[filter]
[/filter]
hitpoints = {VALUE}
[/modify_unit]
#enddef

#define TEST_HEALS VALUE OTHER

#arg ID
1#endarg

#arg SELF
no#endarg

#arg ALLIES
yes#endarg

#arg ENEMIES
no#endarg

#arg POISON
"slowed"#endarg

#arg CUMULATIVE
no#endarg

[heals]
id = {ID}
name = "test-heals_{ID}"
affect_self = {SELF}
affect_allies = {ALLIES}
affect_enemies = {ENEMIES}
poison = {POISON}
value = {VALUE}
{OTHER}
cumulative = {CUMULATIVE}
[affect_adjacent]
[/affect_adjacent]
[/heals]
#enddef
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#####
# API(s) being tested: [heals]value=
##
# Actions:
# Give the leaders a heals ability with both the value and add attributes
# Spawn a Mage next to the side 1 leader.
# Set all units' hitpoints to 1.
# Wait a turn for healing to take place.
##
# Expected end state:
# The Mage has 7 hp: 1 + 2 (rest healing) + 4 ([heals], 2 (value) + 2 (add))
#####
{GENERIC_UNIT_TEST "heal_add" (
[event]
name = start

[modify_unit]
[filter]
[/filter]
[effect]
apply_to = new_ability
[abilities]
{TEST_HEALS 2 (add=2)}
[/abilities]
[/effect]
[/modify_unit]

{NOTRAIT_UNIT 1 (Mage) 7 4}
{SET_HP VALUE=1}

[end_turn][/end_turn]
[/event]

[event]
name = side 2 turn 1
[end_turn][/end_turn]
[/event]

[event]
name =side 1 turn 2
[end_turn][/end_turn]
[/event]

[event]
name = side 2 turn 2

[store_unit]
[filter]
type = "Mage"
[/filter]
variable = temp
[/store_unit]
{ASSERT {VARIABLE_CONDITIONAL temp.hitpoints numerical_equals 7}}
{SUCCEED}
[/event]
)}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#####
# API(s) being tested: [heals]value=
##
# Actions:
# Give the leaders a heals ability with both the value, add, and divide attributes
# Spawn a Mage next to the side 1 leader.
# Set all units' hitpoints to 1.
# Wait a turn for healing to take place.
##
# Expected end state:
# The Mage has 5 hp: 1 + 2 (rest healing) + 2 ([heals], (3+1)/2)
#####
{GENERIC_UNIT_TEST "heal_add_divide" (
[event]
name = start

[modify_unit]
[filter]
[/filter]
[effect]
apply_to = new_ability
[abilities]
{TEST_HEALS 3 (add=1
divide=2)}
[/abilities]
[/effect]
[/modify_unit]

{NOTRAIT_UNIT 1 (Mage) 7 4}
{SET_HP VALUE=1}

[end_turn][/end_turn]
[/event]

[event]
name = side 2 turn 1
[end_turn][/end_turn]
[/event]

[event]
name =side 1 turn 2
[end_turn][/end_turn]
[/event]

[event]
name = side 2 turn 2

[store_unit]
[filter]
type = "Mage"
[/filter]
variable = temp
[/store_unit]
{ASSERT {VARIABLE_CONDITIONAL temp.hitpoints numerical_equals 5}}
{SUCCEED}
[/event]
)}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#####
# API(s) being tested: [heals]value=
##
# Actions:
# Give the leaders a heals ability with both the value, add, and multiply attributes
# Spawn a Mage next to the side 1 leader.
# Set all units' hitpoints to 1.
# Wait a turn for healing to take place.
##
# Expected end state:
# The Mage has 11 hp: 1 + 2 (rest healing) + 8 ([heals], (3+1)*2)
#####
{GENERIC_UNIT_TEST "heal_add_multiply" (
[event]
name = start

[modify_unit]
[filter]
[/filter]
[effect]
apply_to = new_ability
[abilities]
{TEST_HEALS 3 (add=1
multiply=2)}
[/abilities]
[/effect]
[/modify_unit]

{NOTRAIT_UNIT 1 (Mage) 7 4}
{SET_HP VALUE=1}

[end_turn][/end_turn]
[/event]

[event]
name = side 2 turn 1
[end_turn][/end_turn]
[/event]

[event]
name =side 1 turn 2
[end_turn][/end_turn]
[/event]

[event]
name = side 2 turn 2

[store_unit]
[filter]
type = "Mage"
[/filter]
variable = temp
[/store_unit]
{ASSERT {VARIABLE_CONDITIONAL temp.hitpoints numerical_equals 11}}
{SUCCEED}
[/event]
)}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#####
# API(s) being tested: [heals]value=
##
# Actions:
# Give the leaders a heals ability with both the value, add, and sub attributes
# Spawn a Mage next to the side 1 leader.
# Set all units' hitpoints to 1.
# Wait a turn for healing to take place.
##
# Expected end state:
# The Mage has 4 hp: 1 + 2 (rest healing) + 1 ([heals], 3 (value) - 2 (sub))
# The value of the add attribute is ignored.
#####
{GENERIC_UNIT_TEST "heal_add_sub" (
[event]
name = start

[modify_unit]
[filter]
[/filter]
[effect]
apply_to = new_ability
[abilities]
{TEST_HEALS 3 (add=20
sub=2)}
[/abilities]
[/effect]
[/modify_unit]

{NOTRAIT_UNIT 1 (Mage) 7 4}
{SET_HP VALUE=1}

[end_turn][/end_turn]
[/event]

[event]
name = side 2 turn 1
[end_turn][/end_turn]
[/event]

[event]
name =side 1 turn 2
[end_turn][/end_turn]
[/event]

[event]
name = side 2 turn 2

[store_unit]
[filter]
type = "Mage"
[/filter]
variable = temp
[/store_unit]
{ASSERT {VARIABLE_CONDITIONAL temp.hitpoints numerical_equals 4}}
{SUCCEED}
[/event]
)}
Loading

0 comments on commit babc17e

Please sign in to comment.