Move FakeTrimmable implementation to internal/testing. (#1050)

* Move FakeTrimmable implementation to internal/testing.

* Address the comments.
master
Alexander Belyaev 2018-04-10 18:05:03 +02:00 committed by GitHub
parent 895f1d61b4
commit 7b0963216f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 68 additions and 44 deletions

View File

@ -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<SubmapId> GetSubmapIds(int trajectory_id) const override {
return submaps_;
}
MapById<SubmapId, PoseGraphInterface::SubmapData> GetAllSubmapData()
const override {
return {};
}
MapById<NodeId, TrajectoryNode> GetTrajectoryNodes() const override {
return {};
}
std::vector<PoseGraphInterface::Constraint> 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<SubmapId> trimmed_submaps() { return trimmed_submaps_; }
private:
std::vector<SubmapId> submaps_;
std::vector<SubmapId> trimmed_submaps_;
};
} // namespace testing
} // namespace mapping
} // namespace cartographer

View File

@ -19,59 +19,17 @@
#include <vector>
#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<SubmapId> GetSubmapIds(int trajectory_id) const override {
return submaps_;
}
MapById<SubmapId, PoseGraphInterface::SubmapData> GetAllSubmapData()
const override {
return {};
}
MapById<NodeId, TrajectoryNode> GetTrajectoryNodes() const override {
return {};
}
std::vector<PoseGraphInterface::Constraint> 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<SubmapId> trimmed_submaps() { return trimmed_submaps_; }
private:
std::vector<SubmapId> submaps_;
std::vector<SubmapId> 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();