20 #include "gmock/gmock.h" 21 #include "gtest/gtest.h" 27 const int kNumSamples = 10;
29 sensor::TimedPointCloudData CreateFakeRangeData(
int from,
int to) {
33 Eigen::Vector3f(0., 1., 2.),
35 for (
int i = 0; i < kNumSamples; ++i) {
36 double fraction =
static_cast<double>(i) / (kNumSamples - 1);
37 double relative_time = (1.f - fraction) * -duration;
38 result.ranges[i] = Eigen::Vector4f(1., 2., 3., relative_time);
43 bool ArePointTimestampsSorted(
const sensor::TimedPointCloudOriginData& data) {
44 std::vector<float> timestamps;
45 timestamps.reserve(data.ranges.size());
46 for (
const auto& range : data.ranges) {
47 timestamps.push_back(range.point_time[3]);
49 return std::is_sorted(timestamps.begin(), timestamps.end());
52 TEST(RangeDataCollatorTest, SingleSensor) {
53 const std::string sensor_id =
"single_sensor";
54 RangeDataCollator collator({sensor_id});
56 collator.AddRangeData(sensor_id, CreateFakeRangeData(200, 300));
58 EXPECT_EQ(output_0.origins.size(), 1);
59 EXPECT_EQ(output_0.ranges.size(), kNumSamples);
60 EXPECT_TRUE(ArePointTimestampsSorted(output_0));
62 collator.AddRangeData(sensor_id, CreateFakeRangeData(300, 500));
64 EXPECT_EQ(output_1.origins.size(), 1);
65 ASSERT_EQ(output_1.ranges.size(), kNumSamples);
66 EXPECT_TRUE(ArePointTimestampsSorted(output_1));
72 collator.AddRangeData(sensor_id, CreateFakeRangeData(-1000, 510));
74 EXPECT_EQ(output_2.origins.size(), 1);
75 EXPECT_EQ(output_2.ranges.size(), 1);
76 EXPECT_EQ(output_2.ranges[0].point_time[3], 0.f);
77 EXPECT_TRUE(ArePointTimestampsSorted(output_2));
80 TEST(RangeDataCollatorTest, SingleSensorEmptyData) {
81 const std::string sensor_id =
"single_sensor";
82 RangeDataCollator collator({sensor_id});
84 auto output_0 = collator.AddRangeData(sensor_id, empty_data);
85 EXPECT_EQ(output_0.time, empty_data.time);
86 EXPECT_EQ(output_0.ranges.size(), empty_data.ranges.size());
87 EXPECT_TRUE(ArePointTimestampsSorted(output_0));
89 collator.AddRangeData(sensor_id, CreateFakeRangeData(300, 500));
91 EXPECT_EQ(output_1.origins.size(), 1);
92 ASSERT_EQ(output_1.ranges.size(), kNumSamples);
93 EXPECT_TRUE(ArePointTimestampsSorted(output_1));
99 collator.AddRangeData(sensor_id, CreateFakeRangeData(-1000, 510));
101 EXPECT_EQ(output_2.origins.size(), 1);
102 EXPECT_EQ(output_2.ranges.size(), 1);
103 EXPECT_EQ(output_2.ranges[0].point_time[3], 0.f);
104 EXPECT_TRUE(ArePointTimestampsSorted(output_2));
107 TEST(RangeDataCollatorTest, TwoSensors) {
108 const std::string sensor_0 =
"sensor_0";
109 const std::string sensor_1 =
"sensor_1";
110 RangeDataCollator collator({sensor_0, sensor_1});
112 collator.AddRangeData(sensor_0, CreateFakeRangeData(200, 300));
113 EXPECT_EQ(output_0.ranges.size(), 0);
115 collator.AddRangeData(sensor_1, CreateFakeRangeData(-1000, 310));
116 EXPECT_EQ(output_1.origins.size(), 2);
118 ASSERT_EQ(output_1.ranges.size(), 2 * kNumSamples - 1);
123 EXPECT_EQ(output_1.ranges.back().point_time[3], 0.f);
124 EXPECT_TRUE(ArePointTimestampsSorted(output_1));
126 collator.AddRangeData(sensor_0, CreateFakeRangeData(300, 500));
127 EXPECT_EQ(output_2.origins.size(), 2);
129 ASSERT_EQ(output_2.ranges.size(), 2);
134 EXPECT_EQ(output_2.ranges.back().point_time[3], 0.f);
135 EXPECT_TRUE(ArePointTimestampsSorted(output_2));
138 collator.AddRangeData(sensor_0, CreateFakeRangeData(600, 700));
141 output_1.ranges.size() + output_2.ranges.size() + output_3.ranges.size(),
143 EXPECT_EQ(output_3.ranges.back().point_time[3], 0.f);
144 EXPECT_TRUE(ArePointTimestampsSorted(output_3));
147 TEST(RangeDataCollatorTest, ThreeSensors) {
148 const std::string sensor_0 =
"sensor_0";
149 const std::string sensor_1 =
"sensor_1";
150 const std::string sensor_2 =
"sensor_2";
151 RangeDataCollator collator({sensor_0, sensor_1, sensor_2});
153 collator.AddRangeData(sensor_0, CreateFakeRangeData(100, 200));
154 EXPECT_EQ(output_0.ranges.size(), 0);
156 collator.AddRangeData(sensor_1, CreateFakeRangeData(199, 250));
157 EXPECT_EQ(output_1.ranges.size(), 0);
159 collator.AddRangeData(sensor_2, CreateFakeRangeData(210, 300));
160 EXPECT_EQ(output_2.ranges.size(), kNumSamples + 1);
161 EXPECT_TRUE(ArePointTimestampsSorted(output_2));
163 collator.AddRangeData(sensor_2, CreateFakeRangeData(400, 500));
164 EXPECT_EQ(output_2.ranges.size() + output_3.ranges.size(), 3 * kNumSamples);
165 EXPECT_TRUE(ArePointTimestampsSorted(output_3));
Time FromUniversal(const int64 ticks)
Duration FromSeconds(const double seconds)
int64 ToUniversal(const Time time)
double ToSeconds(const Duration duration)
std::vector< Eigen::Vector4f > TimedPointCloud
TEST(TrajectoryConnectivityStateTest, UnknownTrajectory)