Skip to content

Commit ee14a33

Browse files
committed
Finish migrating PLA unit tests to new system.
1 parent 689abfc commit ee14a33

27 files changed

Lines changed: 657 additions & 783 deletions

SerialPrograms/Source/PokemonLA/Inference/Battles/PokemonLA_BattleSpriteWatcher.cpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,14 @@
66

77
#include <vector>
88
#include "Common/Cpp/Logging/AbstractLogger.h"
9+
#include "Common/Cpp/TestRunners/UnitTestDatabase.h"
10+
#include "CommonFramework/Globals.h"
911
#include "CommonFramework/GlobalSettingsPanel.h"
1012
#include "CommonFramework/ImageTypes/ImageViewRGB32.h"
1113
#include "CommonFramework/ImageTools/ImageStats.h"
1214
#include "CommonFramework/Tools/DebugDumper.h"
1315
#include "CommonFramework/VideoPipeline/VideoOverlayScopes.h"
16+
#include "Tests/TestUtils.h"
1417
#include "PokemonLA_BattleSpriteWatcher.h"
1518

1619
#include <iostream>
@@ -80,6 +83,49 @@ bool BattleSpriteWatcher::set_detected_sprites(const ImageViewRGB32& frame, std:
8083
}
8184

8285

86+
87+
88+
89+
90+
91+
class Test_BattleSpriteWatcher : public UnitTest{
92+
public:
93+
Test_BattleSpriteWatcher(
94+
const std::string& image,
95+
bool expected
96+
)
97+
: UnitTest("PokemonLA::BattleSpriteWatcher - " + image)
98+
, m_image(UNIT_TEST_RESOURCE_PATH() + image)
99+
, m_expected(expected)
100+
{}
101+
102+
virtual UnitTestResult run(Logger& logger, CancellableScope& scope) const override{
103+
DummyVideoOverlay overlay;
104+
BattleSpriteWatcher detector(logger, overlay);
105+
ImageRGB32 image(m_image);
106+
return detector.process_frame(image, current_time()) == m_expected;
107+
};
108+
109+
private:
110+
std::string m_image;
111+
bool m_expected;
112+
};
113+
114+
115+
116+
void add_tests_BattleSpriteWatcher(UnitTestDatabase& database){
117+
118+
}
119+
120+
121+
122+
123+
124+
125+
126+
127+
128+
83129
}
84130
}
85131
}

SerialPrograms/Source/PokemonLA/Inference/Battles/PokemonLA_BattleSpriteWatcher.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,13 @@ class BattleSpriteWatcher : public VisualInferenceCallback{
6262
};
6363

6464

65+
66+
67+
68+
void add_tests_BattleSpriteWatcher(UnitTestDatabase& database);
69+
70+
71+
6572
}
6673
}
6774
}

SerialPrograms/Source/PokemonLA/Inference/Battles/PokemonLA_BattleStartDetector.cpp

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@
44
*
55
*/
66

7+
#include "Common/Cpp/TestRunners/UnitTestDatabase.h"
8+
#include "CommonFramework/Globals.h"
79
#include "CommonFramework/ImageTypes/ImageViewRGB32.h"
810
#include "CommonFramework/ImageTools/ImageBoxes.h"
911
#include "CommonFramework/ImageTools/ImageStats.h"
1012
#include "CommonFramework/VideoPipeline/VideoOverlayScopes.h"
1113
#include "CommonTools/Images/ImageGradient.h"
14+
#include "Tests/TestUtils.h"
1215
#include "PokemonLA_BattleStartDetector.h"
1316

1417
//#include <iostream>
@@ -62,6 +65,50 @@ bool BattleStartDetector::process_frame(const ImageViewRGB32& frame, WallClock t
6265

6366

6467

68+
69+
70+
71+
72+
73+
74+
75+
76+
77+
class Test_BattleStartDetector : public UnitTest{
78+
public:
79+
Test_BattleStartDetector(
80+
const std::string& image,
81+
bool expected
82+
)
83+
: UnitTest("PokemonLA::BattleStartDetector - " + image)
84+
, m_image(UNIT_TEST_RESOURCE_PATH() + image)
85+
, m_expected(expected)
86+
{}
87+
88+
virtual UnitTestResult run(Logger& logger, CancellableScope& scope) const override{
89+
DummyVideoOverlay overlay;
90+
BattleStartDetector detector(logger, overlay);
91+
ImageRGB32 image(m_image);
92+
return detector.process_frame(image, current_time()) == m_expected;
93+
};
94+
95+
private:
96+
std::string m_image;
97+
bool m_expected;
98+
};
99+
100+
101+
102+
103+
void add_tests_BattleStartDetector(UnitTestDatabase& database){
104+
105+
}
106+
107+
108+
109+
110+
111+
65112
}
66113
}
67114
}

SerialPrograms/Source/PokemonLA/Inference/Battles/PokemonLA_BattleStartDetector.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
#ifndef PokemonAutomation_PokemonLA_BattleStartDetector_H
1010
#define PokemonAutomation_PokemonLA_BattleStartDetector_H
1111

12+
#include "Common/Cpp/TestRunners/UnitTest.h"
1213
#include "CommonFramework/ImageTools/ImageBoxes.h"
13-
#include "CommonFramework/Logging/Logger.h"
1414
#include "CommonFramework/VideoPipeline/VideoOverlay.h"
1515
#include "CommonTools/InferenceCallbacks/VisualInferenceCallback.h"
1616

@@ -35,6 +35,14 @@ class BattleStartDetector : public VisualInferenceCallback{
3535
};
3636

3737

38+
39+
40+
41+
void add_tests_BattleStartDetector(UnitTestDatabase& database);
42+
43+
44+
45+
3846
}
3947
}
4048
}

