diff --git a/cartographer/mapping/internal/testing/fake_trimmable.h b/cartographer/mapping/internal/testing/fake_trimmable.h new file mode 100644 index 0000000..c86066d --- /dev/null +++ b/cartographer/mapping/internal/testing/fake_trimmable.h @@ -0,0 +1,66 @@ +/* + * Copyright 2018 The Cartographer Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +namespace cartographer { +namespace mapping { +namespace testing { + +class FakeTrimmable : public Trimmable { + public: + FakeTrimmable(int trajectory_id, int num_submaps) { + for (int index = 0; index < num_submaps; ++index) { + submaps_.push_back(SubmapId{trajectory_id, index}); + } + } + ~FakeTrimmable() override {} + + int num_submaps(const int trajectory_id) const override { + return submaps_.size() - trimmed_submaps_.size(); + } + + std::vector GetSubmapIds(int trajectory_id) const override { + return submaps_; + } + + MapById GetAllSubmapData() + const override { + return {}; + } + + MapById GetTrajectoryNodes() const override { + return {}; + } + + std::vector GetConstraints() const override { + return {}; + } + + void MarkSubmapAsTrimmed(const SubmapId& submap_id) override { + trimmed_submaps_.push_back(submap_id); + } + + bool IsFinished(const int trajectory_id) const override { return false; } + + std::vector trimmed_submaps() { return trimmed_submaps_; } + + private: + std::vector submaps_; + std::vector trimmed_submaps_; +}; + +} // namespace testing +} // namespace mapping +} // namespace cartographer diff --git a/cartographer/mapping/pose_graph_trimmer_test.cc b/cartographer/mapping/pose_graph_trimmer_test.cc index d780f6d..daad1bc 100644 --- a/cartographer/mapping/pose_graph_trimmer_test.cc +++ b/cartographer/mapping/pose_graph_trimmer_test.cc @@ -19,59 +19,17 @@ #include #include "cartographer/mapping/id.h" +#include "cartographer/mapping/internal/testing/fake_trimmable.h" #include "gtest/gtest.h" namespace cartographer { namespace mapping { namespace { -class FakePoseGraph : public Trimmable { - public: - FakePoseGraph(int trajectory_id, int num_submaps) { - for (int index = 0; index < num_submaps; ++index) { - submaps_.push_back(SubmapId{trajectory_id, index}); - } - } - ~FakePoseGraph() override {} - - int num_submaps(const int trajectory_id) const override { - return submaps_.size() - trimmed_submaps_.size(); - } - - std::vector GetSubmapIds(int trajectory_id) const override { - return submaps_; - } - - MapById GetAllSubmapData() - const override { - return {}; - } - - MapById GetTrajectoryNodes() const override { - return {}; - } - - std::vector GetConstraints() const override { - return {}; - } - - void MarkSubmapAsTrimmed(const SubmapId& submap_id) override { - trimmed_submaps_.push_back(submap_id); - } - - bool IsFinished(const int trajectory_id) const override { return false; } - - std::vector trimmed_submaps() { return trimmed_submaps_; } - - private: - std::vector submaps_; - std::vector trimmed_submaps_; -}; - TEST(PureLocalizationTrimmerTest, MarksSubmapsAsExpected) { const int kTrajectoryId = 42; PureLocalizationTrimmer trimmer(kTrajectoryId, 15); - FakePoseGraph fake_pose_graph(kTrajectoryId, 17); + testing::FakeTrimmable fake_pose_graph(kTrajectoryId, 17); trimmer.Trim(&fake_pose_graph); const auto trimmed_submaps = fake_pose_graph.trimmed_submaps();