21 #include "gtest/gtest.h" 25 namespace scan_matching {
28 TEST(RotationalScanMatcher3DTest, OnlySameHistogramIsScoreOne) {
29 Eigen::VectorXf histogram(7);
30 histogram << 1.f, 43.f, 0.5f, 0.3123f, 23.f, 42.f, 0.f;
31 RotationalScanMatcher matcher({{histogram, 0.f}});
32 const auto scores = matcher.Match(histogram, 0.f, {0.f, 1.f});
33 ASSERT_EQ(2, scores.size());
34 EXPECT_NEAR(1.f, scores[0], 1e-6);
35 EXPECT_GT(1.f, scores[1]);
38 TEST(RotationalScanMatcher3DTest, InterpolatesAsExpected) {
39 constexpr
int kNumBuckets = 10;
40 constexpr
float kAnglePerBucket = M_PI / kNumBuckets;
41 constexpr
float kNoInitialRotation = 0.f;
42 RotationalScanMatcher matcher(
43 {{Eigen::VectorXf::Unit(kNumBuckets, 3), kNoInitialRotation}});
44 for (
float t = 0.f; t < 1.f; t += 0.1f) {
47 const float expected_score = t / std::hypot(t, 1 - t);
49 auto scores = matcher.Match(Eigen::VectorXf::Unit(kNumBuckets, 2),
50 kNoInitialRotation, {t * kAnglePerBucket});
51 ASSERT_EQ(1, scores.size());
52 EXPECT_NEAR(expected_score, scores[0], 1e-6);
54 scores = matcher.Match(Eigen::VectorXf::Unit(kNumBuckets, 2),
55 kNoInitialRotation, {(2 - t) * kAnglePerBucket});
56 ASSERT_EQ(1, scores.size());
57 EXPECT_NEAR(expected_score, scores[0], 1e-6);
60 matcher.Match(Eigen::VectorXf::Unit(kNumBuckets, 4), kNoInitialRotation,
61 {-t * kAnglePerBucket, (t - 2) * kAnglePerBucket});
62 ASSERT_EQ(2, scores.size());
63 EXPECT_NEAR(expected_score, scores[0], 1e-6);
64 EXPECT_NEAR(expected_score, scores[1], 1e-6);
TEST(TrajectoryConnectivityStateTest, UnknownTrajectory)