Commit 537a978d authored by Viet Dinh's avatar Viet Dinh

update test_math.cpp

parent b6e8a47f
......@@ -2348,6 +2348,55 @@ void Core_SolvePolyTest::run( int )
}
}
template<typename T>
static void checkRoot(Mat& r, T re, T im)
{
for (size_t i = 0; i < r.total(); i++)
{
Vec<T, 2> v = *(Vec<T, 2>*)r.ptr(i);
if (fabs(re - v[0]) < 1e-6 && fabs(im - v[1]) < 1e-6)
{
v[0] = std::numeric_limits<T>::quiet_NaN();
v[1] = std::numeric_limits<T>::quiet_NaN();
return;
}
}
GTEST_NONFATAL_FAILURE_("Can't find root") << "(" << re << ", " << im << ")";
}
TEST(Core_SolvePoly, regression_5599)
{
// x^4 - x^2 = 0, roots: 1, -1, 0, 0
cv::Mat coefs = (cv::Mat_<float>(1,5) << 0, 0, -1, 0, 1 );
{
cv::Mat r;
double prec;
prec = cv::solvePoly(coefs, r);
EXPECT_LE(prec, 1e-6);
EXPECT_EQ(4, (int)r.total());
//std::cout << "Preciseness = " << prec << std::endl;
//std::cout << "roots:\n" << r << "\n" << std::endl;
ASSERT_EQ(CV_32FC2, r.type());
checkRoot<float>(r, 1, 0);
checkRoot<float>(r, -1, 0);
checkRoot<float>(r, 0, 0);
checkRoot<float>(r, 0, 0);
}
// x^2 - 2x + 1 = 0, roots: 1, 1
coefs = (cv::Mat_<float>(1,3) << 1, -2, 1 );
{
cv::Mat r;
double prec;
prec = cv::solvePoly(coefs, r);
EXPECT_LE(prec, 1e-6);
EXPECT_EQ(2, (int)r.total());
//std::cout << "Preciseness = " << prec << std::endl;
//std::cout << "roots:\n" << r << "\n" << std::endl;
ASSERT_EQ(CV_32FC2, r.type());
checkRoot<float>(r, 1, 0);
checkRoot<float>(r, 1, 0);
}
}
class Core_CheckRange_Empty : public cvtest::BaseTest
{
public:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment