trajectory_connectivity_state_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 "gtest/gtest.h"
20 
21 namespace cartographer {
22 namespace mapping {
23 
24 TEST(TrajectoryConnectivityStateTest, UnknownTrajectory) {
26  state.Add(0);
27 
28  // Nothing is transitively connected to an unknown trajectory.
29  EXPECT_FALSE(state.TransitivelyConnected(0, 1));
30  EXPECT_EQ(state.LastConnectionTime(0, 1), common::Time());
31 }
32 
33 TEST(TrajectoryConnectivityStateTest, NotConnected) {
35  state.Add(0);
36  state.Add(1);
37  EXPECT_FALSE(state.TransitivelyConnected(0, 1));
38  EXPECT_EQ(state.LastConnectionTime(0, 1), common::Time());
39 }
40 
41 TEST(TrajectoryConnectivityStateTest, Connected) {
43  state.Add(0);
44  state.Add(1);
45  state.Connect(0, 1, common::FromUniversal(123456));
46  EXPECT_TRUE(state.TransitivelyConnected(0, 1));
47  EXPECT_EQ(state.LastConnectionTime(0, 1), common::FromUniversal(123456));
48 }
49 
50 TEST(TrajectoryConnectivityStateTest, UpdateConnectionTime) {
52  state.Add(0);
53  state.Add(1);
54  state.Connect(0, 1, common::FromUniversal(123456));
55  state.Connect(0, 1, common::FromUniversal(234567));
56  EXPECT_TRUE(state.TransitivelyConnected(0, 1));
57  EXPECT_EQ(state.LastConnectionTime(0, 1), common::FromUniversal(234567));
58 
59  // Connections with an earlier connection time do not update the last
60  // connection time.
61  state.Connect(0, 1, common::FromUniversal(123456));
62  EXPECT_EQ(state.LastConnectionTime(0, 1), common::FromUniversal(234567));
63 }
64 
65 TEST(TrajectoryConnectivityStateTest, JoinTwoComponents) {
67  state.Add(0);
68  state.Add(1);
69  state.Add(2);
70  state.Add(3);
71  state.Connect(0, 1, common::FromUniversal(123456));
72  state.Connect(2, 3, common::FromUniversal(123456));
73 
74  // Connect the two disjoint connected components.
75  state.Connect(0, 2, common::FromUniversal(234567));
76  EXPECT_TRUE(state.TransitivelyConnected(0, 2));
77  EXPECT_TRUE(state.TransitivelyConnected(1, 3));
78 
79  // All bipartite trajectory pairs between the two connected components should
80  // have the updated connection time.
81  EXPECT_EQ(state.LastConnectionTime(0, 2), common::FromUniversal(234567));
82  EXPECT_EQ(state.LastConnectionTime(0, 3), common::FromUniversal(234567));
83  EXPECT_EQ(state.LastConnectionTime(1, 3), common::FromUniversal(234567));
84 
85  // A pair of trajectory IDs belonging to the same connected component should
86  // be unaffected.
87  EXPECT_EQ(state.LastConnectionTime(0, 1), common::FromUniversal(123456));
88 }
89 
90 } // namespace mapping
91 } // namespace cartographer
void Connect(int trajectory_id_a, int trajectory_id_b, common::Time time)
UniversalTimeScaleClock::time_point Time
Definition: time.h:44
Time FromUniversal(const int64 ticks)
Definition: time.cc:34
common::Time LastConnectionTime(int trajectory_id_a, int trajectory_id_b)
bool TransitivelyConnected(int trajectory_id_a, int trajectory_id_b) const
TEST(TrajectoryConnectivityStateTest, UnknownTrajectory)


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