Skip to content

Commit

Permalink
gapi: eliminate std::rand() and RAND_MAX from tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alalek committed Nov 26, 2020
1 parent d65c6af commit 7afd486
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
7 changes: 4 additions & 3 deletions modules/gapi/test/common/gapi_parsers_tests_common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ class ParserSSDTest
int randInRange(const int start, const int end)
{
GAPI_Assert(start <= end);
return start + std::rand() % (end - start + 1);
return theRNG().uniform(start, end);
}

cv::Rect generateBox(const cv::Size& in_sz)
Expand Down Expand Up @@ -211,7 +211,7 @@ class ParserSSDTest
SSDitem it;
it.image_id = static_cast<float>(i);
it.label = static_cast<float>(randInRange(0, 9));
it.confidence = static_cast<float>(std::rand()) / RAND_MAX;
it.confidence = theRNG().uniform(0.f, 1.f);
auto box = generateBox(in_sz);
it.rc_left = normalize(box.x, in_sz.width);
it.rc_right = normalize(box.x + box.width, in_sz.width);
Expand Down Expand Up @@ -245,9 +245,10 @@ class ParserYoloTest
auto data = mat.ptr<float>();

const size_t range = std::accumulate(dims.begin(), dims.end(), 1, std::multiplies<int>());
cv::RNG& rng = theRNG();
for (size_t i = 0; i < range; ++i)
{
data[i] = static_cast<float>(std::rand()) / RAND_MAX;
data[i] = rng.uniform(0.f, 1.f);
}
return mat;
}
Expand Down
4 changes: 2 additions & 2 deletions modules/gapi/test/rmat/rmat_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,11 @@ class RMatAdapterForBackend : public RMat::Adapter {
// we have some specific data hidden under RMat,
// test that we can obtain it via RMat.as<T>() method
TEST(RMat, UsageInBackend) {
int i = std::rand();
int i = 123456;
auto rmat = cv::make_rmat<RMatAdapterForBackend>(i);

auto adapter = rmat.get<RMatAdapterForBackend>();
EXPECT_NE(nullptr, adapter);
ASSERT_NE(nullptr, adapter);
EXPECT_EQ(i, adapter->deviceSpecificData());
}
} // namespace opencv_test
3 changes: 3 additions & 0 deletions modules/gapi/test/test_precomp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,7 @@ static inline void countNonZero_is_forbidden_in_tests_use_norm_instead() {}
}
#define countNonZero() countNonZero_is_forbidden_in_tests_use_norm_instead()

#undef RAND_MAX
#define RAND_MAX RAND_MAX_is_banned_in_tests__use_cv_theRNG_instead

#endif // __OPENCV_GAPI_TEST_PRECOMP_HPP__

0 comments on commit 7afd486

Please sign in to comment.