123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- #ifndef CERES_INTERNAL_TEST_UTIL_H_
- #define CERES_INTERNAL_TEST_UTIL_H_
- #include <string>
- #include "ceres/internal/disable_warnings.h"
- #include "ceres/internal/export.h"
- #include "ceres/problem.h"
- #include "ceres/solver.h"
- #include "ceres/stringprintf.h"
- #include "gtest/gtest.h"
- namespace ceres {
- namespace internal {
- CERES_NO_EXPORT bool ExpectClose(double x,
- double y,
- double max_abs_relative_difference);
- CERES_NO_EXPORT void ExpectArraysClose(int n,
- const double* p,
- const double* q,
- double tolerance);
- CERES_NO_EXPORT void ExpectArraysCloseUptoScale(int n,
- const double* p,
- const double* q,
- double tolerance);
- CERES_NO_EXPORT std::string TestFileAbsolutePath(const std::string& filename);
- CERES_NO_EXPORT std::string ToString(const Solver::Options& options);
- template <typename SystemTestProblem>
- class CERES_NO_EXPORT SystemTest : public ::testing::Test {
- protected:
- void SetUp() final {
- SystemTestProblem system_test_problem;
- SolveAndEvaluateFinalResiduals(
- *system_test_problem.mutable_solver_options(),
- system_test_problem.mutable_problem(),
- &expected_final_residuals_);
- }
- void RunSolverForConfigAndExpectResidualsMatch(const Solver::Options& options,
- Problem* problem) {
- std::vector<double> final_residuals;
- SolveAndEvaluateFinalResiduals(options, problem, &final_residuals);
-
-
-
-
-
- CHECK_EQ(expected_final_residuals_.size(), final_residuals.size());
- for (int i = 0; i < final_residuals.size(); ++i) {
- EXPECT_NEAR(final_residuals[i],
- expected_final_residuals_[i],
- SystemTestProblem::kResidualTolerance)
- << "Not close enough residual:" << i;
- }
- }
- void SolveAndEvaluateFinalResiduals(const Solver::Options& options,
- Problem* problem,
- std::vector<double>* final_residuals) {
- Solver::Summary summary;
- Solve(options, problem, &summary);
- CHECK_NE(summary.termination_type, ceres::FAILURE);
- problem->Evaluate(
- Problem::EvaluateOptions(), nullptr, final_residuals, nullptr, nullptr);
- }
- std::vector<double> expected_final_residuals_;
- };
- }
- }
- #include "ceres/internal/reenable_warnings.h"
- #endif
|