From 25bc6f0c64d24d88ad32d8afbdc5aecd3aeb1ce9 Mon Sep 17 00:00:00 2001 From: Tyler Veness Date: Wed, 13 Dec 2023 20:40:34 -0800 Subject: [PATCH] Disable test diagnostic prints by default (#238) --- CMakeLists.txt | 5 +--- README.md | 4 ++- src/optimization/OptimizationProblem.cpp | 12 +++++---- test/include/CmdlineArguments.hpp | 25 +++++++++++++++++++ test/src/CmdlineArguments.cpp | 21 ++++++++++++++++ test/src/Main.cpp | 13 ++++++++++ test/src/control/OCPCartPoleTest.cpp | 17 ++++++++----- test/src/control/OCPFlywheelTest.cpp | 17 ++++++++----- test/src/control/OCPRobotTest.cpp | 19 ++++++++------ .../optimization/ArmOnElevatorProblemTest.cpp | 5 +++- test/src/optimization/CartPoleProblemTest.cpp | 17 ++++++++----- .../DoubleIntegratorProblemTest.cpp | 17 ++++++++----- test/src/optimization/FlywheelProblemTest.cpp | 17 ++++++++----- test/src/optimization/LinearProblemTest.cpp | 5 +++- .../src/optimization/NonlinearProblemTest.cpp | 11 +++++--- .../src/optimization/QuadraticProblemTest.cpp | 17 +++++++++---- .../optimization/SolverExitConditionTest.cpp | 21 +++++++++++----- test/src/optimization/TrivialProblemTest.cpp | 11 +++++--- 18 files changed, 188 insertions(+), 66 deletions(-) create mode 100644 test/include/CmdlineArguments.hpp create mode 100644 test/src/CmdlineArguments.cpp create mode 100644 test/src/Main.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index efd6a062..c2c0b0e1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -255,10 +255,7 @@ if(BUILD_TESTING) ${CMAKE_CURRENT_SOURCE_DIR}/test/include ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/units/include ) - target_link_libraries( - SleipnirTest - PRIVATE Sleipnir GTest::gtest GTest::gtest_main - ) + target_link_libraries(SleipnirTest PRIVATE Sleipnir GTest::gtest) if(NOT CMAKE_TOOLCHAIN_FILE) gtest_discover_tests(SleipnirTest) endif() diff --git a/README.md b/README.md index 09353405..9241cccc 100644 --- a/README.md +++ b/README.md @@ -159,7 +159,9 @@ The following build types can be specified via `-DCMAKE_BUILD_TYPE` during CMake * Perf * RelWithDebInfo build type, but with frame pointer so perf utility can use it -## Test problem solutions +## Test diagnostics + +Passing the `--enable-diagnostics` flag to the test executable enables solver diagnostic prints. Some test problems generate CSV files containing their solutions. These can be plotted with [tools/plot_test_problem_solutions.py](https://github.com/SleipnirGroup/Sleipnir/blob/main/tools/plot_test_problem_solutions.py). diff --git a/src/optimization/OptimizationProblem.cpp b/src/optimization/OptimizationProblem.cpp index 6a6dec58..be74e117 100644 --- a/src/optimization/OptimizationProblem.cpp +++ b/src/optimization/OptimizationProblem.cpp @@ -349,11 +349,13 @@ Eigen::VectorXd OptimizationProblem::InteriorPoint( // Check for overconstrained problem if (m_equalityConstraints.size() > m_decisionVariables.size()) { - fmt::print("The problem has too few degrees of freedom.\n"); - fmt::print("Violated constraints (cₑ(x) = 0) in order of declaration:\n"); - for (int row = 0; row < c_e.rows(); ++row) { - if (c_e(row) < 0.0) { - fmt::print(" {}/{}: {} = 0\n", row + 1, c_e.rows(), c_e(row)); + if (m_config.diagnostics) { + fmt::print("The problem has too few degrees of freedom.\n"); + fmt::print("Violated constraints (cₑ(x) = 0) in order of declaration:\n"); + for (int row = 0; row < c_e.rows(); ++row) { + if (c_e(row) < 0.0) { + fmt::print(" {}/{}: {} = 0\n", row + 1, c_e.rows(), c_e(row)); + } } } diff --git a/test/include/CmdlineArguments.hpp b/test/include/CmdlineArguments.hpp new file mode 100644 index 00000000..4e691b3a --- /dev/null +++ b/test/include/CmdlineArguments.hpp @@ -0,0 +1,25 @@ +// Copyright (c) Sleipnir contributors + +#pragma once + +#include +#include + +/// Test commandline argument that enables solver diagnostics +inline constexpr std::string_view kEnableDiagnostics = "--enable-diagnostics"; + +/** + * Initializes the commandline argument list for tests to retreive. + */ +void SetCmdlineArgs(char* argv[], int argc); + +/** + * Returns the test executable's commandline arguments. + */ +std::span GetCmdlineArgs(); + +/** + * Returns true if the given argument is present in the test executable's + * commandline arguments. + */ +bool CmdlineArgPresent(std::string_view arg); diff --git a/test/src/CmdlineArguments.cpp b/test/src/CmdlineArguments.cpp new file mode 100644 index 00000000..003c12d6 --- /dev/null +++ b/test/src/CmdlineArguments.cpp @@ -0,0 +1,21 @@ +// Copyright (c) Sleipnir contributors + +#include "CmdlineArguments.hpp" + +#include + +namespace { +static std::span args; +} // namespace + +void SetCmdlineArgs(char* argv[], int argc) { + args = std::span(argv, argc); +} + +std::span GetCmdlineArgs() { + return args; +} + +bool CmdlineArgPresent(std::string_view arg) { + return std::find(args.begin(), args.end(), arg) != args.end(); +} diff --git a/test/src/Main.cpp b/test/src/Main.cpp new file mode 100644 index 00000000..eb35fcce --- /dev/null +++ b/test/src/Main.cpp @@ -0,0 +1,13 @@ +// Copyright (c) Sleipnir contributors + +#include + +#include "CmdlineArguments.hpp" + +int main(int argc, char* argv[]) { + testing::InitGoogleTest(&argc, argv); + + SetCmdlineArgs(argv, argc); + + return RUN_ALL_TESTS(); +} diff --git a/test/src/control/OCPCartPoleTest.cpp b/test/src/control/OCPCartPoleTest.cpp index af8e3dcc..eceb0b48 100644 --- a/test/src/control/OCPCartPoleTest.cpp +++ b/test/src/control/OCPCartPoleTest.cpp @@ -15,6 +15,8 @@ #include #include +#include "CmdlineArguments.hpp" + namespace { /** * Performs 4th order Runge-Kutta integration of dx/dt = f(x, u) for dt. @@ -238,13 +240,16 @@ TEST(OCPSolverTest, DISABLED_CartPoleProblem) { } problem.Minimize(J); - auto end1 = std::chrono::system_clock::now(); - using std::chrono::duration_cast; - using std::chrono::microseconds; - fmt::print("Setup time: {} ms\n\n", - duration_cast(end1 - start).count() / 1000.0); + [[maybe_unused]] auto end1 = std::chrono::system_clock::now(); + if (CmdlineArgPresent(kEnableDiagnostics)) { + using std::chrono::duration_cast; + using std::chrono::microseconds; + fmt::print("Setup time: {} ms\n\n", + duration_cast(end1 - start).count() / 1000.0); + } - auto status = problem.Solve({.diagnostics = true}); + auto status = + problem.Solve({.diagnostics = CmdlineArgPresent(kEnableDiagnostics)}); EXPECT_EQ(sleipnir::ExpressionType::kQuadratic, status.costFunctionType); EXPECT_EQ(sleipnir::ExpressionType::kNonlinear, diff --git a/test/src/control/OCPFlywheelTest.cpp b/test/src/control/OCPFlywheelTest.cpp index c9665f1c..4626798b 100644 --- a/test/src/control/OCPFlywheelTest.cpp +++ b/test/src/control/OCPFlywheelTest.cpp @@ -16,6 +16,8 @@ #include #include +#include "CmdlineArguments.hpp" + namespace { bool Near(double expected, double actual, double tolerance) { return std::abs(expected - actual) < tolerance; @@ -55,13 +57,16 @@ void TestFlywheel(std::string testName, Eigen::Matrix A, (r_mat_vmat - solver.X()) * (r_mat_vmat - solver.X()).T(); solver.Minimize(objective); - auto end1 = std::chrono::system_clock::now(); - using std::chrono::duration_cast; - using std::chrono::microseconds; - fmt::print("Setup time: {} ms\n\n", - duration_cast(end1 - start).count() / 1000.0); + [[maybe_unused]] auto end1 = std::chrono::system_clock::now(); + if (CmdlineArgPresent(kEnableDiagnostics)) { + using std::chrono::duration_cast; + using std::chrono::microseconds; + fmt::print("Setup time: {} ms\n\n", + duration_cast(end1 - start).count() / 1000.0); + } - auto status = solver.Solve({.diagnostics = true}); + auto status = + solver.Solve({.diagnostics = CmdlineArgPresent(kEnableDiagnostics)}); EXPECT_EQ(sleipnir::ExpressionType::kQuadratic, status.costFunctionType); if (method == sleipnir::TranscriptionMethod::kSingleShooting) { diff --git a/test/src/control/OCPRobotTest.cpp b/test/src/control/OCPRobotTest.cpp index a4c1da6f..c1411ce9 100644 --- a/test/src/control/OCPRobotTest.cpp +++ b/test/src/control/OCPRobotTest.cpp @@ -10,6 +10,8 @@ #include #include +#include "CmdlineArguments.hpp" + TEST(OCPSolverTest, Robot) { auto start = std::chrono::system_clock::now(); @@ -64,14 +66,17 @@ TEST(OCPSolverTest, Robot) { solverMinTime.Minimize(solverMinTime.DT() * Eigen::Matrix::Ones()); - auto end1 = std::chrono::system_clock::now(); - using std::chrono::duration_cast; - using std::chrono::microseconds; - fmt::print("Setup time: {} ms\n\n", - duration_cast(end1 - start).count() / 1000.0); + [[maybe_unused]] auto end1 = std::chrono::system_clock::now(); + if (CmdlineArgPresent(kEnableDiagnostics)) { + using std::chrono::duration_cast; + using std::chrono::microseconds; + fmt::print("Setup time: {} ms\n\n", + duration_cast(end1 - start).count() / 1000.0); + } - auto status = - solverMinTime.Solve({.maxIterations = 1000, .diagnostics = true}); + auto status = solverMinTime.Solve( + {.maxIterations = 1000, + .diagnostics = CmdlineArgPresent(kEnableDiagnostics)}); EXPECT_EQ(sleipnir::ExpressionType::kLinear, status.costFunctionType); EXPECT_EQ(sleipnir::ExpressionType::kNonlinear, diff --git a/test/src/optimization/ArmOnElevatorProblemTest.cpp b/test/src/optimization/ArmOnElevatorProblemTest.cpp index aaf68c4d..9cb3969a 100644 --- a/test/src/optimization/ArmOnElevatorProblemTest.cpp +++ b/test/src/optimization/ArmOnElevatorProblemTest.cpp @@ -10,6 +10,8 @@ #include #include +#include "CmdlineArguments.hpp" + // This problem tests the case where regularization fails TEST(ArmOnElevatorProblemTest, DirectTranscription) { constexpr int N = 800; @@ -92,7 +94,8 @@ TEST(ArmOnElevatorProblemTest, DirectTranscription) { } problem.Minimize(J); - auto status = problem.Solve({.diagnostics = true}); + auto status = + problem.Solve({.diagnostics = CmdlineArgPresent(kEnableDiagnostics)}); EXPECT_EQ(sleipnir::ExpressionType::kQuadratic, status.costFunctionType); EXPECT_EQ(sleipnir::ExpressionType::kLinear, status.equalityConstraintType); diff --git a/test/src/optimization/CartPoleProblemTest.cpp b/test/src/optimization/CartPoleProblemTest.cpp index ed6c4831..10db37c5 100644 --- a/test/src/optimization/CartPoleProblemTest.cpp +++ b/test/src/optimization/CartPoleProblemTest.cpp @@ -15,6 +15,8 @@ #include #include +#include "CmdlineArguments.hpp" + /** * Performs 4th order Runge-Kutta integration of dx/dt = f(x, u) for dt. * @@ -243,13 +245,16 @@ TEST(CartPoleProblemTest, DISABLED_DirectTranscription) { } problem.Minimize(J); - auto end1 = std::chrono::system_clock::now(); - using std::chrono::duration_cast; - using std::chrono::microseconds; - fmt::print("Setup time: {} ms\n\n", - duration_cast(end1 - start).count() / 1000.0); + [[maybe_unused]] auto end1 = std::chrono::system_clock::now(); + if (CmdlineArgPresent(kEnableDiagnostics)) { + using std::chrono::duration_cast; + using std::chrono::microseconds; + fmt::print("Setup time: {} ms\n\n", + duration_cast(end1 - start).count() / 1000.0); + } - auto status = problem.Solve({.diagnostics = true}); + auto status = + problem.Solve({.diagnostics = CmdlineArgPresent(kEnableDiagnostics)}); EXPECT_EQ(sleipnir::ExpressionType::kQuadratic, status.costFunctionType); EXPECT_EQ(sleipnir::ExpressionType::kNonlinear, diff --git a/test/src/optimization/DoubleIntegratorProblemTest.cpp b/test/src/optimization/DoubleIntegratorProblemTest.cpp index ef48f063..a17c5d87 100644 --- a/test/src/optimization/DoubleIntegratorProblemTest.cpp +++ b/test/src/optimization/DoubleIntegratorProblemTest.cpp @@ -10,6 +10,8 @@ #include #include +#include "CmdlineArguments.hpp" + TEST(DoubleIntegratorProblemTest, MinimumTime) { auto start = std::chrono::system_clock::now(); @@ -62,13 +64,16 @@ TEST(DoubleIntegratorProblemTest, MinimumTime) { } problem.Minimize(J); - auto end1 = std::chrono::system_clock::now(); - using std::chrono::duration_cast; - using std::chrono::microseconds; - fmt::print("Setup time: {} ms\n\n", - duration_cast(end1 - start).count() / 1000.0); + [[maybe_unused]] auto end1 = std::chrono::system_clock::now(); + if (CmdlineArgPresent(kEnableDiagnostics)) { + using std::chrono::duration_cast; + using std::chrono::microseconds; + fmt::print("Setup time: {} ms\n\n", + duration_cast(end1 - start).count() / 1000.0); + } - auto status = problem.Solve({.diagnostics = true}); + auto status = + problem.Solve({.diagnostics = CmdlineArgPresent(kEnableDiagnostics)}); EXPECT_EQ(sleipnir::ExpressionType::kQuadratic, status.costFunctionType); EXPECT_EQ(sleipnir::ExpressionType::kLinear, status.equalityConstraintType); diff --git a/test/src/optimization/FlywheelProblemTest.cpp b/test/src/optimization/FlywheelProblemTest.cpp index 44ca73c2..414c6a45 100644 --- a/test/src/optimization/FlywheelProblemTest.cpp +++ b/test/src/optimization/FlywheelProblemTest.cpp @@ -15,6 +15,8 @@ #include #include +#include "CmdlineArguments.hpp" + namespace { bool Near(double expected, double actual, double tolerance) { return std::abs(expected - actual) < tolerance; @@ -56,13 +58,16 @@ TEST(FlywheelProblemTest, DirectTranscription) { } problem.Minimize(J); - auto end1 = std::chrono::system_clock::now(); - using std::chrono::duration_cast; - using std::chrono::microseconds; - fmt::print("Setup time: {} ms\n\n", - duration_cast(end1 - start).count() / 1000.0); + [[maybe_unused]] auto end1 = std::chrono::system_clock::now(); + if (CmdlineArgPresent(kEnableDiagnostics)) { + using std::chrono::duration_cast; + using std::chrono::microseconds; + fmt::print("Setup time: {} ms\n\n", + duration_cast(end1 - start).count() / 1000.0); + } - auto status = problem.Solve({.diagnostics = true}); + auto status = + problem.Solve({.diagnostics = CmdlineArgPresent(kEnableDiagnostics)}); EXPECT_EQ(sleipnir::ExpressionType::kQuadratic, status.costFunctionType); EXPECT_EQ(sleipnir::ExpressionType::kLinear, status.equalityConstraintType); diff --git a/test/src/optimization/LinearProblemTest.cpp b/test/src/optimization/LinearProblemTest.cpp index 80477ea0..d24bbc31 100644 --- a/test/src/optimization/LinearProblemTest.cpp +++ b/test/src/optimization/LinearProblemTest.cpp @@ -3,6 +3,8 @@ #include #include +#include "CmdlineArguments.hpp" + TEST(LinearProblemTest, Maximize) { sleipnir::OptimizationProblem problem; @@ -20,7 +22,8 @@ TEST(LinearProblemTest, Maximize) { problem.SubjectTo(x >= 0); problem.SubjectTo(y >= 0); - auto status = problem.Solve({.diagnostics = true}); + auto status = + problem.Solve({.diagnostics = CmdlineArgPresent(kEnableDiagnostics)}); EXPECT_EQ(sleipnir::ExpressionType::kLinear, status.costFunctionType); EXPECT_EQ(sleipnir::ExpressionType::kNone, status.equalityConstraintType); diff --git a/test/src/optimization/NonlinearProblemTest.cpp b/test/src/optimization/NonlinearProblemTest.cpp index 6029b34f..58fd69c0 100644 --- a/test/src/optimization/NonlinearProblemTest.cpp +++ b/test/src/optimization/NonlinearProblemTest.cpp @@ -6,6 +6,8 @@ #include #include +#include "CmdlineArguments.hpp" + std::vector Range(double start, double end, double step) { std::vector ret; @@ -27,7 +29,8 @@ TEST(NonlinearProblemTest, Quartic) { problem.SubjectTo(x >= 1); - auto status = problem.Solve({.diagnostics = true}); + auto status = + problem.Solve({.diagnostics = CmdlineArgPresent(kEnableDiagnostics)}); EXPECT_EQ(sleipnir::ExpressionType::kNonlinear, status.costFunctionType); EXPECT_EQ(sleipnir::ExpressionType::kNone, status.equalityConstraintType); @@ -54,7 +57,8 @@ TEST(NonlinearProblemTest, RosenbrockWithCubicAndLineConstraint) { problem.SubjectTo(sleipnir::pow(x - 1, 3) - y + 1 <= 0); problem.SubjectTo(x + y - 2 <= 0); - auto status = problem.Solve(); + auto status = + problem.Solve({.diagnostics = CmdlineArgPresent(kEnableDiagnostics)}); EXPECT_EQ(sleipnir::ExpressionType::kNonlinear, status.costFunctionType); EXPECT_EQ(sleipnir::ExpressionType::kNone, status.equalityConstraintType); @@ -94,7 +98,8 @@ TEST(NonlinearProblemTest, RosenbrockWithDiskConstraint) { problem.SubjectTo(sleipnir::pow(x, 2) + sleipnir::pow(y, 2) <= 2); - auto status = problem.Solve(); + auto status = + problem.Solve({.diagnostics = CmdlineArgPresent(kEnableDiagnostics)}); EXPECT_EQ(sleipnir::ExpressionType::kNonlinear, status.costFunctionType); EXPECT_EQ(sleipnir::ExpressionType::kNone, status.equalityConstraintType); diff --git a/test/src/optimization/QuadraticProblemTest.cpp b/test/src/optimization/QuadraticProblemTest.cpp index 2165815b..c0b3da18 100644 --- a/test/src/optimization/QuadraticProblemTest.cpp +++ b/test/src/optimization/QuadraticProblemTest.cpp @@ -3,6 +3,8 @@ #include #include +#include "CmdlineArguments.hpp" + TEST(QuadraticProblemTest, Unconstrained1d) { sleipnir::OptimizationProblem problem; @@ -11,7 +13,8 @@ TEST(QuadraticProblemTest, Unconstrained1d) { problem.Minimize(x * x - 6.0 * x); - auto status = problem.Solve({.diagnostics = true}); + auto status = + problem.Solve({.diagnostics = CmdlineArgPresent(kEnableDiagnostics)}); EXPECT_EQ(sleipnir::ExpressionType::kQuadratic, status.costFunctionType); EXPECT_EQ(sleipnir::ExpressionType::kNone, status.equalityConstraintType); @@ -32,7 +35,8 @@ TEST(QuadraticProblemTest, Unconstrained2d) { problem.Minimize(x * x + y * y); - auto status = problem.Solve({.diagnostics = true}); + auto status = + problem.Solve({.diagnostics = CmdlineArgPresent(kEnableDiagnostics)}); EXPECT_EQ(sleipnir::ExpressionType::kQuadratic, status.costFunctionType); EXPECT_EQ(sleipnir::ExpressionType::kNone, status.equalityConstraintType); @@ -52,7 +56,8 @@ TEST(QuadraticProblemTest, Unconstrained2d) { problem.Minimize(x.T() * x); - auto status = problem.Solve({.diagnostics = true}); + auto status = + problem.Solve({.diagnostics = CmdlineArgPresent(kEnableDiagnostics)}); EXPECT_EQ(sleipnir::ExpressionType::kQuadratic, status.costFunctionType); EXPECT_EQ(sleipnir::ExpressionType::kNone, status.equalityConstraintType); @@ -113,7 +118,8 @@ TEST(QuadraticProblemTest, EqualityConstrained) { problem.SubjectTo(x + 3 * y == 36); - auto status = problem.Solve({.diagnostics = true}); + auto status = + problem.Solve({.diagnostics = CmdlineArgPresent(kEnableDiagnostics)}); EXPECT_EQ(sleipnir::ExpressionType::kQuadratic, status.costFunctionType); EXPECT_EQ(sleipnir::ExpressionType::kLinear, status.equalityConstraintType); @@ -135,7 +141,8 @@ TEST(QuadraticProblemTest, EqualityConstrained) { problem.SubjectTo(x == Eigen::Matrix{{3.0, 3.0}}); - auto status = problem.Solve({.diagnostics = true}); + auto status = + problem.Solve({.diagnostics = CmdlineArgPresent(kEnableDiagnostics)}); EXPECT_EQ(sleipnir::ExpressionType::kQuadratic, status.costFunctionType); EXPECT_EQ(sleipnir::ExpressionType::kLinear, status.equalityConstraintType); diff --git a/test/src/optimization/SolverExitConditionTest.cpp b/test/src/optimization/SolverExitConditionTest.cpp index e27cf93c..7192f302 100644 --- a/test/src/optimization/SolverExitConditionTest.cpp +++ b/test/src/optimization/SolverExitConditionTest.cpp @@ -3,6 +3,8 @@ #include #include +#include "CmdlineArguments.hpp" + // These tests ensure coverage of the off-nominal solver exit conditions TEST(SolverExitConditionTest, CallbackRequestedStop) { @@ -13,7 +15,8 @@ TEST(SolverExitConditionTest, CallbackRequestedStop) { problem.Callback([](const sleipnir::SolverIterationInfo&) { return true; }); - auto status = problem.Solve({.diagnostics = true}); + auto status = + problem.Solve({.diagnostics = CmdlineArgPresent(kEnableDiagnostics)}); EXPECT_EQ(sleipnir::ExpressionType::kLinear, status.costFunctionType); EXPECT_EQ(sleipnir::ExpressionType::kNone, status.equalityConstraintType); @@ -34,7 +37,8 @@ TEST(SolverExitConditionTest, TooFewDOFs) { problem.SubjectTo(y == 1); problem.SubjectTo(z == 1); - auto status = problem.Solve({.diagnostics = true}); + auto status = + problem.Solve({.diagnostics = CmdlineArgPresent(kEnableDiagnostics)}); EXPECT_EQ(sleipnir::ExpressionType::kNone, status.costFunctionType); EXPECT_EQ(sleipnir::ExpressionType::kLinear, status.equalityConstraintType); @@ -55,7 +59,8 @@ TEST(SolverExitConditionTest, LocallyInfeasible) { problem.SubjectTo(y == z + 1); problem.SubjectTo(z == x + 1); - auto status = problem.Solve({.diagnostics = true}); + auto status = + problem.Solve({.diagnostics = CmdlineArgPresent(kEnableDiagnostics)}); EXPECT_EQ(sleipnir::ExpressionType::kNone, status.costFunctionType); EXPECT_EQ(sleipnir::ExpressionType::kLinear, status.equalityConstraintType); @@ -76,7 +81,8 @@ TEST(SolverExitConditionTest, LocallyInfeasible) { problem.SubjectTo(y >= z + 1); problem.SubjectTo(z >= x + 1); - auto status = problem.Solve({.diagnostics = true}); + auto status = + problem.Solve({.diagnostics = CmdlineArgPresent(kEnableDiagnostics)}); EXPECT_EQ(sleipnir::ExpressionType::kNone, status.costFunctionType); EXPECT_EQ(sleipnir::ExpressionType::kNone, status.equalityConstraintType); @@ -94,7 +100,9 @@ TEST(SolverExitConditionTest, MaxIterationsExceeded) { x.SetValue(0.0); problem.Minimize(x); - auto status = problem.Solve({.maxIterations = 0, .diagnostics = true}); + auto status = + problem.Solve({.maxIterations = 0, + .diagnostics = CmdlineArgPresent(kEnableDiagnostics)}); EXPECT_EQ(sleipnir::ExpressionType::kLinear, status.costFunctionType); EXPECT_EQ(sleipnir::ExpressionType::kNone, status.equalityConstraintType); @@ -112,7 +120,8 @@ TEST(SolverExitConditionTest, Timeout) { x.SetValue(0.0); problem.Minimize(x); - auto status = problem.Solve({.timeout = 0s, .diagnostics = true}); + auto status = problem.Solve( + {.timeout = 0s, .diagnostics = CmdlineArgPresent(kEnableDiagnostics)}); EXPECT_EQ(sleipnir::ExpressionType::kLinear, status.costFunctionType); EXPECT_EQ(sleipnir::ExpressionType::kNone, status.equalityConstraintType); diff --git a/test/src/optimization/TrivialProblemTest.cpp b/test/src/optimization/TrivialProblemTest.cpp index 4800bf56..32b38fbf 100644 --- a/test/src/optimization/TrivialProblemTest.cpp +++ b/test/src/optimization/TrivialProblemTest.cpp @@ -3,10 +3,13 @@ #include #include +#include "CmdlineArguments.hpp" + TEST(TrivialProblemTest, Empty) { sleipnir::OptimizationProblem problem; - auto status = problem.Solve({.diagnostics = true}); + auto status = + problem.Solve({.diagnostics = CmdlineArgPresent(kEnableDiagnostics)}); EXPECT_EQ(sleipnir::ExpressionType::kNone, status.costFunctionType); EXPECT_EQ(sleipnir::ExpressionType::kNone, status.equalityConstraintType); @@ -20,7 +23,8 @@ TEST(TrivialProblemTest, NoCostUnconstrained) { auto X = problem.DecisionVariable(2, 3); - auto status = problem.Solve({.diagnostics = true}); + auto status = + problem.Solve({.diagnostics = CmdlineArgPresent(kEnableDiagnostics)}); EXPECT_EQ(sleipnir::ExpressionType::kNone, status.costFunctionType); EXPECT_EQ(sleipnir::ExpressionType::kNone, status.equalityConstraintType); @@ -40,7 +44,8 @@ TEST(TrivialProblemTest, NoCostUnconstrained) { auto X = problem.DecisionVariable(2, 3); X.SetValue(Eigen::Matrix{{1.0, 1.0, 1.0}, {1.0, 1.0, 1.0}}); - auto status = problem.Solve({.diagnostics = true}); + auto status = + problem.Solve({.diagnostics = CmdlineArgPresent(kEnableDiagnostics)}); EXPECT_EQ(sleipnir::ExpressionType::kNone, status.costFunctionType); EXPECT_EQ(sleipnir::ExpressionType::kNone, status.equalityConstraintType);