trajectory_connectivity_state_test.cc
Go to the documentation of this file.
00001 /*
00002  * Copyright 2017 The Cartographer Authors
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *      http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00017 #include "cartographer/mapping/internal/trajectory_connectivity_state.h"
00018 
00019 #include "gtest/gtest.h"
00020 
00021 namespace cartographer {
00022 namespace mapping {
00023 
00024 TEST(TrajectoryConnectivityStateTest, UnknownTrajectory) {
00025   TrajectoryConnectivityState state;
00026   state.Add(0);
00027 
00028   // Nothing is transitively connected to an unknown trajectory.
00029   EXPECT_FALSE(state.TransitivelyConnected(0, 1));
00030   EXPECT_EQ(state.LastConnectionTime(0, 1), common::Time());
00031 }
00032 
00033 TEST(TrajectoryConnectivityStateTest, NotConnected) {
00034   TrajectoryConnectivityState state;
00035   state.Add(0);
00036   state.Add(1);
00037   EXPECT_FALSE(state.TransitivelyConnected(0, 1));
00038   EXPECT_EQ(state.LastConnectionTime(0, 1), common::Time());
00039 }
00040 
00041 TEST(TrajectoryConnectivityStateTest, Connected) {
00042   TrajectoryConnectivityState state;
00043   state.Add(0);
00044   state.Add(1);
00045   state.Connect(0, 1, common::FromUniversal(123456));
00046   EXPECT_TRUE(state.TransitivelyConnected(0, 1));
00047   EXPECT_EQ(state.LastConnectionTime(0, 1), common::FromUniversal(123456));
00048 }
00049 
00050 TEST(TrajectoryConnectivityStateTest, UpdateConnectionTime) {
00051   TrajectoryConnectivityState state;
00052   state.Add(0);
00053   state.Add(1);
00054   state.Connect(0, 1, common::FromUniversal(123456));
00055   state.Connect(0, 1, common::FromUniversal(234567));
00056   EXPECT_TRUE(state.TransitivelyConnected(0, 1));
00057   EXPECT_EQ(state.LastConnectionTime(0, 1), common::FromUniversal(234567));
00058 
00059   // Connections with an earlier connection time do not update the last
00060   // connection time.
00061   state.Connect(0, 1, common::FromUniversal(123456));
00062   EXPECT_EQ(state.LastConnectionTime(0, 1), common::FromUniversal(234567));
00063 }
00064 
00065 TEST(TrajectoryConnectivityStateTest, JoinTwoComponents) {
00066   TrajectoryConnectivityState state;
00067   state.Add(0);
00068   state.Add(1);
00069   state.Add(2);
00070   state.Add(3);
00071   state.Connect(0, 1, common::FromUniversal(123456));
00072   state.Connect(2, 3, common::FromUniversal(123456));
00073 
00074   // Connect the two disjoint connected components.
00075   state.Connect(0, 2, common::FromUniversal(234567));
00076   EXPECT_TRUE(state.TransitivelyConnected(0, 2));
00077   EXPECT_TRUE(state.TransitivelyConnected(1, 3));
00078 
00079   // All bipartite trajectory pairs between the two connected components should
00080   // have the updated connection time.
00081   EXPECT_EQ(state.LastConnectionTime(0, 2), common::FromUniversal(234567));
00082   EXPECT_EQ(state.LastConnectionTime(0, 3), common::FromUniversal(234567));
00083   EXPECT_EQ(state.LastConnectionTime(1, 3), common::FromUniversal(234567));
00084 
00085   // A pair of trajectory IDs belonging to the same connected component should
00086   // be unaffected.
00087   EXPECT_EQ(state.LastConnectionTime(0, 1), common::FromUniversal(123456));
00088 }
00089 
00090 }  // namespace mapping
00091 }  // namespace cartographer


cartographer
Author(s): The Cartographer Authors
autogenerated on Thu May 9 2019 02:27:36