core(test): zero values divide test (4.0+)
authorAlexander Alekhin <alexander.a.alekhin@gmail.com>
Sun, 14 Oct 2018 01:28:54 +0000 (01:28 +0000)
committerAlexander Alekhin <alexander.a.alekhin@gmail.com>
Sun, 14 Oct 2018 03:46:29 +0000 (03:46 +0000)
modules/core/test/test_arithm.cpp

index 96d5f42..b9a7d78 100644 (file)
@@ -2286,6 +2286,7 @@ template <typename T> static inline
 void testDivideChecks(const Mat& dst)
 {
     ASSERT_FALSE(dst.empty());
+    CV_StaticAssert(std::numeric_limits<T>::is_integer, "");
     for (int y = 0; y < dst.rows; y++)
     {
         for (int x = 0; x < dst.cols; x++)
@@ -2298,6 +2299,35 @@ void testDivideChecks(const Mat& dst)
     }
 }
 
+template <typename T> static inline
+void testDivideChecksFP(const Mat& dst)
+{
+    ASSERT_FALSE(dst.empty());
+    CV_StaticAssert(!std::numeric_limits<T>::is_integer, "");
+    for (int y = 0; y < dst.rows; y++)
+    {
+        for (int x = 0; x < dst.cols; x++)
+        {
+            if (y == 0 && x == 2)
+            {
+                EXPECT_TRUE(cvIsNaN(dst.at<T>(y, x))) << "dst(" << y << ", " << x << ") = " << dst.at<T>(y, x);
+            }
+            else if (x == 2)
+            {
+                EXPECT_TRUE(cvIsInf(dst.at<T>(y, x))) << "dst(" << y << ", " << x << ") = " << dst.at<T>(y, x);
+            }
+            else
+            {
+                EXPECT_FALSE(cvIsNaN(dst.at<T>(y, x))) << "dst(" << y << ", " << x << ") = " << dst.at<T>(y, x);
+                EXPECT_FALSE(cvIsInf(dst.at<T>(y, x))) << "dst(" << y << ", " << x << ") = " << dst.at<T>(y, x);
+            }
+        }
+    }
+}
+
+template <> inline void testDivideChecks<float>(const Mat& dst) { testDivideChecksFP<float>(dst); }
+template <> inline void testDivideChecks<double>(const Mat& dst) { testDivideChecksFP<double>(dst); }
+
 
 template <typename T, bool isUMat> static inline
 void testDivide()