Skip to content

Commit 0b2e543

Browse files
author
Gin
committed
Add selection arrow tests
1 parent 70e5021 commit 0b2e543

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

SerialPrograms/Source/Tests/PokemonLZA_Tests.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "NintendoSwitch/NintendoSwitch_ConsoleHandle.h"
1515
#include "PokemonLZA/Inference/PokemonLZA_DialogDetector.h"
1616
#include "PokemonLZA/Inference/PokemonLZA_ButtonDetector.h"
17+
#include "PokemonLZA/Inference/PokemonLZA_SelectionArrowDetector.h"
1718
#include "PokemonLZA/Inference/PokemonLZA_MainMenuDetector.h"
1819
#include "PokemonLZA/Inference/Boxes/PokemonLZA_BoxDetection.h"
1920
#include "PokemonLZA/Inference/Boxes/PokemonLZA_BoxInfoDetector.h"
@@ -122,6 +123,42 @@ int test_pokemonLZA_MainMenuDetector(const ImageViewRGB32& image, bool target){
122123
return 0;
123124
}
124125

126+
int test_pokemonLZA_SelectionArrowDetector(const ImageViewRGB32& image, const std::vector<std::string>& words){
127+
// two words: <situation> <True/False>
128+
if (words.size() < 2){
129+
cerr << "Error: not enough number of words in the filename. Found only " << words.size() << "." << endl;
130+
return 1;
131+
}
132+
133+
// Parse situation from second to last word
134+
const std::string& situation_str = words[words.size() - 2];
135+
SelectionArrowType arrow_type;
136+
ImageFloatBox search_box;
137+
138+
if (situation_str == "Fossil"){
139+
arrow_type = SelectionArrowType::RIGHT;
140+
search_box = ImageFloatBox(0.6300, 0.4440, 0.2260, 0.3190);
141+
}else{
142+
cerr << "Error: unknown situation '" << situation_str << "' in filename." << endl;
143+
return 1;
144+
}
145+
146+
// Parse True/False from last word
147+
bool target = false;
148+
if (parse_bool(words[words.size() - 1], target) == false){
149+
cerr << "Error: last word in filename should be True or False." << endl;
150+
return 1;
151+
}
152+
153+
// Run detector with the specified search box and arrow type
154+
auto overlay = DummyVideoOverlay();
155+
SelectionArrowDetector detector(COLOR_RED, &overlay, arrow_type, search_box);
156+
bool result = detector.detect(image);
157+
158+
TEST_RESULT_EQUAL(result, target);
159+
return 0;
160+
}
161+
125162
int test_pokemonLZA_BoxCellInfoDetector(const ImageViewRGB32& image, const std::vector<std::string>& words){
126163
// Expected filename format: <...>_<row>_<col>_<status>.png
127164
// Where status is one of: Empty, Shiny, Alpha, ShinyAlpha

SerialPrograms/Source/Tests/PokemonLZA_Tests.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929

3030
int test_pokemonLZA_MainMenuDetector(const ImageViewRGB32& image, bool target);
3131

32+
int test_pokemonLZA_SelectionArrowDetector(const ImageViewRGB32& image, const std::vector<std::string>& words);
33+
3234
int test_pokemonLZA_BoxCellInfoDetector(const ImageViewRGB32& image, const std::vector<std::string>& words);
3335

3436
}

SerialPrograms/Source/Tests/TestMap.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@ const std::map<std::string, TestFunction> TEST_MAP = {
294294
{"PokemonLZA_ButtonDetector", std::bind(image_words_detector_helper, test_pokemonLZA_ButtonDetector, _1)},
295295
{"PokemonLZA_MainMenuDetector", std::bind(image_bool_detector_helper, test_pokemonLZA_MainMenuDetector, _1)},
296296
{"PokemonLZA_BoxCellInfoDetector", std::bind(image_words_detector_helper, test_pokemonLZA_BoxCellInfoDetector, _1)},
297+
{"PokemonLZA_SelectionArrowDetector", std::bind(image_words_detector_helper, test_pokemonLZA_SelectionArrowDetector, _1)},
297298
};
298299

299300
TestFunction find_test_function(const std::string& test_space, const std::string& test_name){

0 commit comments

Comments
 (0)