From f5b149b971bddb3068a6e4b930ff0bb2a0c3cb31 Mon Sep 17 00:00:00 2001 From: Martin Griffin Date: Thu, 12 Oct 2023 11:14:07 +0100 Subject: [PATCH] Test improvements (#3408) * Run assumptions on all runners * Make i const in battle tests This avoids the pitfall of using i in a PARAMETRIZEd test and confusing the runner. --- include/test/battle.h | 12 ++++++------ test/battle/move_effect/salt_cure.c | 5 +++-- test/battle/status1/bad_poison.c | 16 +++++++++------- test/battle/status1/burn.c | 5 +++-- test/battle/status1/poison.c | 5 +++-- test/battle/status1/sleep.c | 6 +++--- test/test_runner.c | 2 +- 7 files changed, 28 insertions(+), 23 deletions(-) diff --git a/include/test/battle.h b/include/test/battle.h index e1b00efbd..ead67ce32 100644 --- a/include/test/battle.h +++ b/include/test/battle.h @@ -472,8 +472,8 @@ enum { BATTLE_TEST_SINGLES, BATTLE_TEST_DOUBLES }; -typedef void (*SingleBattleTestFunction)(void *, u32, struct BattlePokemon *, struct BattlePokemon *); -typedef void (*DoubleBattleTestFunction)(void *, u32, struct BattlePokemon *, struct BattlePokemon *, struct BattlePokemon *, struct BattlePokemon *); +typedef void (*SingleBattleTestFunction)(void *, const u32, struct BattlePokemon *, struct BattlePokemon *); +typedef void (*DoubleBattleTestFunction)(void *, const u32, struct BattlePokemon *, struct BattlePokemon *, struct BattlePokemon *, struct BattlePokemon *); struct BattleTest { @@ -660,7 +660,7 @@ extern struct BattleTestRunnerState *gBattleTestRunnerState; #define SINGLE_BATTLE_TEST(_name, ...) \ struct CAT(Result, __LINE__) { MEMBERS(__VA_ARGS__) }; \ - static void CAT(Test, __LINE__)(struct CAT(Result, __LINE__) *, u32, struct BattlePokemon *, struct BattlePokemon *); \ + static void CAT(Test, __LINE__)(struct CAT(Result, __LINE__) *, const u32, struct BattlePokemon *, struct BattlePokemon *); \ __attribute__((section(".tests"))) static const struct Test CAT(sTest, __LINE__) = \ { \ .name = _name, \ @@ -674,11 +674,11 @@ extern struct BattleTestRunnerState *gBattleTestRunnerState; .resultsSize = sizeof(struct CAT(Result, __LINE__)), \ }, \ }; \ - static void CAT(Test, __LINE__)(struct CAT(Result, __LINE__) *results, u32 i, struct BattlePokemon *player, struct BattlePokemon *opponent) + static void CAT(Test, __LINE__)(struct CAT(Result, __LINE__) *results, const u32 i, struct BattlePokemon *player, struct BattlePokemon *opponent) #define DOUBLE_BATTLE_TEST(_name, ...) \ struct CAT(Result, __LINE__) { MEMBERS(__VA_ARGS__) }; \ - static void CAT(Test, __LINE__)(struct CAT(Result, __LINE__) *, u32, struct BattlePokemon *, struct BattlePokemon *, struct BattlePokemon *, struct BattlePokemon *); \ + static void CAT(Test, __LINE__)(struct CAT(Result, __LINE__) *, const u32, struct BattlePokemon *, struct BattlePokemon *, struct BattlePokemon *, struct BattlePokemon *); \ __attribute__((section(".tests"))) static const struct Test CAT(sTest, __LINE__) = \ { \ .name = _name, \ @@ -692,7 +692,7 @@ extern struct BattleTestRunnerState *gBattleTestRunnerState; .resultsSize = sizeof(struct CAT(Result, __LINE__)), \ }, \ }; \ - static void CAT(Test, __LINE__)(struct CAT(Result, __LINE__) *results, u32 i, struct BattlePokemon *playerLeft, struct BattlePokemon *opponentLeft, struct BattlePokemon *playerRight, struct BattlePokemon *opponentRight) + static void CAT(Test, __LINE__)(struct CAT(Result, __LINE__) *results, const u32 i, struct BattlePokemon *playerLeft, struct BattlePokemon *opponentLeft, struct BattlePokemon *playerRight, struct BattlePokemon *opponentRight) /* Parametrize */ diff --git a/test/battle/move_effect/salt_cure.c b/test/battle/move_effect/salt_cure.c index c24703fa2..b0b58c997 100644 --- a/test/battle/move_effect/salt_cure.c +++ b/test/battle/move_effect/salt_cure.c @@ -8,18 +8,19 @@ ASSUMPTIONS SINGLE_BATTLE_TEST("Salt Cure inflicts 1/8 of the target's maximum HP as damage per turn") { + u32 j; GIVEN { PLAYER(SPECIES_WOBBUFFET); OPPONENT(SPECIES_WOBBUFFET); } WHEN { TURN { MOVE(player, MOVE_SALT_CURE); } - for (i = 0; i < 3; i++) + for (j = 0; j < 3; j++) TURN {} } SCENE { s32 maxHP = GetMonData(&OPPONENT_PARTY[0], MON_DATA_MAX_HP); ANIMATION(ANIM_TYPE_MOVE, MOVE_SALT_CURE, player); MESSAGE("Foe Wobbuffet is being salt cured!"); - for (i = 0; i < 4; i++) { + for (j = 0; j < 4; j++) { ANIMATION(ANIM_TYPE_GENERAL, B_ANIM_SALT_CURE_DAMAGE, opponent); HP_BAR(opponent, damage: maxHP / 8); MESSAGE("Foe Wobbuffet is hurt by Salt Cure!"); diff --git a/test/battle/status1/bad_poison.c b/test/battle/status1/bad_poison.c index 7a430086b..2ee3f0527 100644 --- a/test/battle/status1/bad_poison.c +++ b/test/battle/status1/bad_poison.c @@ -3,21 +3,23 @@ SINGLE_BATTLE_TEST("Bad poison deals 1/16th cumulative damage per turn") { + u32 j; GIVEN { PLAYER(SPECIES_WOBBUFFET) { Status1(STATUS1_TOXIC_POISON); } OPPONENT(SPECIES_WOBBUFFET); } WHEN { - for (i = 0; i < 4; i++) + for (j = 0; j < 4; j++) TURN {} } SCENE { s32 maxHP = GetMonData(&PLAYER_PARTY[0], MON_DATA_MAX_HP); - for (i = 0; i < 4; i++) - HP_BAR(player, damage: maxHP / 16 * (i + 1)); + for (j = 0; j < 4; j++) + HP_BAR(player, damage: maxHP / 16 * (j + 1)); } } SINGLE_BATTLE_TEST("Bad poison cumulative damage resets on switch") { + u32 j; GIVEN { PLAYER(SPECIES_WOBBUFFET) { Status1(STATUS1_TOXIC_POISON); } PLAYER(SPECIES_WYNAUT); @@ -31,9 +33,9 @@ SINGLE_BATTLE_TEST("Bad poison cumulative damage resets on switch") TURN {} } SCENE { s32 maxHP = GetMonData(&PLAYER_PARTY[0], MON_DATA_MAX_HP); - for (i = 0; i < 2; i++) - HP_BAR(player, damage: maxHP / 16 * (i + 1)); - for (i = 0; i < 2; i++) - HP_BAR(player, damage: maxHP / 16 * (i + 1)); + for (j = 0; j < 2; j++) + HP_BAR(player, damage: maxHP / 16 * (j + 1)); + for (j = 0; j < 2; j++) + HP_BAR(player, damage: maxHP / 16 * (j + 1)); } } diff --git a/test/battle/status1/burn.c b/test/battle/status1/burn.c index 84439ec9e..77d58e5cc 100644 --- a/test/battle/status1/burn.c +++ b/test/battle/status1/burn.c @@ -3,16 +3,17 @@ SINGLE_BATTLE_TEST("Burn deals 1/16th damage per turn") { + u32 j; GIVEN { ASSUME(B_BURN_DAMAGE >= GEN_LATEST); PLAYER(SPECIES_WOBBUFFET) { Status1(STATUS1_BURN); } OPPONENT(SPECIES_WOBBUFFET); } WHEN { - for (i = 0; i < 4; i++) + for (j = 0; j < 4; j++) TURN {} } SCENE { s32 maxHP = GetMonData(&PLAYER_PARTY[0], MON_DATA_MAX_HP); - for (i = 0; i < 4; i++) + for (j = 0; j < 4; j++) HP_BAR(player, damage: maxHP / 16); } } diff --git a/test/battle/status1/poison.c b/test/battle/status1/poison.c index 771d0d2ec..12f6ffa95 100644 --- a/test/battle/status1/poison.c +++ b/test/battle/status1/poison.c @@ -3,15 +3,16 @@ SINGLE_BATTLE_TEST("Poison deals 1/8th damage per turn") { + u32 j; GIVEN { PLAYER(SPECIES_WOBBUFFET) { Status1(STATUS1_POISON); } OPPONENT(SPECIES_WOBBUFFET); } WHEN { - for (i = 0; i < 4; i++) + for (j = 0; j < 4; j++) TURN {} } SCENE { s32 maxHP = GetMonData(&PLAYER_PARTY[0], MON_DATA_MAX_HP); - for (i = 0; i < 4; i++) + for (j = 0; j < 4; j++) HP_BAR(player, damage: maxHP / 8); } } diff --git a/test/battle/status1/sleep.c b/test/battle/status1/sleep.c index 8ef6137d3..b3dd403eb 100644 --- a/test/battle/status1/sleep.c +++ b/test/battle/status1/sleep.c @@ -3,7 +3,7 @@ SINGLE_BATTLE_TEST("Sleep prevents the battler from using a move") { - u32 turns; + u32 turns, j; PARAMETRIZE { turns = 1; } PARAMETRIZE { turns = 2; } PARAMETRIZE { turns = 3; } @@ -11,10 +11,10 @@ SINGLE_BATTLE_TEST("Sleep prevents the battler from using a move") PLAYER(SPECIES_WOBBUFFET) { Status1(STATUS1_SLEEP_TURN(turns)); } OPPONENT(SPECIES_WOBBUFFET); } WHEN { - for (i = 0; i < turns; i++) + for (j = 0; j < turns; j++) TURN { MOVE(player, MOVE_CELEBRATE); } } SCENE { - for (i = 0; i < turns - 1; i++) + for (j = 0; j < turns - 1; j++) MESSAGE("Wobbuffet is fast asleep."); MESSAGE("Wobbuffet woke up!"); STATUS_ICON(player, none: TRUE); diff --git a/test/test_runner.c b/test/test_runner.c index 1469fad1f..7ca66ec08 100644 --- a/test/test_runner.c +++ b/test/test_runner.c @@ -88,7 +88,7 @@ static u32 AssignCostToRunner(void) u32 minCostProcess; if (gTestRunnerState.test->runner == &gAssumptionsRunner) - return 0; + return gTestRunnerI; minCostProcess = MinCostProcess();