Skip to content

Commit

Permalink
Add unit tests for check victory function
Browse files Browse the repository at this point in the history
Mainly focused on defeat_condition field right now... woudl be good
to add some that test victory_when_enemies_defeated.
  • Loading branch information
cbeck88 committed May 22, 2014
1 parent ca5ea80 commit d129d80
Show file tree
Hide file tree
Showing 3 changed files with 179 additions and 2 deletions.
2 changes: 1 addition & 1 deletion data/test/maps/move_skip_sighted.map
Expand Up @@ -4,7 +4,7 @@ Gg^Kov, Gg^Kov, Gg^Kov, Gg^Kov, Gg^Kov, Gg^Kov, 1 Gg^Kov, Gg^Kov, Gg^Kov, 3 Gg^K
Gg^Kov, Gg^Kov, Gg^Kov, Gg^Kov, Gg^Kov, Gg^Kov, Gg^Kov, Kha^Kov, Gg^Kov, Gg^Kov, Gg^Kov, Gg^Kov, Gg^Kov, Kha^Kov, Gg^Kov, Gg^Kov, 2 Gg^Kov, Gg^Kov
Gg^Kov, Gg^Kov, Gg^Kov, Gg^Kov, Gg^Kov, Gg^Kov, Gg^Kov, Cha^Kov, Gg^Kov, Gg^Kov, Gg^Kov, Gg^Kov, Gg^Kov, Cha^Kov, Gg^Kov, Gg^Kov, Gg^Kov, Gg^Kov
Gg^Kov, Gg^Kov, Gg^Kov, Gg^Kov, Gg^Kov, Gg^Kov, Gg^Kov, Gg^Kov, Gg^Kov, Gg^Kov, Gg^Kov, Gg^Kov, Gg^Kov, Gg^Kov, Gg^Kov, Gg^Kov, Gg^Kov, Gg^Kov
Gg^Kov, Gg^Kov, Gg^Kov, Chs^Kov, Gg^Kov, Chs^Kov, Gg^Kov, Ch^Kov, Gg^Kov, Ch^Kov, Gg^Kov, Chs^Kov, Gg^Kov, Ch^Kov, Gg^Kov, Ch^Kov, Gg^Kov, Gg^Kov
Gg^Kov, Gg^Kov, Gg^Kov, Chs^Kov, Gg^Kov, Chs^Kov, Gg^Kov, 4 Ch^Kov, Gg^Kov, Ch^Kov, Gg^Kov, Chs^Kov, Gg^Kov, Ch^Kov, Gg^Kov, Ch^Kov, Gg^Kov, Gg^Kov
Gg^Kov, Gg^Kov, Gg^Kov, Gg^Kov, Gg^Kov, Gg^Kov, Gg^Kov, Gg^Kov, Gg^Kov, Gg^Kov, Gg^Kov, Gg^Kov, Gg^Kov, Gg^Kov, Gg^Kov, Gg^Kov, Gg^Kov, Gg
Gg^Kov, Gg^Kov, Gg^Kov, Chs^Kov, Gg^Kov, Chs^Kov, Gg^Kov, Ch^Kov, Gg^Kov, Ch^Kov, Gg^Kov, Chs^Kov, Gg^Kov, Ch^Kov, Gg^Kov, Ch^Kov, Gg^Kov, Gg
Gg, Gg^Kov, Gg^Kov, Gg^Kov, Gg, Gg^Kov, Gg^Kov, Gg^Kov, Gg^Kov, Gg^Kov, Gg, Gg^Kov, Gg, Gg^Kov, Gg^Kov, Gg^Kov, Gg, Gg
150 changes: 150 additions & 0 deletions data/test/scenarios/test_check_victory.cfg
@@ -0,0 +1,150 @@
# This series of tests checks that scenarios are ending as appropriate.

#define TEST_CHECK_VICTORY_SCEN ID DC1 DC2 DC3 DC4 TWO_THREE_CONTROLLER VWED EVENTS
[test]
name = "Unit Test {ID}"
map_data = "{test/maps/move_skip_sighted.map}"
turns = 3
id = {ID}
random_start_time = no
victory_when_enemies_defeated = {VWED}

{DAWN}

[side]
side=1
controller=human
name = "Alice"
type = Elvish Archer
id=alice
fog=no
team_name=West
defeat_condition={DC1}
{UNIT 1 "Elvish Fighter" 1 1 (id=t1)}
[/side]
[side]
side=2
controller={TWO_THREE_CONTROLLER}
name = "Bob"
type = Orcish Grunt
id=bob
fog=no
team_name=East
defeat_condition={DC2}
{UNIT 2 "Orcish Archer" 1 2 (id=t2)}
[/side]
[side]
side=3
controller={TWO_THREE_CONTROLLER}
name = "Dave"
type = Dwarvish Fighter
id=dave
fog=no
team_name=East
defeat_condition={DC3}
{UNIT 3 "Dwarvish Thunderer" 1 3 (id=t3)}
[/side]
[side]
side=4
controller=human
name= "Charlie"
type = Chocobone
id=charlie
fog=no
team_name=West
defeat_condition={DC4}
{UNIT 4 "Dark Adept" 1 4 (id=t4)}
[/side]

{EVENTS}
[/test]
#enddef

#define KILL_ SIDE CR
[kill]
side={SIDE}
canrecruit={CR}
[/kill]
#enddef

#define FAIL_IF_NO_END ACTIONS
[event]
name=start
{ACTIONS}

[end_turn]
[/end_turn]
[/event]
[event]
name=side 2 turn 1
{RETURN ([false][/false])}
[/event]
#enddef

