Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "cartographer/sensor/map_by_time.h"
00018
00019 #include <deque>
00020
00021 #include "cartographer/common/time.h"
00022 #include "gtest/gtest.h"
00023
00024 namespace cartographer {
00025 namespace sensor {
00026 namespace {
00027
00028 common::Time CreateTime(const int milliseconds) {
00029 return common::Time(common::FromMilliseconds(milliseconds));
00030 }
00031
00032 struct Data {
00033 common::Time time;
00034 };
00035
00036 struct NodeData {
00037 common::Time time;
00038 };
00039
00040 TEST(MapByTimeTest, AppendAndViewTrajectory) {
00041 MapByTime<Data> map_by_time;
00042 map_by_time.Append(0, Data{CreateTime(10)});
00043 map_by_time.Append(42, Data{CreateTime(42)});
00044 map_by_time.Append(42, Data{CreateTime(43)});
00045 std::deque<Data> expected_data = {Data{CreateTime(42)}, Data{CreateTime(43)}};
00046 for (const Data& data : map_by_time.trajectory(42)) {
00047 ASSERT_FALSE(expected_data.empty());
00048 EXPECT_EQ(expected_data.front().time, data.time);
00049 expected_data.pop_front();
00050 }
00051 EXPECT_TRUE(expected_data.empty());
00052 }
00053
00054 TEST(MapByTimeTest, Trimming) {
00055 MapByTime<Data> map_by_time;
00056 EXPECT_FALSE(map_by_time.HasTrajectory(42));
00057 map_by_time.Append(42, Data{CreateTime(1)});
00058 map_by_time.Append(42, Data{CreateTime(41)});
00059 map_by_time.Append(42, Data{CreateTime(42)});
00060 map_by_time.Append(42, Data{CreateTime(43)});
00061 map_by_time.Append(42, Data{CreateTime(47)});
00062 map_by_time.Append(42, Data{CreateTime(48)});
00063 map_by_time.Append(42, Data{CreateTime(49)});
00064 map_by_time.Append(42, Data{CreateTime(5000)});
00065 EXPECT_TRUE(map_by_time.HasTrajectory(42));
00066
00067 mapping::MapById<mapping::NodeId, NodeData> map_by_id;
00068 map_by_id.Append(42, NodeData{CreateTime(42)});
00069 map_by_id.Append(42, NodeData{CreateTime(46)});
00070 map_by_id.Append(42, NodeData{CreateTime(48)});
00071 map_by_time.Trim(map_by_id, mapping::NodeId{42, 1});
00072 map_by_id.Trim(mapping::NodeId{42, 1});
00073 ASSERT_TRUE(map_by_time.HasTrajectory(42));
00074 std::deque<Data> expected_data = {
00075 Data{CreateTime(1)}, Data{CreateTime(41)}, Data{CreateTime(42)},
00076 Data{CreateTime(48)}, Data{CreateTime(49)}, Data{CreateTime(5000)}};
00077 for (const Data& data : map_by_time.trajectory(42)) {
00078 ASSERT_FALSE(expected_data.empty());
00079 EXPECT_EQ(expected_data.front().time, data.time);
00080 expected_data.pop_front();
00081 }
00082 EXPECT_TRUE(expected_data.empty());
00083
00084 map_by_time.Trim(map_by_id, mapping::NodeId{42, 2});
00085 map_by_id.Trim(mapping::NodeId{42, 2});
00086 map_by_time.Trim(map_by_id, mapping::NodeId{42, 0});
00087 map_by_id.Trim(mapping::NodeId{42, 0});
00088 EXPECT_FALSE(map_by_time.HasTrajectory(42));
00089 }
00090
00091 TEST(MapByTimeTest, TrimmingDoesNotCreateTrajectory) {
00092 MapByTime<Data> map_by_time;
00093 EXPECT_FALSE(map_by_time.HasTrajectory(42));
00094 mapping::MapById<mapping::NodeId, NodeData> map_by_id;
00095 map_by_id.Append(42, NodeData{CreateTime(42)});
00096 map_by_time.Trim(map_by_id, mapping::NodeId{42, 0});
00097 EXPECT_FALSE(map_by_time.HasTrajectory(42));
00098 }
00099
00100 }
00101 }
00102 }