SerialPrograms/Source/PokemonLA/Inference/Map/PokemonLA_MapMarkerLocator.cpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,15 @@
66

77
#include <cfloat>
88
#include <cmath>
9+
#include "Common/Cpp/TestRunners/UnitTestDatabase.h"
910
#include "Kernels/Waterfill/Kernels_Waterfill_Session.h"
11+
#include "CommonFramework/Globals.h"
1012
#include "CommonFramework/ImageTypes/ImageRGB32.h"
1113
#include "CommonFramework/ImageTools/ImageStats.h"
1214
#include "CommonFramework/ImageTools/ImageBoxes.h"
1315
#include "CommonTools/Images/BinaryImage_FilterRgb32.h"
1416
#include "CommonTools/Images/WaterfillUtilities.h"
17+
#include "Tests/TestUtils.h"
1518
#include "PokemonLA_MapMarkerLocator.h"
1619

1720
#include <iostream>
@@ -133,6 +136,48 @@ double get_orientation_on_map(const ImageViewRGB32& screen, bool avoid_lava_area
133136

134137

135138

139+
140+
141+
142+
143+
144+
145+
146+
class Test_MapMarkerLocator : public UnitTest{
147+
public:
148+
Test_MapMarkerLocator(
149+
const std::string& image,
150+
float target_angle, float threshold
151+
)
152+
: UnitTest("PokemonLA::MapMarkerLocator - " + image)
153+
, m_image(UNIT_TEST_RESOURCE_PATH() + image)
154+
, m_target_angle(target_angle)
155+
, m_threshold(threshold)
156+
{}
157+
158+
virtual UnitTestResult run(Logger& logger, CancellableScope& scope) const override{
159+
ImageRGB32 image(m_image);
160+
float angle = get_orientation_on_map(image);
161+
TEST_RESULT_APPROXIMATE(angle, m_target_angle, m_threshold);
162+
return true;
163+
};
164+
165+
private:
166+
std::string m_image;
167+
float m_target_angle;
168+
float m_threshold;
169+
};
170+
171+
172+
173+
174+
void add_tests_MapMarkerLocator(UnitTestDatabase& database){
175+
176+
}
177+
178+
179+
180+
136181
}
137182
}
138183
}

SerialPrograms/Source/PokemonLA/Inference/Map/PokemonLA_MapMarkerLocator.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
#ifndef PokemonAutomation_PokemonLA_MapLocation_H
99
#define PokemonAutomation_PokemonLA_MapLocation_H
1010

11+
#include "Common/Cpp/TestRunners/UnitTest.h"
12+
1113
namespace PokemonAutomation{
1214
class ImageViewRGB32;
1315
namespace NintendoSwitch{
@@ -31,6 +33,11 @@ enum class MapRegion;
3133
double get_orientation_on_map(const ImageViewRGB32& screen, bool avoid_lava_area = false);
3234

3335

36+
37+
38+
void add_tests_MapMarkerLocator(UnitTestDatabase& database);
39+
40+
3441
}
3542
}
3643
}

SerialPrograms/Source/PokemonLA/Inference/Map/PokemonLA_MapMissionTabReader.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@
44
*
55
*/
66

7+
#include "Common/Cpp/TestRunners/UnitTestDatabase.h"
8+
#include "CommonFramework/Globals.h"
79
#include "CommonFramework/ImageTools/ImageStats.h"
810
#include "CommonFramework/ImageTools/ImageBoxes.h"
911
#include "CommonTools/Images/SolidColorTest.h"
12+
#include "Tests/TestUtils.h"
1013
#include "PokemonLA_MapMissionTabReader.h"
1114

1215
namespace PokemonAutomation{
@@ -22,6 +25,45 @@ bool is_map_mission_tab_raised(const ImageViewRGB32& screen){
2225
is_white(image_stats(extract_box_reference(screen, box1)));
2326
}
2427

28+
29+
30+
31+
32+
33+
34+
35+
36+
class Test_MapMissionTabReader : public UnitTest{
37+
public:
38+
Test_MapMissionTabReader(
39+
const std::string& image,
40+
bool expected
41+
)
42+
: UnitTest("PokemonLA::MapMissionTabReader - " + image)
43+
, m_image(UNIT_TEST_RESOURCE_PATH() + image)
44+
, m_expected(expected)
45+
{}
46+
47+
virtual UnitTestResult run(Logger& logger, CancellableScope& scope) const override{
48+
ImageRGB32 image(m_image);
49+
return is_map_mission_tab_raised(image) == m_expected;
50+
};
51+
52+
private:
53+
std::string m_image;
54+
bool m_expected;
55+
};
56+
57+
58+
59+
void add_tests_MapMissionTabReader(UnitTestDatabase& database){
60+
61+
}
62+
63+
64+
65+
66+
2567
}
2668
}
2769
}

SerialPrograms/Source/PokemonLA/Inference/Map/PokemonLA_MapMissionTabReader.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
#ifndef PokemonAutomation_PokemonLA_MapMissionTabReader_H
99
#define PokemonAutomation_PokemonLA_MapMissionTabReader_H
1010

11+
#include "Common/Cpp/TestRunners/UnitTest.h"
12+
1113
namespace PokemonAutomation{
1214
class ImageViewRGB32;
1315
namespace NintendoSwitch{
@@ -20,6 +22,14 @@ namespace PokemonLA{
2022
bool is_map_mission_tab_raised(const ImageViewRGB32& screen);
2123

2224

25+
26+
27+
28+
void add_tests_MapMissionTabReader(UnitTestDatabase& database);
29+
30+
31+
32+
2333
}
2434
}
2535
}

0 commit comments

Comments
 (0)