range_data_test.cc
Go to the documentation of this file.
1 /*
2  * Copyright 2016 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 <utility>
20 #include <vector>
21 
22 #include "gmock/gmock.h"
23 
24 namespace cartographer {
25 namespace sensor {
26 namespace {
27 
28 using ::testing::Contains;
29 using ::testing::PrintToString;
30 
31 // Custom matcher for Eigen::Vector3f entries.
32 MATCHER_P(ApproximatelyEquals, expected,
33  string("is equal to ") + PrintToString(expected)) {
34  return (arg - expected).isZero(0.001f);
35 }
36 
37 TEST(RangeDataTest, Compression) {
38  const std::vector<Eigen::Vector3f> returns = {Eigen::Vector3f(0, 1, 2),
39  Eigen::Vector3f(4, 5, 6),
40  Eigen::Vector3f(0, 1, 2)};
41  const RangeData range_data = {
42  Eigen::Vector3f(1, 1, 1), returns, {Eigen::Vector3f(7, 8, 9)}};
43  const RangeData actual = Decompress(Compress(range_data));
44  EXPECT_TRUE(actual.origin.isApprox(Eigen::Vector3f(1, 1, 1), 1e-6));
45  EXPECT_EQ(3, actual.returns.size());
46  EXPECT_EQ(1, actual.misses.size());
47  EXPECT_TRUE(actual.misses[0].isApprox(Eigen::Vector3f(7, 8, 9), 0.001f));
48 
49  // Returns will be reordered, so we compare in an unordered manner.
50  EXPECT_EQ(3, actual.returns.size());
51  EXPECT_THAT(actual.returns,
52  Contains(ApproximatelyEquals(Eigen::Vector3f(0, 1, 2))));
53  EXPECT_THAT(actual.returns,
54  Contains(ApproximatelyEquals(Eigen::Vector3f(4, 5, 6))));
55 }
56 
57 } // namespace
58 } // namespace sensor
59 } // namespace cartographer
RangeData Decompress(const CompressedRangeData &compressed_range_data)
Definition: range_data.cc:63
CompressedRangeData Compress(const RangeData &range_data)
Definition: range_data.cc:56


cartographer
Author(s):
autogenerated on Wed Jun 5 2019 21:57:58