28 #include "gtest/gtest.h" 34 using test::CollatorInput;
37 TEST(Collator, Ordering) {
38 const int kTrajectoryId = 0;
39 const std::array<std::string, 4> kSensorId = {
40 {
"horizontal_rangefinder",
"vertical_rangefinder",
"imu",
"odometry"}};
42 std::vector<CollatorInput> input_data;
45 CollatorInput::CreateTimedPointCloudData(kTrajectoryId, kSensorId[0], 0));
47 CollatorInput::CreateTimedPointCloudData(kTrajectoryId, kSensorId[1], 0));
49 CollatorInput::CreateImuData(kTrajectoryId, kSensorId[2], 0));
51 CollatorInput::CreateOdometryData(kTrajectoryId, kSensorId[3], 0));
53 input_data.push_back(CollatorInput::CreateTimedPointCloudData(
54 kTrajectoryId, kSensorId[0], 100));
55 input_data.push_back(CollatorInput::CreateTimedPointCloudData(
56 kTrajectoryId, kSensorId[1], 200));
58 CollatorInput::CreateImuData(kTrajectoryId, kSensorId[2], 300));
59 input_data.push_back(CollatorInput::CreateTimedPointCloudData(
60 kTrajectoryId, kSensorId[0], 400));
61 input_data.push_back(CollatorInput::CreateTimedPointCloudData(
62 kTrajectoryId, kSensorId[1], 500));
64 CollatorInput::CreateOdometryData(kTrajectoryId, kSensorId[3], 600));
66 std::vector<CollatorOutput> received;
68 collator.AddTrajectory(
70 std::unordered_set<std::string>(kSensorId.begin(), kSensorId.end()),
71 [&received, kTrajectoryId](
const std::string& sensor_id,
72 std::unique_ptr<Data> data) {
73 received.push_back(
CollatorOutput(kTrajectoryId, data->GetSensorId(),
77 input_data[0].MoveToCollator(&collator);
78 input_data[1].MoveToCollator(&collator);
79 input_data[2].MoveToCollator(&collator);
80 input_data[3].MoveToCollator(&collator);
82 input_data[4].MoveToCollator(&collator);
83 input_data[9].MoveToCollator(&collator);
84 input_data[7].MoveToCollator(&collator);
85 input_data[5].MoveToCollator(&collator);
86 input_data[8].MoveToCollator(&collator);
87 input_data[6].MoveToCollator(&collator);
88 EXPECT_EQ(kTrajectoryId, collator.GetBlockingTrajectoryId().value());
90 ASSERT_EQ(7, received.size());
91 EXPECT_EQ(input_data[4].expected_output, received[4]);
92 EXPECT_EQ(input_data[5].expected_output, received[5]);
93 EXPECT_EQ(input_data[6].expected_output, received[6]);
95 collator.FinishTrajectory(kTrajectoryId);
97 ASSERT_EQ(input_data.size(), received.size());
98 for (
size_t i = 4; i < input_data.size(); ++i) {
99 EXPECT_EQ(input_data[i].expected_output, received[i]);
103 TEST(Collator, OrderingMultipleTrajectories) {
104 const int kTrajectoryId[] = {8, 5};
105 const std::array<std::string, 2> kSensorId = {{
"my_points",
"some_imu"}};
107 std::vector<CollatorInput> input_data;
109 input_data.push_back(CollatorInput::CreateTimedPointCloudData(
110 kTrajectoryId[0], kSensorId[0], 0));
111 input_data.push_back(
112 CollatorInput::CreateImuData(kTrajectoryId[0], kSensorId[1], 0));
113 input_data.push_back(CollatorInput::CreateTimedPointCloudData(
114 kTrajectoryId[1], kSensorId[0], 0));
115 input_data.push_back(
116 CollatorInput::CreateImuData(kTrajectoryId[1], kSensorId[1], 0));
118 input_data.push_back(CollatorInput::CreateTimedPointCloudData(
119 kTrajectoryId[0], kSensorId[0], 100));
120 input_data.push_back(
121 CollatorInput::CreateImuData(kTrajectoryId[1], kSensorId[1], 200));
122 input_data.push_back(
123 CollatorInput::CreateImuData(kTrajectoryId[0], kSensorId[1], 300));
124 input_data.push_back(CollatorInput::CreateTimedPointCloudData(
125 kTrajectoryId[1], kSensorId[0], 400));
126 input_data.push_back(CollatorInput::CreateTimedPointCloudData(
127 kTrajectoryId[1], kSensorId[0], 400));
128 input_data.push_back(CollatorInput::CreateTimedPointCloudData(
129 kTrajectoryId[1], kSensorId[0], 500));
130 input_data.push_back(
131 CollatorInput::CreateImuData(kTrajectoryId[1], kSensorId[1], 600));
133 std::vector<CollatorOutput> received;
135 collator.AddTrajectory(
137 std::unordered_set<std::string>(kSensorId.begin(), kSensorId.end()),
138 [&received, kTrajectoryId](
const std::string& sensor_id,
139 std::unique_ptr<Data> data) {
140 received.push_back(
CollatorOutput(kTrajectoryId[0], data->GetSensorId(),
143 collator.AddTrajectory(
145 std::unordered_set<std::string>(kSensorId.begin(), kSensorId.end()),
146 [&received, kTrajectoryId](
const std::string& sensor_id,
147 std::unique_ptr<Data> data) {
148 received.push_back(
CollatorOutput(kTrajectoryId[1], data->GetSensorId(),
152 input_data[0].MoveToCollator(&collator);
153 input_data[1].MoveToCollator(&collator);
154 input_data[2].MoveToCollator(&collator);
155 input_data[3].MoveToCollator(&collator);
157 input_data[4].MoveToCollator(&collator);
158 input_data[6].MoveToCollator(&collator);
159 EXPECT_EQ(kTrajectoryId[1], collator.GetBlockingTrajectoryId().value());
160 input_data[7].MoveToCollator(&collator);
161 input_data[8].MoveToCollator(&collator);
162 EXPECT_EQ(kTrajectoryId[1], collator.GetBlockingTrajectoryId().value());
163 input_data[5].MoveToCollator(&collator);
164 EXPECT_EQ(kTrajectoryId[0], collator.GetBlockingTrajectoryId().value());
165 input_data[10].MoveToCollator(&collator);
166 input_data[9].MoveToCollator(&collator);
167 EXPECT_EQ(kTrajectoryId[0], collator.GetBlockingTrajectoryId().value());
169 ASSERT_EQ(5, received.size());
170 EXPECT_EQ(input_data[4].expected_output, received[4]);
172 collator.FinishTrajectory(kTrajectoryId[0]);
173 collator.FinishTrajectory(kTrajectoryId[1]);
175 ASSERT_EQ(input_data.size(), received.size());
176 for (
size_t i = 4; i < input_data.size(); ++i) {
177 EXPECT_EQ(input_data[i].expected_output, received[i]);
std::tuple< int, std::string, common::Time > CollatorOutput
TEST(TrajectoryConnectivityStateTest, UnknownTrajectory)