#define TEST_KILL_SIDES_TWO_THREE ID ID_yes ID_no ID_yesno DC1 DC2 DC3 DC4 CON VWED
{TEST_CHECK_VICTORY_SCEN ({ID} {ID_yes}) {DC1} {DC2} {DC3} {DC4} {CON} {VWED} (
{FAIL_IF_NO_END (
{KILL_ "2,3" "yes"} #kill leaders of side 2,3
)}
)}

{TEST_CHECK_VICTORY_SCEN ({ID} {ID_no}) {DC1} {DC2} {DC3} {DC4} {CON} {VWED} (
{FAIL_IF_NO_END (
{KILL_ "2,3" "no"} #kill units but not leaders of side 2,3
)}
)}

{TEST_CHECK_VICTORY_SCEN ({ID} {ID_yesno}) {DC1} {DC2} {DC3} {DC4} {CON} {VWED} (
{FAIL_IF_NO_END (
[kill]
side=2,3
[/kill]
)}
)}
#enddef

{TEST_CHECK_VICTORY_SCEN check_victory_basic_timeout "no_leader_left" "no_leader_left" "no_leader_left" "no_leader_left" "human" "yes" ()}
{TEST_CHECK_VICTORY_SCEN check_victory_basic_macro_check "no_leader_left" "no_leader_left" "no_leader_left" "no_leader_left" "human" "yes" ({FAIL_IF_NO_END ()})}

{TEST_KILL_SIDES_TWO_THREE check_victory_basic "" "_fail" "_two" "no_leader_left" "no_leader_left" "no_leader_left" "no_leader_left" "human" "yes"}
{TEST_KILL_SIDES_TWO_THREE check_victory_basic_ai "" "_fail" "_two" "no_leader_left" "no_leader_left" "no_leader_left" "no_leader_left" "ai" "yes"}

{TEST_KILL_SIDES_TWO_THREE check_victory_one_no_units "_fail_one" "_fail_two" "" "no_leader_left" "no_units_left" "no_leader_left" "no_leader_left" "human" "yes"}
{TEST_KILL_SIDES_TWO_THREE check_victory_two_no_units "_fail_one" "_fail_two" "" "no_leader_left" "no_units_left" "no_units_left" "no_leader_left" "human" "yes"}

{TEST_CHECK_VICTORY_SCEN check_victory_always_one "always" "no_leader_left" "no_leader_left" "always" "human" "yes" ()}
{TEST_CHECK_VICTORY_SCEN check_victory_always_two "always" "no_leader_left" "no_leader_left" "no_leader_left" "human" "yes" (
{FAIL_IF_NO_END (
{KILL_ "4" "yes"}
)}
)}
{TEST_CHECK_VICTORY_SCEN check_victory_always_no_units_fail "always" "no_leader_left" "no_leader_left" "no_units_left" "human" "yes" (
{FAIL_IF_NO_END (
{KILL_ "4" "yes"}
)}
)}
{TEST_CHECK_VICTORY_SCEN check_victory_always_no_units "always" "no_leader_left" "no_leader_left" "no_units_left" "human" "yes" (
{FAIL_IF_NO_END (
[kill]
side=4
[/kill]
)}
)}

{TEST_CHECK_VICTORY_SCEN check_victory_always_fail "always" "no_leader_left" "no_leader_left" "no_leader_left" "human" "yes" ({FAIL_IF_NO_END ()})}


{TEST_KILL_SIDES_TWO_THREE check_victory_never_fail "_one" "_two" "_three" "no_leader_left" "never" "no_leader_left" "no_leader_left" "human" "yes"}
{TEST_CHECK_VICTORY_SCEN check_victory_never_pass "no_leader_left" "always" "never" "no_leader_left" "human" "yes" (
{FAIL_IF_NO_END (
{KILL_ "1,4" "yes"}
)}
)}
{TEST_CHECK_VICTORY_SCEN check_victory_never_ai_fail "no_leader_left" "always" "never" "no_leader_left" "ai" "yes" (
{FAIL_IF_NO_END (
{KILL_ "1,4" "yes"}
)}
)}


# //TODO: Add checks for victory_when_enemies_defeated = no
29 changes: 28 additions & 1 deletion wml_test_schedule
Expand Up @@ -9,10 +9,37 @@
2 empty_test
4 break_replay_with_lua_random
0 fixed_lua_random_replay_with_sync_choice
0 test_end_turn
#
# Test Check Victory (If this isn't working other tests may have dubious value)
#
2 check_victory_basic_timeout
1 check_victory_basic_macro_check
0 check_victory_basic
1 check_victory_basic_fail
0 check_victory_basic_two
0 check_victory_basic_ai
1 check_victory_basic_ai_fail
0 check_victory_basic_ai_two
1 check_victory_one_no_units_fail_one
1 check_victory_one_no_units_fail_two
0 check_victory_one_no_units
1 check_victory_two_no_units_fail_one
1 check_victory_two_no_units_fail_two
0 check_victory_two_no_units
0 check_victory_always_one
0 check_victory_always_two
1 check_victory_always_no_units_fail
0 check_victory_always_no_units
1 check_victory_always_fail
1 check_victory_never_fail_one
1 check_victory_never_fail_two
1 check_victory_never_fail_three
0 check_victory_never_pass
1 check_victory_never_ai_fail
#
# WML API tests
#
0 test_end_turn
0 two_plus_two
1 two_plus_two_fail
0 order_of_nested_events
Expand Down

0 comments on commit d129d80

Please sign in to comment.