Drake
multilane_types_compare.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <gmock/gmock.h>
4 #include <gtest/gtest.h>
5 
9 
10 namespace drake {
11 namespace maliput {
12 namespace multilane {
13 namespace test {
14 
15 using ::testing::Matcher;
16 using ::testing::MatcherInterface;
17 using ::testing::MatchResultListener;
18 
19 // Compares equality within @p tolerance deviation of two EndpointXy objects.
20 // @param xy1 An EndpointXy object to compare.
21 // @param xy2 An EndpointXy object to compare.
22 // @param tolerance An allowable absolute deviation for each EndpointXy's
23 // coordinate.
24 // @return ::testing::AssertionFailure() When EndpointXy objects are different.
25 // @return ::testing::AssertionSuccess() When EndpointXy objects are within
26 // the @p tolerance deviation.
27 
28 // TODO(agalbachicar) Given that EndpointXy is composed of two lengths and
29 // one angle, tolerance must be replaced into two distinct
30 // values to match each magnitude.
31 ::testing::AssertionResult IsEndpointXyClose(const EndpointXy& xy1,
32  const EndpointXy& xy2,
33  double tolerance);
34 
35 // Compares equality within @p tolerance deviation of two EndpointZ objects.
36 // @param z1 An EndpointZ object to compare.
37 // @param z2 An EndpointZ object to compare.
38 // @param tolerance An allowable absolute deviation for each EndpointZ's
39 // coordinate.
40 // @return ::testing::AssertionFailure() When EndpointZ objects are different.
41 // @return ::testing::AssertionSuccess() When EndpointZ objects are within
42 // the @p tolerance deviation.
43 
44 // TODO(agalbachicar) Given that EndpointZ is composed of different
45 // magnitudes, tolerance must be replaced into distinct
46 // values to match each magnitude.
47 ::testing::AssertionResult IsEndpointZClose(const EndpointZ& z1,
48  const EndpointZ& z2,
49  double tolerance);
50 
51 // Compares equality within @p tolerance deviation of two Endpoint objects.
52 // @param pos1 An Endpoint object to compare.
53 // @param pos2 An Endpoint object to compare.
54 // @param tolerance An allowable absolute deviation for each Endpoint's
55 // coordinate.
56 // @return ::testing::AssertionFailure() When Endpoint objects are different.
57 // @return ::testing::AssertionSuccess() When Endpoint objects are within
58 // the @p tolerance deviation.
59 
60 // TODO(agalbachicar) Given that EndpointXy and EndpointZ are composed of
61 // different magnitudes, tolerance must be replaced into
62 // distinct values to match each magnitude.
63 ::testing::AssertionResult IsEndpointClose(const Endpoint& pos1,
64  const Endpoint& pos2,
65  double tolerance);
66 
67 // Compares equality within @p linear_tolerance and @p angular_tolerance
68 // deviations of two ArcOffset objects.
69 // @param arc_offset1 An ArcOffset object to compare.
70 // @param arc_offset2 An ArcOffset object to compare.
71 // @param linear_tolerance An allowable absolute linear deviation for
72 // ArcOffset's radius.
73 // @param angular_tolerance An allowable absolute angle deviation for
74 // ArcOffset's d_theta.
75 // @return ::testing::AssertionFailure() When ArcOffset objects are different.
76 // @return ::testing::AssertionSuccess() When ArcOffset objects are within
77 // @p linear_tolerance and @p angular_tolerance deviations.
78 ::testing::AssertionResult IsArcOffsetClose(const ArcOffset& arc_offset1,
79  const ArcOffset& arc_offset2,
80  double linear_tolerance,
81  double angular_tolerance);
82 
83 // Compares equality within @p tolerance of @p cubic1 and @p cubic2
84 // coefficients.
85 // @param cubic1 A CubicPolynomial object to compare.
86 // @param cubic2 A CubicPolynomial object to compare.
87 // @param tolerance An allowable absolute linear deviation for each coefficient.
88 // @return ::testing::AssertionFailure() When any coefficient of
89 // CubicPolynomial objects are different.
90 // @return ::testing::AssertionSuccess() When all coefficients of
91 // CubicPolynomial objects are equal.
92 ::testing::AssertionResult IsCubicPolynomialClose(const CubicPolynomial& cubic1,
93  const CubicPolynomial& cubic2,
94  double tolerance);
95 
96 /// Wraps api::HBounds comparison into a MatcherInterface.
97 class HBoundsMatcher : public MatcherInterface<const api::HBounds&> {
98  public:
100  : elevation_bounds_(elevation_bounds), tolerance_(tolerance) {}
101 
102  bool MatchAndExplain(const api::HBounds& other,
103  MatchResultListener*) const override {
104  return api::test::IsHBoundsClose(elevation_bounds_, other, tolerance_);
105  }
106 
107  void DescribeTo(std::ostream* os) const override {
108  *os << "is within tolerance [" << tolerance_ << "] of elevation_bounds: ["
109  << elevation_bounds_.min() << ", " << elevation_bounds_.max() << "].";
110  }
111 
112  private:
113  const api::HBounds elevation_bounds_;
114  const double tolerance_{};
115 };
116 
117 /// @return A Matcher<const api::HBounds&> of type HBoundsMatcher.
118 Matcher<const api::HBounds&> Matches(const api::HBounds& elevation_bounds,
119  double tolerance);
120 
121 /// Wraps an ArcOffset comparison into a MatcherInterface.
122 class ArcOffsetMatcher : public MatcherInterface<const ArcOffset&> {
123  public:
124  ArcOffsetMatcher(const ArcOffset& arc_offset, double linear_tolerance,
125  double angular_tolerance)
126  : arc_offset_(arc_offset),
127  linear_tolerance_(linear_tolerance),
128  angular_tolerance_(angular_tolerance) {}
129 
130  bool MatchAndExplain(const ArcOffset& other,
131  MatchResultListener*) const override {
132  return IsArcOffsetClose(arc_offset_, other, linear_tolerance_,
133  angular_tolerance_);
134  }
135 
136  void DescribeTo(std::ostream* os) const override {
137  *os << "is within linear and angular tolerance: [" << linear_tolerance_
138  << ", " << angular_tolerance_ << "] of arc_offset: ["
139  << arc_offset_.radius() << ", " << arc_offset_.d_theta() << "].";
140  }
141 
142  private:
143  const ArcOffset arc_offset_;
144  const double linear_tolerance_{};
145  const double angular_tolerance_{};
146 };
147 
148 /// @return A Matcher<const ArcOffset&> of type ArcOffsetMatcher.
149 Matcher<const ArcOffset&> Matches(const ArcOffset& arc_offset,
150  double linear_tolerance,
151  double angular_tolerance);
152 
153 /// Wraps a LineOffset comparison into a MatcherInterface.
154 class LineOffsetMatcher : public MatcherInterface<const LineOffset&> {
155  public:
156  LineOffsetMatcher(const LineOffset& line_offset, double tolerance)
157  : line_offset_(line_offset), tolerance_(tolerance) {}
158 
159  bool MatchAndExplain(const LineOffset& other,
160  MatchResultListener*) const override {
161  const double delta = std::abs(line_offset_.length() - other.length());
162  return delta <= tolerance_;
163  }
164 
165  void DescribeTo(std::ostream* os) const override {
166  *os << "is within tolerance: [" << tolerance_ << "] of line_offset: ["
167  << line_offset_ << "].";
168  }
169 
170  private:
171  const LineOffset line_offset_;
172  const double tolerance_{};
173 };
174 
175 /// @return A Matcher<const LineOffset&> of type LineOffsetMatcher.
176 Matcher<const LineOffset&> Matches(const LineOffset& line_offset,
177  double tolerance);
178 
179 /// Wraps a LineOffset comparison into a MatcherInterface.
180 class LaneLayoutMatcher : public MatcherInterface<const LaneLayout&> {
181  public:
182  LaneLayoutMatcher(const LaneLayout& lane_layout, double tolerance)
183  : lane_layout_(lane_layout), tolerance_(tolerance) {}
184 
185  bool MatchAndExplain(const LaneLayout& other,
186  MatchResultListener*) const override {
187  double delta{};
188 
189  delta = std::abs(lane_layout_.left_shoulder() - other.left_shoulder());
190  if (delta > tolerance_) return false;
191 
192  delta = std::abs(lane_layout_.right_shoulder() - other.right_shoulder());
193  if (delta > tolerance_) return false;
194 
195  if (lane_layout_.num_lanes() != other.num_lanes()) return false;
196 
197  if (lane_layout_.ref_lane() != other.ref_lane()) return false;
198 
199  delta = std::abs(lane_layout_.ref_r0() - other.ref_r0());
200  if (delta > tolerance_) return false;
201 
202  return true;
203  }
204 
205  void DescribeTo(std::ostream* os) const override {
206  *os << "is within tolerance: [" << tolerance_ << "] of lane_layout: ["
207  << lane_layout_ << "].";
208  }
209 
210  private:
211  const LaneLayout lane_layout_;
212  const double tolerance_{};
213 };
214 
215 /// @return A Matcher<const LaneLayout&> of type LaneLayoutMatcher.
216 Matcher<const LaneLayout&> Matches(const LaneLayout& lane_layout,
217  double tolerance);
218 
219 /// Wraps a StartReference::Spec comparison into a MatcherInterface.
221  : public MatcherInterface<const StartReference::Spec&> {
222  public:
224  double tolerance)
225  : start_reference_(start_reference), tolerance_(tolerance) {}
226 
228  MatchResultListener*) const override {
229  return IsEndpointClose(start_reference_.endpoint(), other.endpoint(),
230  tolerance_);
231  }
232 
233  void DescribeTo(std::ostream* os) const override {
234  *os << "is within tolerance: [" << tolerance_ << "] of start_reference: ["
235  << start_reference_ << "].";
236  }
237 
238  private:
239  const StartReference::Spec start_reference_;
240  const double tolerance_{};
241 };
242 
243 /// @return A Matcher<const StartReference::Spec&> of type
244 /// StartReferenceSpecMatcher.
245 Matcher<const StartReference::Spec&> Matches(
246  const StartReference::Spec& start_reference, double tolerance);
247 
248 /// Wraps a EndReference::Spec comparison into a MatcherInterface.
250  : public MatcherInterface<const EndReference::Spec&> {
251  public:
253  double tolerance)
254  : end_reference_(end_reference), tolerance_(tolerance) {}
255 
257  MatchResultListener*) const override {
258  return IsEndpointZClose(end_reference_.endpoint_z(), other.endpoint_z(),
259  tolerance_);
260  }
261 
262  void DescribeTo(std::ostream* os) const override {
263  *os << "is within tolerance: [" << tolerance_ << "] of end_reference: ["
264  << end_reference_ << "].";
265  }
266 
267  private:
268  const EndReference::Spec end_reference_;
269  const double tolerance_{};
270 };
271 
272 /// @return A Matcher<const EndReference::Spec&> of type
273 /// EndReferenceSpecMatcher.
274 Matcher<const EndReference::Spec&> Matches(
275  const EndReference::Spec& end_reference, double tolerance);
276 
277 } // namespace test
278 } // namespace multilane
279 } // namespace maliput
280 } // namespace drake
::testing::AssertionResult IsHBoundsClose(const HBounds &hbounds1, const HBounds &hbounds2, double tolerance)
Definition: maliput_types_compare.cc:184
double ref_r0() const
Definition: builder.h:338
void DescribeTo(std::ostream *os) const override
Definition: multilane_types_compare.h:107
bool MatchAndExplain(const api::HBounds &other, MatchResultListener *) const override
Definition: multilane_types_compare.h:102
double right_shoulder() const
Definition: builder.h:332
::testing::AssertionResult IsEndpointZClose(const EndpointZ &z1, const EndpointZ &z2, double tolerance)
Definition: multilane_types_compare.cc:58
Definition: automotive_demo.cc:90
bool MatchAndExplain(const StartReference::Spec &other, MatchResultListener *) const override
Definition: multilane_types_compare.h:227
Expression abs(const Expression &e)
Definition: symbolic_expression.cc:551
Defines how a Connection&#39;s reference curve starts.
Definition: builder.h:32
Wraps api::HBounds comparison into a MatcherInterface.
Definition: multilane_types_compare.h:97
LineOffsetMatcher(const LineOffset &line_offset, double tolerance)
Definition: multilane_types_compare.h:156
bool MatchAndExplain(const LineOffset &other, MatchResultListener *) const override
Definition: multilane_types_compare.h:159
void DescribeTo(std::ostream *os) const override
Definition: multilane_types_compare.h:233
void DescribeTo(std::ostream *os) const override
Definition: multilane_types_compare.h:165
StartReferenceSpecMatcher(const StartReference::Spec &start_reference, double tolerance)
Definition: multilane_types_compare.h:223
double length() const
Definition: connection.h:162
Wraps a EndReference::Spec comparison into a MatcherInterface.
Definition: multilane_types_compare.h:249
Wraps all the lane-related specifications in a Connection.
Definition: builder.h:301
double left_shoulder() const
Definition: builder.h:330
double max() const
Gets maximum bound.
Definition: lane_data.h:386
bool MatchAndExplain(const ArcOffset &other, MatchResultListener *) const override
Definition: multilane_types_compare.h:130
void DescribeTo(std::ostream *os) const override
Definition: multilane_types_compare.h:262
Definition: arc_road_curve.cc:11
double min() const
Gets minimum bound.
Definition: lane_data.h:378
Wraps a LineOffset comparison into a MatcherInterface.
Definition: multilane_types_compare.h:180
int num_lanes() const
Definition: builder.h:334
Specification for path offset along a line.
Definition: connection.h:152
const api::HBounds elevation_bounds
Definition: multilane_line_road_curve_test.cc:34
void DescribeTo(std::ostream *os) const override
Definition: multilane_types_compare.h:136
Wraps a LineOffset comparison into a MatcherInterface.
Definition: multilane_types_compare.h:154
::testing::AssertionResult IsEndpointXyClose(const EndpointXy &xy1, const EndpointXy &xy2, double tolerance)
Definition: multilane_types_compare.cc:13
::testing::AssertionResult IsArcOffsetClose(const ArcOffset &arc_offset1, const ArcOffset &arc_offset2, double linear_tolerance, double angular_tolerance)
Definition: multilane_types_compare.cc:156
HBoundsMatcher(const api::HBounds &elevation_bounds, double tolerance)
Definition: multilane_types_compare.h:99
Bounds in the elevation dimension (h component) of a Lane-frame, consisting of a pair of minimum and ...
Definition: lane_data.h:360
double tolerance_
Definition: model_test.cc:276
::testing::AssertionResult IsCubicPolynomialClose(const CubicPolynomial &cubic1, const CubicPolynomial &cubic2, double tolerance)
Definition: multilane_types_compare.cc:194
int ref_lane() const
Definition: builder.h:336
Wraps a StartReference::Spec comparison into a MatcherInterface.
Definition: multilane_types_compare.h:220
Defines how a Connection&#39;s reference curve ends.
Definition: builder.h:169
void DescribeTo(std::ostream *os) const override
Definition: multilane_types_compare.h:205
Specification for path offset along a circular arc.
Definition: connection.h:178
Wraps an ArcOffset comparison into a MatcherInterface.
Definition: multilane_types_compare.h:122
Matcher< const api::HBounds & > Matches(const api::HBounds &elevation_bounds, double tolerance)
Definition: multilane_types_compare.cc:228
ArcOffsetMatcher(const ArcOffset &arc_offset, double linear_tolerance, double angular_tolerance)
Definition: multilane_types_compare.h:124
const EndpointZ & endpoint_z() const
Definition: builder.h:173
EndReferenceSpecMatcher(const EndReference::Spec &end_reference, double tolerance)
Definition: multilane_types_compare.h:252
LaneLayoutMatcher(const LaneLayout &lane_layout, double tolerance)
Definition: multilane_types_compare.h:182
bool MatchAndExplain(const EndReference::Spec &other, MatchResultListener *) const override
Definition: multilane_types_compare.h:256
const double tolerance
Definition: dynamic_bicycle_car_test.cc:42
bool MatchAndExplain(const LaneLayout &other, MatchResultListener *) const override
Definition: multilane_types_compare.h:185
const Endpoint & endpoint() const
Definition: builder.h:36
::testing::AssertionResult IsEndpointClose(const Endpoint &p1, const Endpoint &p2, double tolerance)
Definition: multilane_types_compare.cc:125