Repository navigation
Max Lair: test the current boss inference (no behavior change) #171
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
9a2cb81
Max Lair: test the current boss inference through GlobalState helpers
dayfine 7e8668a
Max Lair: rename the boss helpers to accept_opponent() and boss_if_ca…
dayfine fd84076
Max Lair: decide boss_if_caught() from the battles won
dayfine 033c76e
SwSh Max Lair: mark the boss-state cases the next PR fixes
dayfine e819c82
SwSh Max Lair: word the boss-state notes as TODOs
dayfine 9575715
Merge origin/main into swsh/maxlair-boss-tests
dayfine 09e2b8c
Max Lair: add is_boss_battle() helper and rename slug to opponent_slug
dayfine aba7b2e
Merge remote-tracking branch 'origin/main' into swsh/maxlair-boss-tests
dayfine f6b95cd
SwSh MaxLair: move boss state tests to PokemonSwSh_MaxLair_State_Tests
dayfine aab7407
SwSh MaxLair: make BossStateTestCase a struct with input and expectat…
dayfine 4eb6d5a
SwSh MaxLair: move test case table to unnamed namespace for code health
dayfine e019799
Merge origin/main into swsh/maxlair-boss-tests
dayfine File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
133 changes: 133 additions & 0 deletions
133
...grams/Source/VideoGames/PokemonSwSh/MaxLair/Framework/PokemonSwSh_MaxLair_State_Tests.cpp
This file contains hidden or 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,133 @@ | ||
| /* Max Lair State Tests | ||
| * | ||
| * From: https://github.com/PokemonAutomation/ | ||
| * | ||
| */ | ||
|
|
||
| #include <format> | ||
| #include <utility> | ||
| #include "Common/Cpp/TestRunners/UnitTest.h" | ||
| #include "VideoGames/PokemonSwSh/MaxLair/Framework/PokemonSwSh_MaxLair_State.h" | ||
| #include "PokemonSwSh_MaxLair_State_Tests.h" | ||
|
|
||
| namespace PokemonAutomation{ | ||
| namespace NintendoSwitch{ | ||
| namespace PokemonSwSh{ | ||
| namespace MaxLairInternal{ | ||
| namespace{ | ||
|
|
||
| struct BossStateTestCaseInput{ | ||
| std::string name; | ||
| uint8_t wins; | ||
| std::set<std::string> opponent; | ||
| std::string boss; | ||
| uint8_t final_wins; // wins on the caught screen | ||
| }; | ||
|
|
||
| struct BossStateTestCaseExpectation{ | ||
| bool accepted; | ||
| std::string boss; | ||
| std::string boss_if_caught; | ||
| }; | ||
|
|
||
| struct BossStateTestCase{ | ||
| BossStateTestCaseInput input; | ||
| BossStateTestCaseExpectation expectation; | ||
| }; | ||
|
|
||
| class Test_MaxLairBossState : public UnitTest{ | ||
| public: | ||
| explicit Test_MaxLairBossState(BossStateTestCase scenario) | ||
| : UnitTest("PokemonSwSh::MaxLairBossState - " + scenario.input.name) | ||
| , m_scenario(std::move(scenario)) | ||
| {} | ||
|
|
||
| virtual UnitTestResult run(Logger&, CancellableScope&) const override{ | ||
| const BossStateTestCaseInput& input = m_scenario.input; | ||
| const BossStateTestCaseExpectation& expected = m_scenario.expectation; | ||
| GlobalState state; | ||
| state.wins = input.wins; | ||
| state.opponent = input.opponent; | ||
| state.boss = input.boss; | ||
| const bool accepted = state.accept_opponent(); | ||
| if (accepted != expected.accepted){ | ||
| return std::format("Expected opponent accepted={}, got {}", expected.accepted, accepted); | ||
| } | ||
| if (state.boss != expected.boss){ | ||
| return std::format("Expected boss '{}', got '{}'", expected.boss, state.boss); | ||
| } | ||
| state.wins = input.final_wins; | ||
| const std::string caught = state.boss_if_caught(); | ||
| if (caught != expected.boss_if_caught){ | ||
| return std::format("Expected boss_if_caught '{}', got '{}'", expected.boss_if_caught, caught); | ||
| } | ||
| return true; | ||
| } | ||
|
|
||
| private: | ||
| BossStateTestCase m_scenario; | ||
| }; | ||
|
|
||
| // Cases marked TODO record the current, wrong behaviour. | ||
| const BossStateTestCase CASES[] = { | ||
| { | ||
| .input = {.name = "rental before three wins", .wins = 2, .opponent = {"mimikyu-disguised"}, .boss = "", .final_wins = 3}, | ||
| .expectation = {.accepted = true, .boss = "", .boss_if_caught = ""}, | ||
| }, | ||
| // TODO: to be fixed: a rental at the boss stage is accepted as the boss and reported caught. | ||
| { | ||
| .input = {.name = "Mimikyu at boss stage", .wins = 3, .opponent = {"mimikyu-disguised"}, .boss = "", .final_wins = 3}, | ||
| .expectation = {.accepted = true, .boss = "mimikyu-disguised", .boss_if_caught = "mimikyu-disguised"}, | ||
| }, | ||
| // TODO: to be fixed: a rental misread as the boss is kept after the real boss is read. | ||
| { | ||
| .input = {.name = "Kyurem after Mimikyu misidentification", .wins = 3, .opponent = {"kyurem"}, .boss = "mimikyu-disguised", .final_wins = 3}, | ||
| .expectation = {.accepted = true, .boss = "mimikyu-disguised", .boss_if_caught = "mimikyu-disguised"}, | ||
| }, | ||
| // TODO: to be fixed: the boss is reported caught without a fourth win. | ||
| { | ||
| .input = {.name = "identified boss lost", .wins = 3, .opponent = {"kyurem"}, .boss = "kyurem", .final_wins = 3}, | ||
| .expectation = {.accepted = true, .boss = "kyurem", .boss_if_caught = "kyurem"}, | ||
| }, | ||
| { | ||
| .input = {.name = "identified boss caught", .wins = 3, .opponent = {"kyurem"}, .boss = "", .final_wins = 4}, | ||
| .expectation = {.accepted = true, .boss = "kyurem", .boss_if_caught = "kyurem"}, | ||
| }, | ||
| { | ||
| .input = {.name = "boss before three wins must retry", .wins = 2, .opponent = {"kyurem"}, .boss = "", .final_wins = 2}, | ||
| .expectation = {.accepted = false, .boss = "", .boss_if_caught = ""}, | ||
| }, | ||
| // TODO: to be fixed: a boss stage with no opponent read is accepted. | ||
| { | ||
| .input = {.name = "empty boss-stage read", .wins = 3, .opponent = {}, .boss = "", .final_wins = 3}, | ||
| .expectation = {.accepted = true, .boss = "", .boss_if_caught = ""}, | ||
| }, | ||
| // TODO: to be fixed: a two-candidate read is accepted and the first is taken as the boss. | ||
| { | ||
| .input = {.name = "ambiguous boss-stage read", .wins = 3, .opponent = {"kyurem", "mimikyu-disguised"}, .boss = "", .final_wins = 3}, | ||
| .expectation = {.accepted = true, .boss = "kyurem", .boss_if_caught = "kyurem"}, | ||
| }, | ||
| // TODO: to be fixed: a rental read at the boss stage is accepted, and the boss is reported caught without a fourth win. | ||
| { | ||
| .input = {.name = "rental read after known boss", .wins = 3, .opponent = {"mimikyu-disguised"}, .boss = "kyurem", .final_wins = 3}, | ||
| .expectation = {.accepted = true, .boss = "kyurem", .boss_if_caught = "kyurem"}, | ||
| }, | ||
| // TODO: to be fixed: a rental read at the boss stage is accepted and the rental is reported as the caught boss. | ||
| { | ||
| .input = {.name = "fourth win after rental boss", .wins = 3, .opponent = {"mimikyu-disguised"}, .boss = "mimikyu-disguised", .final_wins = 4}, | ||
| .expectation = {.accepted = true, .boss = "mimikyu-disguised", .boss_if_caught = "mimikyu-disguised"}, | ||
| }, | ||
| }; | ||
|
|
||
| } | ||
|
|
||
| void add_tests_MaxLairBossState(UnitTestDatabase& database){ | ||
| for (const BossStateTestCase& scenario : CASES){ | ||
| database.add<Test_MaxLairBossState>(scenario); | ||
| } | ||
| } | ||
|
|
||
| } | ||
| } | ||
| } | ||
| } |
25 changes: 25 additions & 0 deletions
25
...rograms/Source/VideoGames/PokemonSwSh/MaxLair/Framework/PokemonSwSh_MaxLair_State_Tests.h
This file contains hidden or 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,25 @@ | ||
| /* Max Lair State Tests | ||
| * | ||
| * From: https://github.com/PokemonAutomation/ | ||
| * | ||
| */ | ||
|
|
||
| #ifndef PokemonAutomation_PokemonSwSh_MaxLair_State_Tests_H | ||
| #define PokemonAutomation_PokemonSwSh_MaxLair_State_Tests_H | ||
|
|
||
| #include "Common/Cpp/TestRunners/UnitTestDatabase.h" | ||
|
|
||
| namespace PokemonAutomation{ | ||
| namespace NintendoSwitch{ | ||
| namespace PokemonSwSh{ | ||
| namespace MaxLairInternal{ | ||
|
|
||
|
|
||
| void add_tests_MaxLairBossState(UnitTestDatabase& database); | ||
|
|
||
|
|
||
| } | ||
| } | ||
| } | ||
| } | ||
| #endif |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.