10 #include <gtest/gtest.h> 17 const double eps = 1e-9;
24 double coefs_roots[][6] = {{1, -2, 1, 2, 1.0, 1.0},
25 {1, 0, -1, 2, -1.0, 1.0},
26 {1, -1, -56, 2, -7.0, 8.0},
28 {2.0, 0, 0, 2, 0, 0}};
30 for (
auto& coefs_root : coefs_roots)
32 const double a = coefs_root[0], b = coefs_root[1], c = coefs_root[2];
33 const int num_roots_good =
static_cast<int>(coefs_root[3]);
34 const double r1_good = coefs_root[4], r2_good = coefs_root[5];
40 "\nSolving: %.02f * x^2 + %.02f * x + %.02f = 0\n", a, b, c);
59 double coefs_roots[][7] = {{-6, 11, -6, 3, 1.0, 2.0, 3.0},
60 {2, 3, 4, 1, -1.650629191439386, 0, 0},
61 {0, -91, -90, 3, -1.0, -9.0, 10.0}};
63 for (
auto& coefs_root : coefs_roots)
65 const double a = coefs_root[0], b = coefs_root[1], c = coefs_root[2];
66 const int num_roots_good =
static_cast<int>(coefs_root[3]);
67 const double roots_good[3] = {coefs_root[4], coefs_root[5],
74 "\nSolving: x^3 + %.02f * x^2 + %.02f * x + %.02f = 0\n", a, b, c);
77 for (
int k = 0; k < num_roots; k++)
80 for (
int j = 0; j < num_roots; j++)
81 if (std::abs(roots[k] - roots_good[j]) <
eps) match =
true;
83 EXPECT_TRUE(match) << sTestStr <<
"k: " << k << std::endl;
93 double coefs_roots[][9] = {{-10, 35, -50, 24, 4, 1.0, 2.0, 3.0, 4.0},
94 {-14, 35, 50, 0, 4, -1, 0, 5, 10}};
96 for (
auto& coefs_root : coefs_roots)
98 const double a = coefs_root[0], b = coefs_root[1], c = coefs_root[2],
100 const int num_roots_good =
static_cast<int>(coefs_root[4]);
101 const double roots_good[4] = {coefs_root[5], coefs_root[6],
102 coefs_root[7], coefs_root[8]};
108 "\nSolving: x^4 + %.02f * x^3 + %.02f * x^2 + %.02f * x + %.02f = " 113 for (
int k = 0; k < num_roots; k++)
116 for (
int j = 0; j < num_roots; j++)
117 if (std::abs(roots[k] - roots_good[j]) <
eps) match =
true;
119 EXPECT_TRUE(match) << sTestStr <<
"k: " << k << std::endl;
EXPECT_TRUE(mrpt::system::fileExists(ini_fil))
std::string std::string format(std::string_view fmt, ARGS &&... args)
TEST(poly_roots, solve_poly2)
int solve_poly4(double *x, double a, double b, double c, double d) noexcept
Solves quartic equation x^4 + a*x^3 + b*x^2 + c*x + d = 0 by Dekart-Euler method. ...
EXPECT_EQ(out.image_pair_was_used.size(), NUM_IMGS)
EXPECT_NEAR(out.cam_params.rightCameraPose.x, 0.1194, 0.005)
int solve_poly3(double *x, double a, double b, double c) noexcept
Solves cubic equation x^3 + a*x^2 + b*x + c = 0.
int solve_poly2(double a, double b, double c, double &r1, double &r2) noexcept
Solves equation a*x^2 + b*x + c = 0.