Skip to content

Commit a9406a7

Browse files
Address review feedback in coverage tests
Agent-Logs-Url: https://github.com/astomodynamics/cddp-cpp/sessions/74fc7104-f2ef-41e6-b9dc-7425d8765f3b Co-authored-by: astomodynamics <49183997+astomodynamics@users.noreply.github.com>
1 parent 301b981 commit a9406a7

2 files changed

Lines changed: 16 additions & 6 deletions

File tree

tests/cddp_core/test_finite_difference.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121

2222
namespace {
2323

24+
constexpr int kCentralDifference = 0;
25+
constexpr int kForwardDifference = 1;
26+
constexpr int kBackwardDifference = 2;
27+
2428
double quadratic_cost(const Eigen::VectorXd &x) {
2529
return x(0) * x(0) + 3.0 * x(0) * x(1) + std::sin(x(1));
2630
}
@@ -55,7 +59,9 @@ TEST(FiniteDifferenceTest, GradientMatchesAnalyticForAllModes) {
5559
const Eigen::Vector2d x(0.4, -0.2);
5660
const Eigen::Vector2d grad_expected = expected_gradient(x);
5761

58-
for (const int mode : std::array<int, 3>{0, 1, 2}) {
62+
for (const int mode :
63+
std::array<int, 3>{kCentralDifference, kForwardDifference,
64+
kBackwardDifference}) {
5965
const Eigen::VectorXd grad =
6066
cddp::finite_difference_gradient(quadratic_cost, x, 1e-6, mode);
6167
EXPECT_TRUE(grad.isApprox(grad_expected, 1e-4)) << "mode=" << mode;
@@ -66,7 +72,9 @@ TEST(FiniteDifferenceTest, JacobianMatchesAnalyticForAllModes) {
6672
const Eigen::Vector2d x(-0.3, 0.6);
6773
const Eigen::Matrix2d jac_expected = expected_jacobian(x);
6874

69-
for (const int mode : std::array<int, 3>{0, 1, 2}) {
75+
for (const int mode :
76+
std::array<int, 3>{kCentralDifference, kForwardDifference,
77+
kBackwardDifference}) {
7078
const Eigen::MatrixXd jac =
7179
cddp::finite_difference_jacobian(vector_function, x, 1e-6, mode);
7280
EXPECT_TRUE(jac.isApprox(jac_expected, 1e-4)) << "mode=" << mode;
@@ -77,7 +85,9 @@ TEST(FiniteDifferenceTest, HessianMatchesAnalyticForAllModes) {
7785
const Eigen::Vector2d x(0.4, -0.2);
7886
const Eigen::Matrix2d hess_expected = expected_hessian(x);
7987

80-
for (const int mode : std::array<int, 3>{0, 1, 2}) {
88+
for (const int mode :
89+
std::array<int, 3>{kCentralDifference, kForwardDifference,
90+
kBackwardDifference}) {
8191
const Eigen::MatrixXd hess =
8292
cddp::finite_difference_hessian(quadratic_cost, x, 1e-5, mode);
8393
EXPECT_TRUE(hess.isApprox(hess_expected, 2e-2)) << "mode=" << mode;

tests/cddp_core/test_helper_conversions.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ TEST(HelperConversionTest, EulerRotationRoundTripIsConsistent) {
3131
}
3232

3333
TEST(HelperConversionTest, RotationMatrixToEulerHandlesGimbalLock) {
34-
const double half_pi = std::acos(-1.0) / 2.0;
35-
const Eigen::Vector3d euler(0.5, half_pi, -0.2);
34+
constexpr double kHalfPi = 1.5707963267948966;
35+
const Eigen::Vector3d euler(0.5, kHalfPi, -0.2);
3636

3737
const Eigen::Matrix3d rotation = cddp::helper::eulerZYXToRotationMatrix(euler);
3838
const Eigen::Vector3d recovered = cddp::helper::rotationMatrixToEulerZYX(rotation);
3939

4040
EXPECT_TRUE(recovered.allFinite());
41-
EXPECT_NEAR(recovered(1), half_pi, 1e-9);
41+
EXPECT_NEAR(recovered(1), kHalfPi, 1e-9);
4242
EXPECT_NEAR(recovered(2), 0.0, 1e-12);
4343
}
4444

0 commit comments

Comments
 (0)