diff --git a/modules/core/test/test_arithm.cpp b/modules/core/test/test_arithm.cpp index 8b84436140..256493c54b 100644 --- a/modules/core/test/test_arithm.cpp +++ b/modules/core/test/test_arithm.cpp @@ -2201,4 +2201,101 @@ TEST(Core_MeanStdDev, regression_multichannel) } } +template static inline +void testDivideInitData(Mat& src1, Mat& src2) +{ + CV_StaticAssert(std::numeric_limits::is_integer, ""); + const static T src1_[] = { + 0, 0, 0, 0, + 8, 8, 8, 8, + -8, -8, -8, -8 + }; + Mat(3, 4, traits::Type::value, (void*)src1_).copyTo(src1); + const static T src2_[] = { + 1, 2, 0, std::numeric_limits::max(), + 1, 2, 0, std::numeric_limits::max(), + 1, 2, 0, std::numeric_limits::max(), + }; + Mat(3, 4, traits::Type::value, (void*)src2_).copyTo(src2); +} + +template static inline +void testDivideInitDataFloat(Mat& src1, Mat& src2) +{ + CV_StaticAssert(!std::numeric_limits::is_integer, ""); + const static T src1_[] = { + 0, 0, 0, 0, + 8, 8, 8, 8, + -8, -8, -8, -8 + }; + Mat(3, 4, traits::Type::value, (void*)src1_).copyTo(src1); + const static T src2_[] = { + 1, 2, 0, std::numeric_limits::infinity(), + 1, 2, 0, std::numeric_limits::infinity(), + 1, 2, 0, std::numeric_limits::infinity(), + }; + Mat(3, 4, traits::Type::value, (void*)src2_).copyTo(src2); +} + +template <> inline void testDivideInitData(Mat& src1, Mat& src2) { testDivideInitDataFloat(src1, src2); } +template <> inline void testDivideInitData(Mat& src1, Mat& src2) { testDivideInitDataFloat(src1, src2); } + + +template static inline +void testDivideChecks(const Mat& dst) +{ + ASSERT_FALSE(dst.empty()); + for (int y = 0; y < dst.rows; y++) + { + for (int x = 0; x < dst.cols; x++) + { + if (x == 2) + { + EXPECT_EQ(0, dst.at(y, x)) << "dst(" << y << ", " << x << ") = " << dst.at(y, x); + } + } + } +} + + +template static inline +void testDivide() +{ + Mat src1, src2; + testDivideInitData(src1, src2); + ASSERT_FALSE(src1.empty()); ASSERT_FALSE(src2.empty()); + + Mat dst; + if (!isUMat) + { + cv::divide(src1, src2, dst); + } + else + { + UMat usrc1, usrc2, udst; + src1.copyTo(usrc1); + src2.copyTo(usrc2); + cv::divide(usrc1, usrc2, udst); + udst.copyTo(dst); + } + + testDivideChecks(dst); + + if (::testing::Test::HasFailure()) + { + std::cout << "src1 = " << std::endl << src1 << std::endl; + std::cout << "src2 = " << std::endl << src2 << std::endl; + std::cout << "dst = " << std::endl << dst << std::endl; + } +} + +TEST(Core_DivideRules, type_32s) { testDivide(); } +TEST(UMat_Core_DivideRules, type_32s) { testDivide(); } +TEST(Core_DivideRules, type_16s) { testDivide(); } +TEST(UMat_Core_DivideRules, type_16s) { testDivide(); } +TEST(Core_DivideRules, type_32f) { testDivide(); } +TEST(UMat_Core_DivideRules, type_32f) { testDivide(); } +TEST(Core_DivideRules, type_64f) { testDivide(); } +TEST(UMat_Core_DivideRules, type_64f) { testDivide(); } + }} // namespace