Skip to content
Merged
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
2 changes: 2 additions & 0 deletions SerialPrograms/Source/ComputerPrograms/UnitTestRunner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "CommonFramework/Tools/GlobalThreadPools.h"
#include "UnitTestRunner.h"

#include "PokemonHome/PokemonHome_Tests.h"
#include "PokemonSwSh/PokemonSwSh_Tests.h"
#include "PokemonLA/PokemonLA_Tests.h"
#include "PokemonSV/PokemonSV_Tests.h"
Expand All @@ -29,6 +30,7 @@ UnitTestDatabase make_UNIT_TESTS_ALL(){
UnitTestDatabase ret;

OCR::add_tests(ret);
NintendoSwitch::PokemonHome::add_tests(ret);
NintendoSwitch::PokemonSwSh::add_tests(ret);
NintendoSwitch::PokemonLA::add_tests(ret);
NintendoSwitch::PokemonSV::add_tests(ret);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/* Button Detector
*
* From: https://github.com/PokemonAutomation/
*
*/

#include <string>
#include "Common/Cpp/Color.h"
#include "CommonFramework/Globals.h"
#include "CommonFramework/ImageTypes/ImageRGB32.h"
#include "CommonFramework/ImageTypes/ImageViewRGB32.h"
#include "CommonFramework/VideoPipeline/VideoOverlay.h"
#include "CommonFramework/VideoPipeline/VideoOverlayScopes.h"
#include "PokemonHome/Inference/PokemonHome_ButtonDetector.h"
#include "PokemonHome_BoxViewDetector.h"
#include "Tests/TestUtils.h"

namespace PokemonAutomation{
namespace NintendoSwitch{
namespace PokemonHome{

BoxViewDetector::BoxViewDetector(VideoOverlay* overlay) : m_button_plus_detector(COLOR_BLACK, ButtonType::ButtonPlus, { 0.100, 0.956, 0.107, 0.041 }, overlay){}

void BoxViewDetector::make_overlays(VideoOverlaySet& items) const{
m_button_plus_detector.make_overlays(items);
}

bool BoxViewDetector::detect(const ImageViewRGB32& screen){
return m_button_plus_detector.detect(screen);
}



class Test_BoxViewDetector : public UnitTest{
public:

Test_BoxViewDetector(
const std::string& image,
bool expected
)
: UnitTest("PokemonHome::BoxViewDetector - " + image)
, m_image(UNIT_TEST_RESOURCE_PATH() + image)
, m_expected(expected)
{}

virtual UnitTestResult run(Logger& logger, CancellableScope& scope) const override{
DummyVideoOverlay overlay;
BoxViewDetector detector(&overlay);
ImageRGB32 image(m_image);
return detector.detect(image) == m_expected;
};

private:
std::string m_image;
bool m_expected;
};

void add_tests_BoxViewDetector(UnitTestDatabase& database){
database.add<Test_BoxViewDetector>("PokemonHome/BoxView/BoxView-1.png", true);
database.add<Test_BoxViewDetector>("PokemonHome/SummaryScreen/enamorus_Shiny.png", false);
database.add<Test_BoxViewDetector>("PokemonHome/SummaryScreen/machamp_Regular.png", false);
database.add<Test_BoxViewDetector>("PokemonHome/SummaryScreen/rowlet_ShinyAlpha.png", false);
}

}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/* Box View Detector
*
* From: https://github.com/PokemonAutomation/
*
*/

#ifndef PokemonAutomation_PokemonHome_BoxViewDetector_H
#define PokemonAutomation_PokemonHome_BoxViewDetector_H

#include "Common/Cpp/TestRunners/UnitTestDatabase.h"
#include "CommonFramework/VideoPipeline/VideoOverlayScopes.h"
#include "CommonTools/VisualDetector.h"
#include "PokemonHome/Inference/PokemonHome_ButtonDetector.h"

namespace PokemonAutomation{
class Logger;
namespace NintendoSwitch{
namespace PokemonHome{

class BoxViewDetector : public StaticScreenDetector{
public:
BoxViewDetector(VideoOverlay* overlay = nullptr);

virtual void make_overlays(VideoOverlaySet& items) const override;
virtual bool detect(const ImageViewRGB32& screen) override;

virtual void reset_state() override { m_button_plus_detector.reset_state(); }

private:
ButtonDetector m_button_plus_detector;

};
class BoxViewWatcher : public DetectorToFinder<BoxViewDetector>{
public:
BoxViewWatcher(VideoOverlay* overlay = nullptr)
: DetectorToFinder("BoxViewWatcher", Milliseconds(100), overlay)
{}
};

void add_tests_BoxViewDetector(UnitTestDatabase& database);

}
}
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -156,34 +156,6 @@ bool ButtonDetector::detect(const ImageViewRGB32& screen){
}


BoxViewDetector::BoxViewDetector(VideoOverlay* overlay) : m_button_plus_detector(COLOR_BLACK, ButtonType::ButtonPlus, {0.100, 0.956, 0.107, 0.041}, overlay){}

void BoxViewDetector::make_overlays(VideoOverlaySet& items) const{
m_button_plus_detector.make_overlays(items);
}

bool BoxViewDetector::detect(const ImageViewRGB32& screen){
return m_button_plus_detector.detect(screen);
}


SummaryScreenDetector::SummaryScreenDetector(VideoOverlay* overlay) : m_button_B_detector(COLOR_BLACK, ButtonType::ButtonB, {0.100, 0.956, 0.107, 0.041}, overlay){}

void SummaryScreenDetector::make_overlays(VideoOverlaySet& items) const{
m_button_B_detector.make_overlays(items);
}

bool SummaryScreenDetector::detect(const ImageViewRGB32& screen){
return m_button_B_detector.detect(screen);
}








}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,49 +64,6 @@ class ButtonWatcher : public DetectorToFinder<ButtonDetector>{
};


class BoxViewDetector : public StaticScreenDetector{
public:
BoxViewDetector(VideoOverlay* overlay = nullptr);

virtual void make_overlays(VideoOverlaySet& items) const override;
virtual bool detect(const ImageViewRGB32& screen) override;

virtual void reset_state() override { m_button_plus_detector.reset_state(); }

private:
ButtonDetector m_button_plus_detector;

};
class BoxViewWatcher : public DetectorToFinder<BoxViewDetector>{
public:
BoxViewWatcher(VideoOverlay* overlay = nullptr)
: DetectorToFinder("BoxViewWatcher", Milliseconds(100), overlay)
{}
};


class SummaryScreenDetector : public StaticScreenDetector{
public:
SummaryScreenDetector(VideoOverlay* overlay = nullptr);

virtual void make_overlays(VideoOverlaySet& items) const override;
virtual bool detect(const ImageViewRGB32& screen) override;

virtual void reset_state() override { m_button_B_detector.reset_state(); }

private:
ButtonDetector m_button_B_detector;

};
class SummaryScreenWatcher : public DetectorToFinder<SummaryScreenDetector>{
public:
SummaryScreenWatcher(VideoOverlay* overlay = nullptr)
: DetectorToFinder("SummaryScreenWatcher", Milliseconds(100), overlay)
{}
};



}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/* Button Detector
*
* From: https://github.com/PokemonAutomation/
*
*/

#include <string>
#include "CommonFramework/Globals.h"
#include "CommonFramework/VideoPipeline/VideoOverlayScopes.h"
#include "PokemonHome/Inference/PokemonHome_ButtonDetector.h"
#include "PokemonHome_SummaryScreenDetector.h"
#include "Tests/TestUtils.h"

namespace PokemonAutomation{
namespace NintendoSwitch{
namespace PokemonHome{


SummaryScreenDetector::SummaryScreenDetector(VideoOverlay* overlay)
: m_button_B_detector(COLOR_BLACK, ButtonType::ButtonB, { 0.100, 0.956, 0.107, 0.041 }, overlay){}

void SummaryScreenDetector::make_overlays(VideoOverlaySet& items) const{
m_button_B_detector.make_overlays(items);
}

bool SummaryScreenDetector::detect(const ImageViewRGB32& screen){
return m_button_B_detector.detect(screen);
}


class Test_SummaryScreenDetector : public UnitTest{
public:

Test_SummaryScreenDetector(
const std::string& image,
bool expected
)
: UnitTest("PokemonHome::SummaryScreenDetector - " + image)
, m_image(UNIT_TEST_RESOURCE_PATH() + image)
, m_expected(expected)
{}

virtual UnitTestResult run(Logger& logger, CancellableScope& scope) const override{
DummyVideoOverlay overlay;
SummaryScreenDetector detector(&overlay);
ImageRGB32 image(m_image);
return detector.detect(image) == m_expected;
};

private:
std::string m_image;
bool m_expected;
};

void add_tests_SummaryScreenDetector(UnitTestDatabase& database){
database.add<Test_SummaryScreenDetector>("PokemonHome/BoxView/BoxView-1.png", false);
database.add<Test_SummaryScreenDetector>("PokemonHome/SummaryScreen/enamorus_Shiny.png", true);
database.add<Test_SummaryScreenDetector>("PokemonHome/SummaryScreen/machamp_Regular.png", true);
database.add<Test_SummaryScreenDetector>("PokemonHome/SummaryScreen/rowlet_ShinyAlpha.png", true);
}

}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/* Summary Screen Detector
*
* From: https://github.com/PokemonAutomation/
*
*/

#ifndef PokemonAutomation_PokemonHome_SummaryScreenDetector_H
#define PokemonAutomation_PokemonHome_SummaryScreenDetector_H

#include "Common/Cpp/TestRunners/UnitTestDatabase.h"
#include "CommonFramework/VideoPipeline/VideoOverlayScopes.h"
#include "CommonTools/VisualDetector.h"
#include "PokemonHome/Inference/PokemonHome_ButtonDetector.h"

namespace PokemonAutomation{
class Logger;
namespace NintendoSwitch{
namespace PokemonHome{

class SummaryScreenDetector : public StaticScreenDetector{
public:
SummaryScreenDetector(VideoOverlay* overlay = nullptr);

virtual void make_overlays(VideoOverlaySet& items) const override;
virtual bool detect(const ImageViewRGB32& screen) override;

virtual void reset_state() override { m_button_B_detector.reset_state(); }

private:
ButtonDetector m_button_B_detector;

};
class SummaryScreenWatcher : public DetectorToFinder<SummaryScreenDetector>{
public:
SummaryScreenWatcher(VideoOverlay* overlay = nullptr)
: DetectorToFinder("SummaryScreenWatcher", Milliseconds(100), overlay)
{}
};

void add_tests_SummaryScreenDetector(UnitTestDatabase& database);

}
}
}
#endif
25 changes: 25 additions & 0 deletions SerialPrograms/Source/PokemonHome/PokemonHome_Tests.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/* Pokemon Home Tests
*
* From: https://github.com/PokemonAutomation/
*
*/

#include "Common/Cpp/TestRunners/UnitTestDatabase.h"
#include "Inference/PokemonHome_BoxViewDetector.h"
#include "Inference/PokemonHome_SummaryScreenDetector.h"
#include "PokemonHome_Tests.h"

namespace PokemonAutomation{
namespace NintendoSwitch{
namespace PokemonHome{


void add_tests(UnitTestDatabase& database){
add_tests_BoxViewDetector(database);
add_tests_SummaryScreenDetector(database);
}


}
}
}
25 changes: 25 additions & 0 deletions SerialPrograms/Source/PokemonHome/PokemonHome_Tests.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/* Pokemon Home Tests
*
* From: https://github.com/PokemonAutomation/
*
*/

#ifndef PokemonAutomation_PokemonHome_Tests_H
#define PokemonAutomation_PokemonHome_Tests_H

#include "Common/Cpp/TestRunners/UnitTestDatabase.h"

namespace PokemonAutomation{
namespace NintendoSwitch{
namespace PokemonHome{



void add_tests(UnitTestDatabase& database);



}
}
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,16 @@ language
#include "CommonFramework/ImageTools/ImageStats.h"
#include "CommonFramework/Notifications/ProgramNotifications.h"
#include "CommonFramework/ProgramStats/StatsTracking.h"
#include "CommonFramework/VideoPipeline/VideoOverlay.h"
#include "CommonFramework/VideoPipeline/VideoOverlayScopes.h"
#include "CommonTools/Async/InferenceRoutines.h"
#include "CommonTools/StartupChecks/StartProgramChecks.h"
#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h"
#include "Pokemon/Pokemon_Strings.h"
#include "Pokemon/Pokemon_BoxCursor.h"
#include "Pokemon/Pokemon_CollectedPokemonInfo.h"
#include "PokemonHome/Inference/PokemonHome_ButtonDetector.h"
#include "PokemonHome/Inference/PokemonHome_BoxViewDetector.h"
#include "PokemonHome/Inference/PokemonHome_SummaryScreenDetector.h"
#include "PokemonHome_BoxNavigation.h"
#include "PokemonHome_BoxSorter.h"

Expand Down
Loading
Loading