15 #include <gmock/gmock.h>
16 #include <gtest/gtest.h>
37 using Eigen::Vector2d;
41 struct CovarianceCalculation :
public testing::Test {};
43 TEST_F(CovarianceCalculation, UniformWeightOverload) {
50 const auto translation_vector = std::vector{
51 Vector2d{0, 0},
Vector2d{2, 2},
Vector2d{0, 0},
Vector2d{2, 2},
Vector2d{0, 0},
52 Vector2d{2, 0},
Vector2d{0, 2},
Vector2d{2, 2},
Vector2d{0, 2},
Vector2d{2, 0},
54 const auto translation_mean =
Vector2d{1, 1};
56 ASSERT_NEAR(covariance(0, 0), 1.1111, 0.001);
57 ASSERT_NEAR(covariance(0, 1), 0.2222, 0.001);
58 ASSERT_NEAR(covariance(1, 0), 0.2222, 0.001);
59 ASSERT_NEAR(covariance(1, 1), 1.1111, 0.001);
62 TEST_F(CovarianceCalculation, NonUniformWeightOverload) {
73 const auto translation_vector = std::vector{
74 Vector2d{0, 0},
Vector2d{2, 2},
Vector2d{0, 0},
Vector2d{2, 2},
Vector2d{0, 0},
75 Vector2d{2, 0},
Vector2d{0, 2},
Vector2d{2, 2},
Vector2d{0, 2},
Vector2d{2, 0},
77 auto weights = std::vector{0.0, 1.0, 2.0, 1.0, 0.0, 1.0, 2.0, 1.0, 0.0, 1.0};
78 const auto total_weight = std::accumulate(
weights.begin(),
weights.end(), 0.0);
79 std::for_each(
weights.begin(),
weights.end(), [total_weight](
auto&
weight) { weight /= total_weight; });
80 const auto translation_mean =
Vector2d{1.1111, 1.1111};
82 ASSERT_NEAR(covariance(0, 0), 1.1765, 0.001);
83 ASSERT_NEAR(covariance(0, 1), 0.1176, 0.001);
84 ASSERT_NEAR(covariance(1, 0), 0.1176, 0.001);
85 ASSERT_NEAR(covariance(1, 1), 1.1765, 0.001);
88 struct PoseCovarianceEstimation :
public testing::Test {
114 TEST_F(PoseCovarianceEstimation, PureTranslation) {
126 TEST_F(PoseCovarianceEstimation, PureRotation) {
139 TEST_F(PoseCovarianceEstimation, JointTranslationAndRotation) {
141 const auto states = std::vector{
153 TEST_F(PoseCovarianceEstimation, CancellingOrientations) {
156 const auto states = std::vector{
160 constexpr
double kInf = std::numeric_limits<double>::infinity();
166 ASSERT_EQ(covariance(2, 2), std::numeric_limits<double>::infinity());
169 TEST_F(PoseCovarianceEstimation, RandomWalkWithSmoothRotationWithUniformWeights) {
171 const auto states = std::vector{
192 TEST_F(PoseCovarianceEstimation, WeightsCanSingleOutOneSample) {
194 const auto states = std::vector{
200 const auto weights = std::vector{0.0, 1.0, 0.0, 1.0};
209 TEST_F(PoseCovarianceEstimation, RandomWalkWithSmoothRotationAndNonUniformWeights) {
211 const auto states = std::vector{
223 const auto weights = std::vector{0.1, 0.4, 0.7, 0.1, 0.9, 0.2, 0.2, 0.4, 0.1, 0.4};
232 struct ScalarEstimation :
public testing::Test {};
234 TEST_F(ScalarEstimation, UniformWeightOverload) {
236 const auto states = std::vector{0.0, 1.0, 1.0, 2.0, 2.0, 3.0, 4.0, 4.0, 5.0, 5.0, 6.0, 7.0, 7.0, 8.0, 9.0};
239 const auto standard_deviation = std::sqrt(variance);
242 ASSERT_NEAR(standard_deviation, 2.763,
kTolerance);
245 TEST_F(ScalarEstimation, NonUniformWeightOverload) {
247 const auto states = std::vector{0.0, 1.0, 1.0, 2.0, 2.0, 3.0, 4.0, 4.0, 5.0, 5.0, 6.0, 7.0, 7.0, 8.0, 9.0};
248 const auto weights = std::vector{0.1, 0.15, 0.15, 0.3, 0.3, 0.4, 0.8, 0.8, 0.4, 0.4, 0.35, 0.3, 0.3, 0.15, 0.1};
250 const auto standard_deviation = std::sqrt(variance);
253 ASSERT_NEAR(standard_deviation, 2.026,
kTolerance);