WML unit tests for simple aspects
This commit is contained in:
parent
d00cc80076
commit
cb0fad078a
4 changed files with 481 additions and 1 deletions
91
data/test/scenarios/ai/_main.cfg
Normal file
91
data/test/scenarios/ai/_main.cfg
Normal file
|
@ -0,0 +1,91 @@
|
|||
|
||||
#define AI_NOTIFICATION_STAGE CODE
|
||||
[ai]
|
||||
ai_algorithm=idle_ai
|
||||
[stage]
|
||||
id=check_validity
|
||||
engine=lua
|
||||
code={CODE}
|
||||
[/stage]
|
||||
[/ai]
|
||||
#enddef
|
||||
|
||||
#define ASPECT_NOTIFICATION
|
||||
<<
|
||||
local H = wesnoth.require('lua/helper.lua')
|
||||
local expected = H.get_variable_array('expected')
|
||||
local aspect = wesnoth.get_variable('test_attribute')
|
||||
if ai.aspects[aspect] ~= expected[wesnoth.current.turn].value then
|
||||
wesnoth.set_variable('is_valid', false)
|
||||
local msg = 'Failed on turn ' .. tostring(wesnoth.current.turn)
|
||||
msg = msg .. ' (time: ' .. wesnoth.get_time_of_day().id .. ')'
|
||||
msg = msg .. '; ' .. aspect
|
||||
msg = msg .. ' was ' .. tostring(ai.aspects[aspect])
|
||||
msg = msg .. ' but expected to be '
|
||||
msg = msg .. tostring(expected[wesnoth.current.turn].value)
|
||||
wesnoth.wml_actions.wml_message{message=msg, logger='error'}
|
||||
end
|
||||
>>
|
||||
#enddef
|
||||
|
||||
#define SPLIT LIST SEP
|
||||
[split]
|
||||
list={LIST}
|
||||
key=value
|
||||
separator={SEP}
|
||||
[/split]
|
||||
#enddef
|
||||
|
||||
#define AI_ASPECT_UNIT_TEST NAME TEST_ATTRIBUTE EXPECTED AIWML CONTENT
|
||||
{AI_UNIT_TEST {NAME} {ASPECT_NOTIFICATION} {TEST_ATTRIBUTE} {EXPECTED} {AIWML} {CONTENT}}
|
||||
#enddef
|
||||
|
||||
#define AI_UNIT_TEST NAME TEST_CODE TEST_ATTRIBUTE EXPECTED AIWML CONTENT
|
||||
[test]
|
||||
name = "AI Unit Test " + {NAME}
|
||||
map_data = "{test/maps/generic_unit_test.map}"
|
||||
turns = -1
|
||||
id = {NAME}
|
||||
|
||||
{DEFAULT_SCHEDULE}
|
||||
|
||||
[side]
|
||||
side=1
|
||||
controller=computer
|
||||
name = "Alice"
|
||||
type = Elvish Archer
|
||||
id=alice
|
||||
{AI_NOTIFICATION_STAGE {TEST_CODE}}
|
||||
{AIWML}
|
||||
[/side]
|
||||
[side]
|
||||
side=2
|
||||
controller=computer
|
||||
name = "Bob"
|
||||
type = Orcish Grunt
|
||||
id=bob
|
||||
[ai]
|
||||
ai_algorithm=idle_ai
|
||||
[/ai]
|
||||
[/side]
|
||||
|
||||
[event]
|
||||
name=prestart
|
||||
{VARIABLE is_valid true}
|
||||
{VARIABLE test_attribute {TEST_ATTRIBUTE}}
|
||||
[set_variables]
|
||||
name=expected
|
||||
{EXPECTED}
|
||||
[/set_variables]
|
||||
[/event]
|
||||
[event]
|
||||
name=turn 12 end
|
||||
{RETURN {VARIABLE_CONDITIONAL is_valid boolean_equals true}}
|
||||
[/event]
|
||||
|
||||
{CONTENT}
|
||||
[/test]
|
||||
#enddef
|
||||
|
||||
{test/scenarios/ai/config}
|
||||
{test/scenarios/ai/modify}
|
147
data/test/scenarios/ai/config/simple_aspect.cfg
Normal file
147
data/test/scenarios/ai/config/simple_aspect.cfg
Normal file
|
@ -0,0 +1,147 @@
|
|||
|
||||
{AI_ASPECT_UNIT_TEST test_basic_simplified_aspect attack_depth
|
||||
{SPLIT 3,5,5,3,7,7,5,3,5,5,7,7 ,}
|
||||
(
|
||||
[ai]
|
||||
time_of_day=first_watch,second_watch
|
||||
attack_depth=7
|
||||
[/ai]
|
||||
[ai]
|
||||
turns=1,4,8
|
||||
attack_depth=3
|
||||
[/ai]
|
||||
) ()}
|
||||
|
||||
{AI_ASPECT_UNIT_TEST test_basic_abbreviated_aspect attack_depth
|
||||
{SPLIT 7,7,7,7,7,7,5,5,5,5,9,9 ,}
|
||||
(
|
||||
[ai]
|
||||
time_of_day=first_watch,second_watch
|
||||
attack_depth=9
|
||||
[attack_depth]
|
||||
turns=1-6
|
||||
value=7
|
||||
[/attack_depth]
|
||||
[/ai]
|
||||
) ()}
|
||||
|
||||
{AI_ASPECT_UNIT_TEST test_basic_standard_aspect attack_depth
|
||||
{SPLIT 7,7,7,7,7,7,7,7,7,7,7,7 ,
|
||||
} (
|
||||
[ai]
|
||||
[aspect]
|
||||
id=attack_depth
|
||||
name=standard_aspect
|
||||
value=7
|
||||
[/aspect]
|
||||
[/ai]
|
||||
) ()}
|
||||
|
||||
{AI_ASPECT_UNIT_TEST test_basic_composite_aspect attack_depth
|
||||
{SPLIT 5,5,14,14,14,14,5,5,5,5,12,12 ,}
|
||||
(
|
||||
[ai]
|
||||
[aspect]
|
||||
id=attack_depth
|
||||
[facet]
|
||||
time_of_day=first_watch,second_watch
|
||||
value=12
|
||||
[/facet]
|
||||
[facet]
|
||||
turns=3-6
|
||||
value=14
|
||||
[/facet]
|
||||
[/aspect]
|
||||
[/ai]
|
||||
) ()}
|
||||
|
||||
{AI_ASPECT_UNIT_TEST test_basic_lua_aspect attack_depth
|
||||
{SPLIT 2,4,6,8,10,12,14,16,18,20,22,24 ,}
|
||||
(
|
||||
[ai]
|
||||
[aspect]
|
||||
id=attack_depth
|
||||
engine=lua
|
||||
code=<<return wesnoth.current.turn * 2>>
|
||||
[/aspect]
|
||||
[/ai]
|
||||
) ()}
|
||||
|
||||
{AI_ASPECT_UNIT_TEST test_basic_composite_facet attack_depth
|
||||
{SPLIT 5,5,5,5,5,5,7,7,7,14,14,14 ,}
|
||||
(
|
||||
[ai]
|
||||
[aspect]
|
||||
id=attack_depth
|
||||
[facet]
|
||||
name=composite_aspect
|
||||
turns=7-12
|
||||
[facet]
|
||||
time_of_day=dusk,first_watch,second_watch
|
||||
value=14
|
||||
[/facet]
|
||||
[default]
|
||||
value=7
|
||||
[/default]
|
||||
[/facet]
|
||||
[/aspect]
|
||||
[/ai]
|
||||
) ()}
|
||||
|
||||
{AI_ASPECT_UNIT_TEST test_basic_lua_facet attack_depth
|
||||
{SPLIT 2,7,7,2,7,7,14,7,7,5,7,7 ,}
|
||||
(
|
||||
[ai]
|
||||
[aspect]
|
||||
id=attack_depth
|
||||
[facet]
|
||||
engine=lua
|
||||
time_of_day=dusk
|
||||
code=<<return wesnoth.current.turn / 2>>
|
||||
[/facet]
|
||||
[facet]
|
||||
engine=lua
|
||||
time_of_day=dawn
|
||||
code=<<return wesnoth.current.turn * 2>>
|
||||
[/facet]
|
||||
[default]
|
||||
value=7
|
||||
[/default]
|
||||
[/aspect]
|
||||
[/ai]
|
||||
) ()}
|
||||
|
||||
{AI_ASPECT_UNIT_TEST test_basic_composite_default_facet attack_depth
|
||||
{SPLIT 10,5,5,5,5,5,10,5,5,5,5,5 ,}
|
||||
(
|
||||
[ai]
|
||||
[aspect]
|
||||
id=attack_depth
|
||||
[default]
|
||||
name=composite_aspect
|
||||
[facet]
|
||||
id=my_composite_default_attack_depth
|
||||
time_of_day=dawn
|
||||
value=10
|
||||
[/facet]
|
||||
[default]
|
||||
value=5
|
||||
[/default]
|
||||
[/default]
|
||||
[/aspect]
|
||||
[/ai]
|
||||
) ()}
|
||||
|
||||
{AI_ASPECT_UNIT_TEST test_basic_lua_default_facet attack_depth
|
||||
{SPLIT 1,2,3,4,5,6,7,8,9,10,11,12 ,}
|
||||
(
|
||||
[ai]
|
||||
[aspect]
|
||||
id=attack_depth
|
||||
[default]
|
||||
engine=lua
|
||||
code=<<return wesnoth.current.turn>>
|
||||
[/default]
|
||||
[/aspect]
|
||||
[/ai]
|
||||
) ()}
|
223
data/test/scenarios/ai/modify/aspects.cfg
Normal file
223
data/test/scenarios/ai/modify/aspects.cfg
Normal file
|
@ -0,0 +1,223 @@
|
|||
|
||||
{AI_ASPECT_UNIT_TEST test_modify_ai_delete_facet attack_depth
|
||||
{SPLIT 7,7,7,7,7,7,5,5,5,5,5,5 ,}
|
||||
(
|
||||
[ai]
|
||||
[attack_depth]
|
||||
id=custom_depth
|
||||
value=7
|
||||
[/attack_depth]
|
||||
[/ai]
|
||||
) (
|
||||
[event]
|
||||
name=turn 6 end
|
||||
[modify_ai]
|
||||
action=delete
|
||||
path=aspect[attack_depth].facet[custom_depth]
|
||||
[/modify_ai]
|
||||
[/event]
|
||||
)}
|
||||
|
||||
{AI_ASPECT_UNIT_TEST test_modify_ai_change_facet attack_depth
|
||||
{SPLIT 7,7,7,7,7,7,8,8,8,8,8,8 ,}
|
||||
(
|
||||
[ai]
|
||||
[attack_depth]
|
||||
id=custom_depth
|
||||
value=7
|
||||
[/attack_depth]
|
||||
[/ai]
|
||||
) (
|
||||
[event]
|
||||
name=turn 6 end
|
||||
[modify_ai]
|
||||
action=change
|
||||
path=aspect[attack_depth].facet[custom_depth]
|
||||
[facet]
|
||||
value=8
|
||||
[/facet]
|
||||
[/modify_ai]
|
||||
[/event]
|
||||
)}
|
||||
|
||||
{AI_ASPECT_UNIT_TEST test_modify_ai_replace_facet attack_depth
|
||||
{SPLIT 7,7,7,7,8,8,8,8,5,5,5,5 ,}
|
||||
(
|
||||
[ai]
|
||||
[attack_depth]
|
||||
id=custom_depth
|
||||
value=7
|
||||
[/attack_depth]
|
||||
[/ai]
|
||||
) (
|
||||
[event]
|
||||
name=turn 4 end
|
||||
[modify_ai]
|
||||
action=add
|
||||
path=aspect[attack_depth].facet[]
|
||||
[facet]
|
||||
id=custom_depth
|
||||
value=8
|
||||
[/facet]
|
||||
[/modify_ai]
|
||||
[/event]
|
||||
[event]
|
||||
name=turn 8 end
|
||||
[modify_ai]
|
||||
action=delete
|
||||
path=aspect[attack_depth].facet[custom_depth]
|
||||
[/modify_ai]
|
||||
[/event]
|
||||
)}
|
||||
|
||||
{AI_ASPECT_UNIT_TEST test_modify_ai_add_facet attack_depth
|
||||
{SPLIT 7,7,7,7,8,8,8,8,7,7,7,7 ,}
|
||||
(
|
||||
[ai]
|
||||
[attack_depth]
|
||||
id=custom_depth
|
||||
value=7
|
||||
[/attack_depth]
|
||||
[/ai]
|
||||
) (
|
||||
[event]
|
||||
name=turn 4 end
|
||||
[modify_ai]
|
||||
action=add
|
||||
path=aspect[attack_depth].facet[]
|
||||
[facet]
|
||||
id=custom_depth2
|
||||
value=8
|
||||
[/facet]
|
||||
[/modify_ai]
|
||||
[/event]
|
||||
[event]
|
||||
name=turn 8 end
|
||||
[modify_ai]
|
||||
action=delete
|
||||
path=aspect[attack_depth].facet[custom_depth2]
|
||||
[/modify_ai]
|
||||
[/event]
|
||||
)}
|
||||
|
||||
{AI_ASPECT_UNIT_TEST test_modify_ai_change_default_facet attack_depth
|
||||
{SPLIT 5,5,5,5,7,7,7,7,8,8,8,8 ,}
|
||||
(
|
||||
[ai]
|
||||
[attack_depth]
|
||||
turns=5-8
|
||||
id=custom_depth
|
||||
value=7
|
||||
[/attack_depth]
|
||||
[/ai]
|
||||
) (
|
||||
[event]
|
||||
name=turn 6 end
|
||||
[modify_ai]
|
||||
action=change
|
||||
path=aspect[attack_depth].facet[*]
|
||||
[facet]
|
||||
value=8
|
||||
[/facet]
|
||||
[/modify_ai]
|
||||
[/event]
|
||||
)}
|
||||
|
||||
{AI_ASPECT_UNIT_TEST test_modify_ai_nested_facets attack_depth
|
||||
{SPLIT 5,7,7,14,14,14,12,7,7,14,14,5 ,}
|
||||
(
|
||||
[ai]
|
||||
[aspect]
|
||||
id=attack_depth
|
||||
[facet]
|
||||
id=composite_depth
|
||||
name=composite_aspect
|
||||
turns=2-11
|
||||
[facet]
|
||||
id=night_depth
|
||||
time_of_day=dusk,first_watch,second_watch
|
||||
value=14
|
||||
[/facet]
|
||||
[default]
|
||||
id=my_default_attack_depth
|
||||
value=7
|
||||
[/default]
|
||||
[/facet]
|
||||
[/aspect]
|
||||
[/ai]
|
||||
) (
|
||||
[event]
|
||||
name=turn 4 end
|
||||
[modify_ai]
|
||||
action=add
|
||||
path=aspect[attack_depth].facet[composite_depth].facet[]
|
||||
[facet]
|
||||
id=twilight_depth
|
||||
time_of_day=dawn,dusk
|
||||
value=12
|
||||
[/facet]
|
||||
[/modify_ai]
|
||||
[/event]
|
||||
[event]
|
||||
name=turn 8 end
|
||||
[modify_ai]
|
||||
action=delete
|
||||
path=aspect[attack_depth].facet[composite_depth].facet[twilight_depth]
|
||||
[/modify_ai]
|
||||
[/event]
|
||||
)}
|
||||
|
||||
{AI_ASPECT_UNIT_TEST test_modify_ai_composite_default_facets attack_depth
|
||||
{SPLIT 10,5,5,5,5,5,5,5,12,12,12,12 ,}
|
||||
(
|
||||
[ai]
|
||||
[aspect]
|
||||
id=attack_depth
|
||||
[default]
|
||||
name=composite_aspect
|
||||
[facet]
|
||||
id=dawn_default
|
||||
time_of_day=dawn
|
||||
value=10
|
||||
[/facet]
|
||||
[default]
|
||||
value=5
|
||||
[/default]
|
||||
[/default]
|
||||
[/aspect]
|
||||
[/ai]
|
||||
) (
|
||||
[event]
|
||||
name=turn 4 end
|
||||
[modify_ai]
|
||||
action=delete
|
||||
path=aspect[attack_depth].facet[default_facet].facet[dawn_default]
|
||||
[/modify_ai]
|
||||
[/event]
|
||||
[event]
|
||||
name=turn 8 end
|
||||
[modify_ai]
|
||||
action=add
|
||||
path=aspect[attack_depth].facet[default_facet].facet[]
|
||||
[facet]
|
||||
value=12
|
||||
[/facet]
|
||||
[/modify_ai]
|
||||
[/event]
|
||||
)}
|
||||
|
||||
{AI_ASPECT_UNIT_TEST test_modify_ai_change_aspect attack_depth
|
||||
{SPLIT 5,5,5,5,5,5,3,4,4,5,5,6 ,}
|
||||
() (
|
||||
[event]
|
||||
name=turn 6 end
|
||||
[modify_ai]
|
||||
action=change
|
||||
path=aspect[attack_depth]
|
||||
[aspect]
|
||||
engine=lua
|
||||
code=<<return math.floor(wesnoth.current.turn / 2)>>
|
||||
[/aspect]
|
||||
[/modify_ai]
|
||||
[/event]
|
||||
)}
|
|
@ -169,4 +169,23 @@
|
|||
0 forloop_array
|
||||
0 forloop_array_reverse
|
||||
0 forloop_step_large_positive
|
||||
0 forloop_step_large_negative
|
||||
0 forloop_step_large_negative
|
||||
# AI Config Parsing tests
|
||||
0 test_basic_simplified_aspect
|
||||
0 test_basic_abbreviated_aspect
|
||||
0 test_basic_standard_aspect
|
||||
0 test_basic_composite_aspect
|
||||
0 test_basic_lua_aspect
|
||||
0 test_basic_composite_facet
|
||||
0 test_basic_lua_facet
|
||||
0 test_basic_composite_default_facet
|
||||
0 test_basic_lua_default_facet
|
||||
# AI Modification tests
|
||||
0 test_modify_ai_delete_facet
|
||||
0 test_modify_ai_change_facet
|
||||
0 test_modify_ai_replace_facet
|
||||
0 test_modify_ai_add_facet
|
||||
0 test_modify_ai_change_default_facet
|
||||
0 test_modify_ai_nested_facets
|
||||
0 test_modify_ai_composite_default_facets
|
||||
0 test_modify_ai_change_aspect
|
Loading…
Add table
Reference in a new issue