Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
6840f56
FRLG AutoStory tests: the run plan cases in their own file
dayfine Nov 3, 2026
fe0abb8
Merge frlg/mt-moon-maps into frlg/autostory-run-plan-tests
dayfine Nov 3, 2026
1e2c0db
Merge frlg/mt-moon-maps into frlg/autostory-run-plan-tests
dayfine Nov 3, 2026
dcb2c4e
Merge frlg/mt-moon-maps into frlg/autostory-run-plan-tests
dayfine Nov 3, 2026
16c49a0
Merge frlg/mt-moon-maps into frlg/autostory-run-plan-tests
dayfine Nov 3, 2026
6571546
Merge frlg/mt-moon-maps into frlg/autostory-run-plan-tests
dayfine Nov 3, 2026
750158d
Merge frlg/mt-moon-maps (battle loop: end on the overworld after RUN …
dayfine Nov 3, 2026
88e56d3
Merge frlg/mt-moon-maps (walker: a battle's black after any leg, or b…
dayfine Nov 3, 2026
e0d7b69
Merge frlg/mt-moon-maps (a cave's floor closed on one side is wild) i…
dayfine Nov 3, 2026
ed10cea
Merge frlg/mt-moon-maps (a disabled move, and a move list that never …
dayfine Nov 3, 2026
26c45ba
Merge frlg/autostory-mvp (matchup attacks in every battle) into frlg/…
dayfine Nov 3, 2026
bdd6619
Merge frlg/mt-moon-maps (HP bar share, nurse for yellow HP, move prom…
dayfine Nov 3, 2026
79a4536
Merge frlg/mt-moon-maps (e6e78b98b: verify mode from #122) into frlg/…
dayfine Nov 3, 2026
5ae6e48
Merge frlg/mt-moon-maps (ab85eadde: battle sim from #120) into frlg/a…
dayfine Nov 3, 2026
1402d53
Merge frlg/mt-moon-maps into frlg/autostory-run-plan-tests
dayfine Nov 3, 2026
49c061f
Merge frlg/mt-moon-maps (the console's TEACH through the TM CASE) int…
dayfine Nov 3, 2026
b4ed1fa
Merge frlg/mt-moon-maps (GRIND until the boss is winnable; TEACH skip…
dayfine Nov 3, 2026
f301c00
Merge frlg/mt-moon-maps (GRIND/CAPTURE missed flash, TEACH after-forg…
dayfine Nov 3, 2026
4153647
Merge frlg/mt-moon-maps (bag rows below an item the reader can't name…
dayfine Nov 3, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,265 @@
/* AutoStory Run Plan Tests
*
* From: https://github.com/PokemonAutomation/
*
* Which rows of the story table a run takes (plan_story_run()) with the
* RNG programs' handoffs on and off, and the rows the handoffs split or
* join.
*
*/

#include <functional>
#include <string>
#include <string_view>
#include <vector>
#include "Common/Cpp/Exceptions.h"
#include "Common/Cpp/TestRunners/UnitTest.h"
#include "PokemonFRLG_AutoStoryTable.h"

namespace PokemonAutomation{
namespace NintendoSwitch{
namespace PokemonFRLG{


namespace{

class Test_AutoStory : public UnitTest{
public:
Test_AutoStory(std::string name, std::function<UnitTestResult()> body)
: UnitTest("PokemonFRLG::AutoStory - " + std::move(name))
, m_body(std::move(body))
{}
virtual UnitTestResult run(Logger&, CancellableScope&) const override{
try{
return m_body();
}catch (Exception& e){
return std::string(e.name()) + ": " + e.message();
}
}

private:
std::function<UnitTestResult()> m_body;
};


size_t row_index(std::string_view id){
const std::vector<StoryCheckpoint>& checkpoints = story_checkpoints();
for (size_t c = 0; c < checkpoints.size(); c++){
if (checkpoints[c].id == id){
return c;
}
}
throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, "No checkpoint " + std::string(id));
}

std::string joined_ids(const std::vector<StoryCheckpoint>& rows){
std::string text;
for (const StoryCheckpoint& row : rows){
text += (text.empty() ? "" : " ") + row.id;
}
return text;
}

const char* handoff_name(StoryHandoff handoff){
switch (handoff){
case StoryHandoff::NONE:
return "none";
case StoryHandoff::SID_HELPER:
return "SID Helper";
case StoryHandoff::STARTER_RNG:
return "Starter RNG";
case StoryHandoff::GIFT_RNG:
return "Gift RNG";
}
return "?";
}

struct RunPlanScenario{
std::string name = "";
std::string first = "";
// The table's last row if empty.
std::string last = "";
StoryHandoffs handoffs = {};
std::string expected_ids = "";
StoryHandoff expected_stop = StoryHandoff::NONE;
};

class Test_RunPlan : public UnitTest{
public:
Test_RunPlan(RunPlanScenario scenario)
: UnitTest("PokemonFRLG::AutoStory - run plan: " + scenario.name)
, m_scenario(std::move(scenario))
{}

virtual UnitTestResult run(Logger&, CancellableScope&) const override{
try{
const size_t last = m_scenario.last.empty() ? story_checkpoints().size() - 1 : row_index(m_scenario.last);
const StoryRunPlan plan = plan_story_run(story_checkpoints(), row_index(m_scenario.first), last, m_scenario.handoffs);
const std::string ids = joined_ids(plan.rows);
if (ids != m_scenario.expected_ids || plan.stop != m_scenario.expected_stop){
return "Expected rows \"" + m_scenario.expected_ids + "\", stop " + handoff_name(m_scenario.expected_stop)
+ "; got \"" + ids + "\", stop " + handoff_name(plan.stop) + ".";
}
return true;
}catch (Exception& e){
return std::string(e.name()) + ": " + e.message();
}
}

private:
const RunPlanScenario m_scenario;
};

void add_tests_RunPlan(UnitTestDatabase& database){

Check warning on line 113 in SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRunPlan_Tests.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

PokemonAutomation::NintendoSwitch::PokemonFRLG::add_tests_RunPlan( UnitTestDatabase & database): function_lines=43 (advisory above 25, limit 50)
const std::string TODAY = "00.01 00.02 00.03 00.04 00.05 00.06 00.07 00.08 00.09 00.10 00.11 00.12";
const RunPlanScenario scenarios[] = {
{.name = "handoffs off: the story as before", .first = "00.01", .expected_ids = TODAY},
{.name = "handoffs off: a range", .first = "00.02", .last = "00.04", .expected_ids = "00.02 00.03 00.04"},
{
.name = "SID Helper: 00.01 stops on the keyboard",
.first = "00.01",
.handoffs = {.sid_helper = true},
.expected_ids = "",
.expected_stop = StoryHandoff::SID_HELPER,
},
{
.name = "SID Helper: back in at 00.01b",
.first = "00.01b",
.last = "00.03",
.handoffs = {.sid_helper = true},
.expected_ids = "00.01b 00.02 00.03",
},
{.name = "00.01b runs when started at, option off", .first = "00.01b", .last = "00.02", .expected_ids = "00.01b 00.02"},
{.name = "SID Helper: a later start passes over it", .first = "00.02", .last = "00.03", .handoffs = {.sid_helper = true}, .expected_ids = "00.02 00.03"},
{.name = "handoffs off: an end at 00.04 still takes the rival's battle", .first = "00.03", .last = "00.04", .expected_ids = "00.03 00.04"},
{
.name = "Starter RNG: stops after 00.04's save",
.first = "00.02",
.handoffs = {.starter_rng = true},
.expected_ids = "00.02 00.03 00.04",
.expected_stop = StoryHandoff::STARTER_RNG,
},
{.name = "00.04b runs from its own save", .first = "00.04b", .last = "00.05", .expected_ids = "00.04b 00.05"},
{.name = "Starter RNG: a later start doesn't stop", .first = "00.05", .last = "00.06", .handoffs = {.starter_rng = true}, .expected_ids = "00.05 00.06"},
{
.name = "both handoffs, back in after SID Helper",
.first = "00.01b",
.handoffs = {.sid_helper = true, .starter_rng = true},
.expected_ids = "00.01b 00.02 00.03 00.04",
.expected_stop = StoryHandoff::STARTER_RNG,
},
};
for (const RunPlanScenario& scenario : scenarios){
database.add<Test_RunPlan>(scenario);
}
}

void add_tests_GiftRunPlan(UnitTestDatabase& database){

Check warning on line 157 in SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRunPlan_Tests.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

PokemonAutomation::NintendoSwitch::PokemonFRLG::add_tests_GiftRunPlan( UnitTestDatabase & database): function_lines=38 (advisory above 25, limit 50)
const RunPlanScenario scenarios[] = {
{
.name = "Gift RNG: stops after 00.12's save",
.first = "00.11",
.handoffs = {.gift_rng = true},
.expected_ids = "00.11 00.12",
.expected_stop = StoryHandoff::GIFT_RNG,
},
{.name = "Gift RNG off: 00.12b is passed over", .first = "00.11", .expected_ids = "00.11 00.12"},
{.name = "Gift RNG off: 00.12b runs when started at", .first = "00.12b", .expected_ids = "00.12b"},
{
.name = "Gift RNG: started at 00.12b, from the save beside the salesman",
.first = "00.12b",
.handoffs = {.gift_rng = true},
.expected_ids = "",
.expected_stop = StoryHandoff::GIFT_RNG,
},
{
.name = "Gift RNG: started at 00.12b with Starter RNG on too",
.first = "00.12b",
.handoffs = {.sid_helper = true, .starter_rng = true, .gift_rng = true},
.expected_ids = "",
.expected_stop = StoryHandoff::GIFT_RNG,
},
{.name = "Starter RNG alone: 00.12b runs when started at", .first = "00.12b", .handoffs = {.starter_rng = true}, .expected_ids = "00.12b"},
{
.name = "Starter RNG first, with both on",
.first = "00.03",
.handoffs = {.starter_rng = true, .gift_rng = true},
.expected_ids = "00.03 00.04",
.expected_stop = StoryHandoff::STARTER_RNG,
},
};
for (const RunPlanScenario& scenario : scenarios){
database.add<Test_RunPlan>(scenario);
}
}

std::string step_names(const StoryCheckpoint& checkpoint){
std::string text;
for (const StoryStep& step : checkpoint.steps){
text += (text.empty() ? "" : " ") + step.name;
}
return text;
}

// With Starter RNG's handoff off, 00.04 and 00.04b run as the one 00.04
// the story had before the split: from the lab's table to the rival's
// battle, saving once with the starter's START menu.
UnitTestResult test_starter_rows_joined(){

Check warning on line 207 in SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRunPlan_Tests.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

PokemonAutomation::NintendoSwitch::PokemonFRLG::test_starter_rows_joined(): function_lines=27 (advisory above 25, limit 50)
const std::vector<StoryCheckpoint>& checkpoints = story_checkpoints();
const StoryRunPlan plan = plan_story_run(checkpoints, row_index("00.04"), row_index("00.04b"), StoryHandoffs{});
const std::string expected_steps =
"below_squirtle squirtle_ball choose_squirtle no_nickname rival_takes_bulbasaur above_rival_trigger rival_trigger rival_battle";
if (plan.rows.size() != 1){
return "Expected one checkpoint, got \"" + joined_ids(plan.rows) + "\".";
}
const StoryCheckpoint& row = plan.rows[0];
if (row.id != "00.04" || row.title != "Squirtle, then the rival's battle" || step_names(row) != expected_steps){
return "Expected 00.04 \"Squirtle, then the rival's battle\": " + expected_steps
+ "; got " + row.id + " \"" + row.title + "\": " + step_names(row);
}
const std::optional<StoryPose> start = story_pose(*row.start);
if (!start || start->map != "PalletTown_ProfessorOaksLab" || !(start->tile == TilePos{6, 4}) || row.menu != StartMenu::BEFORE_POKEDEX){
return "Expected the joined 00.04 to start at the table (6, 4) and save with the starter's START menu.";
}
// Split, 00.04 saves under the ball facing it, before the starter.
const StoryCheckpoint& to_ball = checkpoints[row_index("00.04")];
const std::optional<StoryPose> ball = story_pose(*checkpoints[row_index("00.04b")].start);
if (to_ball.handoff != StoryHandoff::STARTER_RNG || to_ball.menu != StartMenu::BEFORE_POKEMON
|| !ball || !(ball->tile == TilePos{9, 5}) || ball->facing != Direction::NORTH
){
return "Expected 00.04 to end under Squirtle's ball (9, 5) facing north, saving before the starter.";
}
return true;
}

// The ways back in after SID Helper and Gift RNG load no save and start
// where 00.01 and 00.12 leave the player, so the rows after them follow
// unchanged.
UnitTestResult test_after_sid_helper_row(){
const StoryCheckpoint& sid = story_checkpoints()[row_index("00.01b")];
if (!sid.live_start || story_checkpoints()[0].handoff != StoryHandoff::SID_HELPER){
return "Expected 00.01 to be SID Helper's handoff and 00.01b to start from the live game.";
}
for (const StoryCheckpoint& checkpoint : story_checkpoints()){
if (checkpoint.live_start != (checkpoint.id == "00.01b" || checkpoint.id == "00.12b")){
return checkpoint.id + ": only 00.01b and 00.12b start from the live game.";
}
}
return true;
}

}


void add_tests_AutoStoryRunPlan(UnitTestDatabase& database){
add_tests_RunPlan(database);
add_tests_GiftRunPlan(database);
database.add<Test_AutoStory>("00.01b and 00.12b: back in after SID Helper and Gift RNG", test_after_sid_helper_row);
database.add<Test_AutoStory>("00.04 and 00.04b: one checkpoint with Starter RNG off", test_starter_rows_joined);
}



}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ const std::vector<StoryCheckpoint>& story_checkpoints();


void add_tests_AutoStory(UnitTestDatabase& database);
// Which rows a run takes (PokemonFRLG_AutoStoryRunPlan_Tests.cpp).
void add_tests_AutoStoryRunPlan(UnitTestDatabase& database);
// The table run end to end against a fake game (PokemonFRLG_AutoStorySimulation_Tests.cpp).
void add_tests_AutoStorySimulation(UnitTestDatabase& database);

Expand Down
Loading
Loading