Skip to content
Snippets Groups Projects
Commit 48482444 authored by Joan Solà Ortega's avatar Joan Solà Ortega
Browse files

Add gtest for constructor with lists

parent 3ba91db0
No related branches found
No related tags found
1 merge request!346Resolve "Frame/Capture/Feature/Landmark Other as list/vectors in FactorBase"
Pipeline #5081 passed
...@@ -47,13 +47,9 @@ add_library(dummy ${SRC_DUMMY}) ...@@ -47,13 +47,9 @@ add_library(dummy ${SRC_DUMMY})
wolf_add_gtest(gtest_capture_base gtest_capture_base.cpp) wolf_add_gtest(gtest_capture_base gtest_capture_base.cpp)
target_link_libraries(gtest_capture_base ${PROJECT_NAME}) target_link_libraries(gtest_capture_base ${PROJECT_NAME})
# CaptureBase class test # FactorBase class test
#wolf_add_gtest(gtest_factor_sparse gtest_factor_sparse.cpp) wolf_add_gtest(gtest_factor_base gtest_factor_base.cpp)
#target_link_libraries(gtest_factor_sparse ${PROJECT_NAME}) target_link_libraries(gtest_factor_base ${PROJECT_NAME})
# FactorBlockDifference class test
wolf_add_gtest(gtest_factor_block_difference gtest_factor_block_difference.cpp)
target_link_libraries(gtest_factor_block_difference ${PROJECT_NAME})
# FactorAutodiff class test # FactorAutodiff class test
wolf_add_gtest(gtest_factor_autodiff gtest_factor_autodiff.cpp) wolf_add_gtest(gtest_factor_autodiff gtest_factor_autodiff.cpp)
...@@ -169,6 +165,10 @@ target_link_libraries(gtest_factor_absolute ${PROJECT_NAME}) ...@@ -169,6 +165,10 @@ target_link_libraries(gtest_factor_absolute ${PROJECT_NAME})
wolf_add_gtest(gtest_factor_autodiff_distance_3d gtest_factor_autodiff_distance_3d.cpp) wolf_add_gtest(gtest_factor_autodiff_distance_3d gtest_factor_autodiff_distance_3d.cpp)
target_link_libraries(gtest_factor_autodiff_distance_3d ${PROJECT_NAME}) target_link_libraries(gtest_factor_autodiff_distance_3d ${PROJECT_NAME})
# FactorBlockDifference class test
wolf_add_gtest(gtest_factor_block_difference gtest_factor_block_difference.cpp)
target_link_libraries(gtest_factor_block_difference ${PROJECT_NAME})
# FactorOdom3d class test # FactorOdom3d class test
wolf_add_gtest(gtest_factor_diff_drive gtest_factor_diff_drive.cpp) wolf_add_gtest(gtest_factor_diff_drive gtest_factor_diff_drive.cpp)
target_link_libraries(gtest_factor_diff_drive ${PROJECT_NAME}) target_link_libraries(gtest_factor_diff_drive ${PROJECT_NAME})
......
/*
* gtest_factor_base.cpp
*
* Created on: Apr 2, 2020
* Author: jsola
*/
#include "core/utils/utils_gtest.h"
#include "core/utils/logging.h"
#include "core/factor/factor_base.h"
using namespace wolf;
using namespace Eigen;
class FactorBaseTest : public testing::Test
{
public:
FrameBasePtr F0,F1;
CaptureBasePtr C0,C1;
FeatureBasePtr f0,f1;
LandmarkBasePtr L0,L1;
virtual void SetUp()
{
F0 = std::make_shared<FrameBase>(0.0, nullptr);
F1 = std::make_shared<FrameBase>(1.0, nullptr);
C0 = std::make_shared<CaptureBase>("Capture", 0.0, nullptr);
C1 = std::make_shared<CaptureBase>("Capture", 1.0, nullptr);
f0 = std::make_shared<FeatureBase>("Feature", Vector2d(1,2), Matrix2d::Identity(), FeatureBase::UncertaintyType::UNCERTAINTY_IS_COVARIANCE);
f1 = std::make_shared<FeatureBase>("Feature", Vector2d(1,2), Matrix2d::Identity(), FeatureBase::UncertaintyType::UNCERTAINTY_IS_COVARIANCE);
L0 = std::make_shared<LandmarkBase>("Lmk", nullptr);
L1 = std::make_shared<LandmarkBase>("Lmk", nullptr);
}
// virtual void TearDown(){}
};
class FactorDummy : public FactorBase
{
public:
FactorDummy(const FrameBasePtr& _frame_other,
const CaptureBasePtr& _capture_other,
const FeatureBasePtr& _feature_other,
const LandmarkBasePtr& _landmark_other) :
FactorBase("Dummy",
_frame_other,
_capture_other,
_feature_other,
_landmark_other,
nullptr,
false)
{
//
}
FactorDummy(const FrameBasePtrList& _frame_other_list,
const CaptureBasePtrList& _capture_other_list,
const FeatureBasePtrList& _feature_other_list,
const LandmarkBasePtrList& _landmark_other_list) :
FactorBase("Dummy",
_frame_other_list,
_capture_other_list,
_feature_other_list,
_landmark_other_list,
nullptr,
false)
{
//
}
virtual ~FactorDummy() = default;
virtual std::string getTopology() const override {return "DUMMY";}
virtual bool evaluate(double const* const* _parameters, double* _residuals, double** _jacobians) const override {return true;}
virtual void evaluate(const std::vector<const double*>& _states_ptr, Eigen::VectorXd& _residual, std::vector<Eigen::MatrixXd>& _jacobians) const override {}
virtual JacobianMethod getJacobianMethod() const override {return JacobianMethod::JAC_ANALYTIC;}
virtual std::vector<StateBlockPtr> getStateBlockPtrVector() const override {std::vector<StateBlockPtr> v; return v;}
virtual std::vector<unsigned int> getStateSizes() const override {std::vector<unsigned int> v; return v;}
virtual unsigned int getSize() const override {return 0;}
};
TEST_F(FactorBaseTest, constructor_from_pointers)
{
FactorDummy fac(nullptr,C0,f0,nullptr);
ASSERT_TRUE(fac.getFrameOtherList().empty());
ASSERT_EQ(fac.getCaptureOtherList().size(), 1);
ASSERT_EQ(fac.getFeatureOtherList().size(), 1);
ASSERT_TRUE(fac.getLandmarkOtherList().empty());
}
TEST_F(FactorBaseTest, constructor_from_lists)
{
FactorDummy fac({},{C0},{f0,f1},{});
ASSERT_TRUE(fac.getFrameOtherList().empty());
ASSERT_EQ(fac.getCaptureOtherList().size(), 1);
ASSERT_EQ(fac.getFeatureOtherList().size(), 2);
ASSERT_TRUE(fac.getLandmarkOtherList().empty());
}
int main(int argc, char **argv)
{
testing::InitGoogleTest(&argc, argv);
// restrict to a group of tests only
//::testing::GTEST_FLAG(filter) = "TestInit.*";
// restrict to this test only
//::testing::GTEST_FLAG(filter) = "TestInit.testName";
return RUN_ALL_TESTS();
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment