29 #include "gmock/gmock.h" 35 TEST(Submap2DTest, TheRightNumberOfRangeDataAreInserted) {
36 constexpr
int kNumRangeData = 10;
40 std::to_string(kNumRangeData) +
43 "grid_type = \"PROBABILITY_GRID\"," 46 "range_data_inserter = {" 47 "range_data_inserter_type = \"PROBABILITY_GRID_INSERTER_2D\"," 48 "probability_grid_range_data_inserter = {" 49 "insert_free_space = true, " 50 "hit_probability = 0.53, " 51 "miss_probability = 0.495, " 56 std::set<std::shared_ptr<Submap2D>> all_submaps;
57 for (
int i = 0; i != 1000; ++i) {
58 submaps.InsertRangeData({Eigen::Vector3f::Zero(), {}, {}});
61 for (
const auto& submap : submaps.submaps()) {
62 all_submaps.insert(submap);
64 if (submaps.matching_index() != 0) {
65 EXPECT_LE(kNumRangeData, submaps.submaps().front()->num_range_data());
68 int correct_num_range_data = 0;
69 for (
const auto& submap : all_submaps) {
70 if (submap->num_range_data() == kNumRangeData * 2) {
71 ++correct_num_range_data;
75 EXPECT_EQ(correct_num_range_data, all_submaps.size() - 2);
78 TEST(Submap2DTest, ToFromProto) {
79 MapLimits expected_map_limits(1., Eigen::Vector2d(2., 3.),
80 CellLimits(100, 110));
81 Submap2D expected(Eigen::Vector2f(4.f, 5.f),
82 common::make_unique<ProbabilityGrid>(expected_map_limits));
84 expected.ToProto(&proto,
true );
85 EXPECT_TRUE(proto.has_submap_2d());
86 EXPECT_FALSE(proto.has_submap_3d());
87 const auto actual = Submap2D(proto.submap_2d());
88 EXPECT_TRUE(expected.local_pose().translation().isApprox(
89 actual.local_pose().translation(), 1e-6));
90 EXPECT_TRUE(expected.local_pose().rotation().isApprox(
91 actual.local_pose().rotation(), 1e-6));
92 EXPECT_EQ(expected.num_range_data(), actual.num_range_data());
93 EXPECT_EQ(expected.finished(), actual.finished());
94 EXPECT_NEAR(expected.grid()->limits().resolution(),
95 actual.grid()->limits().resolution(), 1e-6);
96 EXPECT_TRUE(expected.grid()->limits().max().isApprox(
97 actual.grid()->limits().max(), 1e-6));
98 EXPECT_EQ(expected.grid()->limits().cell_limits().num_x_cells,
99 actual.grid()->limits().cell_limits().num_x_cells);
proto::SubmapsOptions2D CreateSubmapsOptions2D(common::LuaParameterDictionary *const parameter_dictionary)
std::unique_ptr< LuaParameterDictionary > MakeDictionary(const std::string &code)
TEST(TrajectoryConnectivityStateTest, UnknownTrajectory)