map_by_time_test.cc
Go to the documentation of this file.
1 /*
2  * Copyright 2017 The Cartographer Authors
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
18 
19 #include <deque>
20 
22 #include "gtest/gtest.h"
23 
24 namespace cartographer {
25 namespace sensor {
26 namespace {
27 
28 common::Time CreateTime(const int milliseconds) {
29  return common::Time(common::FromMilliseconds(milliseconds));
30 }
31 
32 struct Data {
34 };
35 
36 struct NodeData {
38 };
39 
40 TEST(MapByTimeTest, AppendAndViewTrajectory) {
41  MapByTime<Data> map_by_time;
42  map_by_time.Append(0, Data{CreateTime(10)});
43  map_by_time.Append(42, Data{CreateTime(42)});
44  map_by_time.Append(42, Data{CreateTime(43)});
45  std::deque<Data> expected_data = {Data{CreateTime(42)}, Data{CreateTime(43)}};
46  for (const Data& data : map_by_time.trajectory(42)) {
47  ASSERT_FALSE(expected_data.empty());
48  EXPECT_EQ(expected_data.front().time, data.time);
49  expected_data.pop_front();
50  }
51  EXPECT_TRUE(expected_data.empty());
52 }
53 
54 TEST(MapByTimeTest, Trimming) {
55  MapByTime<Data> map_by_time;
56  EXPECT_FALSE(map_by_time.HasTrajectory(42));
57  map_by_time.Append(42, Data{CreateTime(1)});
58  map_by_time.Append(42, Data{CreateTime(41)});
59  map_by_time.Append(42, Data{CreateTime(42)});
60  map_by_time.Append(42, Data{CreateTime(43)});
61  map_by_time.Append(42, Data{CreateTime(47)});
62  map_by_time.Append(42, Data{CreateTime(48)});
63  map_by_time.Append(42, Data{CreateTime(49)});
64  map_by_time.Append(42, Data{CreateTime(5000)});
65  EXPECT_TRUE(map_by_time.HasTrajectory(42));
66  // Trim one node.
67  mapping::MapById<mapping::NodeId, NodeData> map_by_id;
68  map_by_id.Append(42, NodeData{CreateTime(42)});
69  map_by_id.Append(42, NodeData{CreateTime(46)});
70  map_by_id.Append(42, NodeData{CreateTime(48)});
71  map_by_time.Trim(map_by_id, mapping::NodeId{42, 1});
72  map_by_id.Trim(mapping::NodeId{42, 1});
73  ASSERT_TRUE(map_by_time.HasTrajectory(42));
74  std::deque<Data> expected_data = {
75  Data{CreateTime(1)}, Data{CreateTime(41)}, Data{CreateTime(42)},
76  Data{CreateTime(48)}, Data{CreateTime(49)}, Data{CreateTime(5000)}};
77  for (const Data& data : map_by_time.trajectory(42)) {
78  ASSERT_FALSE(expected_data.empty());
79  EXPECT_EQ(expected_data.front().time, data.time);
80  expected_data.pop_front();
81  }
82  EXPECT_TRUE(expected_data.empty());
83  // Trim everything.
84  map_by_time.Trim(map_by_id, mapping::NodeId{42, 2});
85  map_by_id.Trim(mapping::NodeId{42, 2});
86  map_by_time.Trim(map_by_id, mapping::NodeId{42, 0});
87  map_by_id.Trim(mapping::NodeId{42, 0});
88  EXPECT_FALSE(map_by_time.HasTrajectory(42));
89 }
90 
91 TEST(MapByTimeTest, TrimmingDoesNotCreateTrajectory) {
92  MapByTime<Data> map_by_time;
93  EXPECT_FALSE(map_by_time.HasTrajectory(42));
94  mapping::MapById<mapping::NodeId, NodeData> map_by_id;
95  map_by_id.Append(42, NodeData{CreateTime(42)});
96  map_by_time.Trim(map_by_id, mapping::NodeId{42, 0});
97  EXPECT_FALSE(map_by_time.HasTrajectory(42));
98 }
99 
100 } // namespace
101 } // namespace sensor
102 } // namespace cartographer
common::Duration FromMilliseconds(const int64 milliseconds)
Definition: time.cc:43
UniversalTimeScaleClock::time_point Time
Definition: time.h:44
common::Time time
Data(const std::string &sensor_id)
Definition: data.h:34
TEST(TrajectoryConnectivityStateTest, UnknownTrajectory)


cartographer
Author(s): The Cartographer Authors
autogenerated on Mon Feb 28 2022 22:00:58