Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
@@ -1,4 +1,4 @@
/* Pokemon SV BBQ Tests

Check warning on line 1 in SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQTests.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

<file>: file_lines=809 (advisory above 500, limit 1000)
*
* From: https://github.com/PokemonAutomation/
*
Expand Down Expand Up @@ -495,6 +495,128 @@
const BBQuestPlanScenario m_scenario;
};


// A quest panel with a cursor. A reroll replaces the quest under the cursor
// with the next of `replacements`, unless out of BP.
class SimulatedQuestPanel : public BBQRerollActions{

Check warning on line 501 in SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQTests.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

PokemonAutomation::NintendoSwitch::PokemonSV::SimulatedQuestPanel: public_methods=7 (advisory above 5, limit 7)
public:
std::vector<BBQuests> quests;
std::vector<BBQuests> replacements;
size_t cursor = 0;
bool panel_opens = true;
bool menu_seen = true;
bool out_of_bp = false;
int missed_reads = 0; // Reads that fail OCR on every slot.

bool panel_open = false;
bool menu_open = false;
std::vector<size_t> rerolled_slots;

virtual bool open_panel() override{
panel_open = panel_opens;
return panel_open;
}
virtual std::optional<size_t> open_reroll_menu() override{
menu_open = true;
if (!menu_seen){
return std::nullopt;
}
return cursor;
}
virtual void close_reroll_menu() override{
menu_open = false;
}
virtual void move_cursor(int slots) override{
cursor = (size_t)((int)cursor + slots);
}
virtual void confirm_reroll() override{
menu_open = false;
if (out_of_bp){
return;
}
rerolled_slots.push_back(cursor);
quests[cursor] = replacements[rerolled_slots.size() - 1];
}
virtual void close_panel() override{
panel_open = false;
menu_open = false;
}
virtual std::vector<BBQuests> read_quests() override{
if (missed_reads > 0){
missed_reads--;
return std::vector<BBQuests>(quests.size(), BBQuests::UnableToDetect);
}
return quests;
}
};

struct BBQRerollScenario{
std::string name;
std::vector<BBQuests> quests;
std::vector<BBQuests> replacements = {};
size_t slot;
size_t cursor = 0;
bool panel_opens = true;
bool menu_seen = true;
bool out_of_bp = false;
int missed_reads = 0;
BBQRerollResult expected;
std::vector<size_t> expected_rerolled_slots = {};
std::vector<BBQuests> expected_quests;
};

std::string reroll_result_to_string(BBQRerollResult result){
switch (result){
case BBQRerollResult::Rerolled: return "Rerolled";
case BBQRerollResult::PanelNotOpened: return "PanelNotOpened";
case BBQRerollResult::MenuNotFound: return "MenuNotFound";
case BBQRerollResult::NotReplaced: return "NotReplaced";
}
return "?";
}

class Test_BBQReroll : public UnitTest{
public:
Test_BBQReroll(BBQRerollScenario scenario)
: UnitTest("PokemonSV::BBQReroll - " + scenario.name)
, m_scenario(std::move(scenario))
{}

virtual UnitTestResult run(Logger&, CancellableScope&) const override{

Check warning on line 585 in SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQTests.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

PokemonAutomation::NintendoSwitch::PokemonSV::Test_BBQReroll::run( Logger & , CancellableScope &) const: function_lines=30 (advisory above 25, limit 50)
SimulatedQuestPanel panel;
panel.quests = m_scenario.quests;
panel.replacements = m_scenario.replacements;
panel.cursor = m_scenario.cursor;
panel.panel_opens = m_scenario.panel_opens;
panel.menu_seen = m_scenario.menu_seen;
panel.out_of_bp = m_scenario.out_of_bp;
panel.missed_reads = m_scenario.missed_reads;

NullLogger logger;
std::vector<BBQuests> quests = m_scenario.quests;
const BBQRerollResult result = reroll_quest(logger, panel, quests, m_scenario.slot);
if (result != m_scenario.expected){
return "Expected " + reroll_result_to_string(m_scenario.expected)
+ ", got " + reroll_result_to_string(result);
}
if (panel.rerolled_slots != m_scenario.expected_rerolled_slots){
return "Expected rerolled slots: " + slots_to_string(m_scenario.expected_rerolled_slots)
+ "got: " + slots_to_string(panel.rerolled_slots);
}
if (quests != m_scenario.expected_quests){
return "Expected quests: " + quests_to_string(m_scenario.expected_quests)
+ "got: " + quests_to_string(quests);
}
if (panel.panel_open || panel.menu_open){
return "Panel left open.";
}
return true;
}

private:
const BBQRerollScenario m_scenario;
};

}

static void add_tests_BBQuestPlan(UnitTestDatabase& database){
Expand Down Expand Up @@ -568,6 +690,100 @@
}
}

static void add_tests_BBQReroll(UnitTestDatabase& database){

Check failure on line 693 in SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQTests.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health

PokemonAutomation::NintendoSwitch::PokemonSV::add_tests_BBQReroll( UnitTestDatabase & database): function_lines=92, limit=50, allowed 50
using enum BBQuests;
const BBQRerollScenario scenarios[] = {
{
.name = "cursor on the top quest",
.quests = {make_tm, sneak_up, travel_500},
.replacements = {catch_any},
.slot = 2,
.expected = BBQRerollResult::Rerolled,
.expected_rerolled_slots = {2},
.expected_quests = {make_tm, sneak_up, catch_any},
},
{
// Seen on a Switch: the panel can open with the cursor where it
// was left, so moving down from the top rerolls the wrong quest.
.name = "cursor left below the quest moves up",
.quests = {make_tm, travel_500, sneak_up, hatch_egg},
.replacements = {catch_any},
.slot = 1,
.cursor = 3,
.expected = BBQRerollResult::Rerolled,
.expected_rerolled_slots = {1},
.expected_quests = {make_tm, catch_any, sneak_up, hatch_egg},
},
{
.name = "fourth quest",
.quests = {make_tm, travel_500, sneak_up, hatch_egg},
.replacements = {catch_any},
.slot = 3,
.expected = BBQRerollResult::Rerolled,
.expected_rerolled_slots = {3},
.expected_quests = {make_tm, travel_500, sneak_up, catch_any},
},
{
.name = "panel not opened spends nothing",
.quests = {make_tm, sneak_up, travel_500},
.slot = 2,
.panel_opens = false,
.expected = BBQRerollResult::PanelNotOpened,
.expected_quests = {make_tm, sneak_up, travel_500},
},
{
.name = "menu not seen spends nothing",
.quests = {make_tm, sneak_up, travel_500},
.slot = 2,
.menu_seen = false,
.expected = BBQRerollResult::MenuNotFound,
.expected_quests = {make_tm, sneak_up, travel_500},
},
{
.name = "out of BP is not replaced",
.quests = {make_tm, sneak_up, travel_500},
.slot = 2,
.out_of_bp = true,
.expected = BBQRerollResult::NotReplaced,
.expected_quests = {make_tm, sneak_up, travel_500},
},
{
.name = "a missed read is read again",
.quests = {make_tm, sneak_up, travel_500},
.replacements = {catch_any},
.slot = 2,
.missed_reads = 2,
.expected = BBQRerollResult::Rerolled,
.expected_rerolled_slots = {2},
.expected_quests = {make_tm, sneak_up, catch_any},
},
{
.name = "three missed reads give up",
.quests = {make_tm, sneak_up, travel_500},
.replacements = {catch_any},
.slot = 2,
.missed_reads = 3,
.expected = BBQRerollResult::NotReplaced,
.expected_rerolled_slots = {2},
.expected_quests = {make_tm, sneak_up, travel_500},
},
{
// Cannot be told apart from out of BP.
.name = "replaced by the same quest is not replaced",
.quests = {make_tm, sneak_up, travel_500},
.replacements = {travel_500},
.slot = 2,
.expected = BBQRerollResult::NotReplaced,
.expected_rerolled_slots = {2},
.expected_quests = {make_tm, sneak_up, travel_500},
},
};
for (const BBQRerollScenario& scenario : scenarios){
database.add<Test_BBQReroll>(scenario);
}
}



void add_tests_BBQ(UnitTestDatabase& database){
database.add<Test_BBQuestsSlugs>();
Expand All @@ -580,6 +796,7 @@
database.add<Test_BlueberryPoints>("PokemonSV/BlueberryPoints/6740.png", 6740, 1920, 1080);
database.add<Test_BlueberryPoints>("PokemonSV/BlueberryPoints/6740.png", 6740, 1280, 720);

add_tests_BBQReroll(database);
add_tests_BBQuestPlan(database);
add_tests_BBQFarmerRounds(database);
add_tests_TeraEncounterAction(database);
Expand Down
Loading
Loading