Skip to content

Commit 9d64c40

Browse files
enpemeta-codesync[bot]
authored andcommitted
Add test for parameters of the stereo detector
Summary: As title. Reviewed By: janherling Differential Revision: D86154052 fbshipit-source-id: 9ff69783fdeb16ee530c531542f0468a0e622fb0
1 parent f9c52da commit 9d64c40

File tree

2 files changed

+166
-0
lines changed

2 files changed

+166
-0
lines changed

impl/ocean/test/testcv/testdetector/testbullseyes/TestBullseyeDetectorStereo.cpp

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ bool TestBullseyeDetectorStereo::test(const double testDuration)
4545

4646
bool allSucceeded = true;
4747

48+
allSucceeded = testParameters(testDuration, randomGenerator) && allSucceeded;
49+
50+
Log::info() << " ";
51+
Log::info() << " ";
52+
4853
allSucceeded = stressTestDetectBullseyes(testDuration, randomGenerator) && allSucceeded;
4954

5055
Log::info() << " ";
@@ -65,6 +70,12 @@ bool TestBullseyeDetectorStereo::test(const double testDuration)
6570

6671
} // namespace TestBullseyes
6772

73+
TEST(TestBullseyeDetectorStereo, Parameters)
74+
{
75+
RandomGenerator randomGenerator;
76+
EXPECT_TRUE(TestDetector::TestBullseyes::TestBullseyeDetectorStereo::testParameters(GTEST_TEST_DURATION, randomGenerator));
77+
}
78+
6879
TEST(TestBullseyeDetectorStereo, StressTestDetectBullseyes)
6980
{
7081
RandomGenerator randomGenerator;
@@ -76,6 +87,153 @@ namespace TestBullseyes
7687

7788
#endif // OCEAN_USE_GTEST
7889

90+
bool TestBullseyeDetectorStereo::testParameters(const double testDuration, RandomGenerator& randomGenerator)
91+
{
92+
ocean_assert(testDuration > 0.0);
93+
94+
Log::info() << "Parameters class test:";
95+
96+
bool allSucceeded = true;
97+
98+
const Timestamp startTimestamp(true);
99+
100+
do
101+
{
102+
// Test 1: Default constructor (verify inherits mono parameters correctly)
103+
{
104+
const BullseyeDetectorStereo::Parameters defaultParams;
105+
106+
// Verify the object is valid
107+
if (!defaultParams.isValid())
108+
{
109+
allSucceeded = false;
110+
}
111+
112+
// Verify inherited mono parameters have default values
113+
if (defaultParams.framePyramidPixelThreshold() != 640u * 480u)
114+
{
115+
allSucceeded = false;
116+
}
117+
118+
if (defaultParams.framePyramidLayers() != 3u)
119+
{
120+
allSucceeded = false;
121+
}
122+
123+
if (defaultParams.useAdaptiveRowSpacing() != true)
124+
{
125+
allSucceeded = false;
126+
}
127+
}
128+
129+
// Test 2: Static factory method (Parameters::defaultParameters())
130+
{
131+
const BullseyeDetectorStereo::Parameters factoryParams = BullseyeDetectorStereo::Parameters::defaultParameters();
132+
133+
// Verify the object is valid
134+
if (!factoryParams.isValid())
135+
{
136+
allSucceeded = false;
137+
}
138+
139+
// Verify it has the same values as default constructor
140+
if (factoryParams.framePyramidPixelThreshold() != 640u * 480u)
141+
{
142+
allSucceeded = false;
143+
}
144+
145+
if (factoryParams.framePyramidLayers() != 3u)
146+
{
147+
allSucceeded = false;
148+
}
149+
150+
if (factoryParams.useAdaptiveRowSpacing() != true)
151+
{
152+
allSucceeded = false;
153+
}
154+
}
155+
156+
// Test 3: Parameter modification (modify inherited mono parameters, verify changes persist)
157+
{
158+
BullseyeDetectorStereo::Parameters params;
159+
160+
// Modify framePyramidPixelThreshold
161+
const unsigned int newPixelThreshold = RandomI::random(randomGenerator, 100u, 1000000u);
162+
params.setFramePyramidPixelThreshold(newPixelThreshold);
163+
164+
if (params.framePyramidPixelThreshold() != newPixelThreshold)
165+
{
166+
allSucceeded = false;
167+
}
168+
169+
// Modify framePyramidLayers
170+
const unsigned int newLayers = RandomI::random(randomGenerator, 1u, 10u);
171+
params.setFramePyramidLayers(newLayers);
172+
173+
if (params.framePyramidLayers() != newLayers)
174+
{
175+
allSucceeded = false;
176+
}
177+
178+
// Modify useAdaptiveRowSpacing
179+
const bool newAdaptiveSpacing = RandomI::random(randomGenerator, 1u) == 1u;
180+
params.setUseAdaptiveRowSpacing(newAdaptiveSpacing);
181+
182+
if (params.useAdaptiveRowSpacing() != newAdaptiveSpacing)
183+
{
184+
allSucceeded = false;
185+
}
186+
187+
// Verify still valid after modifications
188+
if (!params.isValid())
189+
{
190+
allSucceeded = false;
191+
}
192+
}
193+
194+
// Test 4: Inheritance verification (verify all BullseyeDetectorMono::Parameters members accessible)
195+
{
196+
BullseyeDetectorStereo::Parameters stereoParams;
197+
198+
// Test that we can use it as a BullseyeDetectorMono::Parameters
199+
const BullseyeDetectorMono::Parameters& monoParamsRef = stereoParams;
200+
201+
// Verify mono parameters are accessible through the reference
202+
if (!monoParamsRef.isValid())
203+
{
204+
allSucceeded = false;
205+
}
206+
207+
if (monoParamsRef.framePyramidPixelThreshold() != stereoParams.framePyramidPixelThreshold())
208+
{
209+
allSucceeded = false;
210+
}
211+
212+
if (monoParamsRef.framePyramidLayers() != stereoParams.framePyramidLayers())
213+
{
214+
allSucceeded = false;
215+
}
216+
217+
if (monoParamsRef.useAdaptiveRowSpacing() != stereoParams.useAdaptiveRowSpacing())
218+
{
219+
allSucceeded = false;
220+
}
221+
}
222+
}
223+
while (startTimestamp + testDuration > Timestamp(true));
224+
225+
if (allSucceeded)
226+
{
227+
Log::info() << "Validation: succeeded.";
228+
}
229+
else
230+
{
231+
Log::info() << "Validation: FAILED!";
232+
}
233+
234+
return allSucceeded;
235+
}
236+
79237
bool TestBullseyeDetectorStereo::stressTestDetectBullseyes(const double testDuration, RandomGenerator& randomGenerator)
80238
{
81239
ocean_assert(testDuration > 0.0);

impl/ocean/test/testcv/testdetector/testbullseyes/TestBullseyeDetectorStereo.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,14 @@ class OCEAN_TEST_CV_DETECTOR_BULLSEYES_EXPORT TestBullseyeDetectorStereo
5050
* @return True, if succeeded
5151
*/
5252
static bool stressTestDetectBullseyes(const double testDuration, RandomGenerator& randomGenerator);
53+
54+
/**
55+
* Tests the Parameters class.
56+
* @param testDuration The duration in seconds for which this test will be run, must be > 0.0
57+
* @param randomGenerator A random generator that will be used to generate test data
58+
* @return True, if succeeded
59+
*/
60+
static bool testParameters(const double testDuration, RandomGenerator& randomGenerator);
5361
};
5462

5563
} // namespace TestBullseyes

0 commit comments

Comments
 (0)