Branch data Line data Source code
1 : : // ----------------- BEGIN LICENSE BLOCK ---------------------------------
2 : : //
3 : : // Copyright (C) 2018-2021 Intel Corporation
4 : : //
5 : : // SPDX-License-Identifier: LGPL-2.1-only
6 : : //
7 : : // ----------------- END LICENSE BLOCK -----------------------------------
8 : :
9 : : #include "TestSupport.hpp"
10 : : #include "ad/rss/core/RssResponseResolving.hpp"
11 : :
12 : : namespace ad {
13 : : namespace rss {
14 : : namespace core {
15 : :
16 : : using state::LateralResponse;
17 : : using state::LongitudinalResponse;
18 : :
19 : : class RssResponseResolvingTests : public testing::Test
20 : : {
21 : : protected:
22 : 9 : void SetUp() override
23 : : {
24 : 9 : state::RssState rssStateT1O1;
25 : 9 : state::RssState rssStateT1O2;
26 : 9 : state::RssState rssStateT2O1;
27 : 9 : state::RssState rssStateT2O2;
28 : 9 : state::RssState rssStateT3O1;
29 : 9 : state::RssState rssStateT3O2;
30 [ + - ]: 9 : resetRssState(rssStateT1O1, 1u, 1u, world::ConstellationType::SameDirection);
31 [ + - ]: 9 : resetRssState(rssStateT1O2, 2u, 2u, world::ConstellationType::SameDirection);
32 [ + - ]: 9 : resetRssState(rssStateT2O1, 1u, 1u, world::ConstellationType::SameDirection);
33 [ + - ]: 9 : resetRssState(rssStateT2O2, 2u, 2u, world::ConstellationType::SameDirection);
34 [ + - ]: 9 : resetRssState(rssStateT3O1, 1u, 1u, world::ConstellationType::SameDirection);
35 [ + - ]: 9 : resetRssState(rssStateT3O2, 2u, 2u, world::ConstellationType::SameDirection);
36 : 9 : rssStateSnapshotT1.time_index = 1u;
37 [ + - ]: 9 : rssStateSnapshotT1.default_ego_vehicle_rss_dynamics = getEgoRssDynamics();
38 [ + - ]: 9 : rssStateSnapshotT1.individual_responses.push_back(rssStateT1O1);
39 [ + - ]: 9 : rssStateSnapshotT1.individual_responses.push_back(rssStateT1O2);
40 : :
41 : 9 : rssStateSnapshotT2.time_index = 2u;
42 [ + - ]: 9 : rssStateSnapshotT2.default_ego_vehicle_rss_dynamics = getEgoRssDynamics();
43 [ + - ]: 9 : rssStateSnapshotT2.individual_responses.push_back(rssStateT2O1);
44 [ + - ]: 9 : rssStateSnapshotT2.individual_responses.push_back(rssStateT2O2);
45 : :
46 : 9 : rssStateSnapshotT3.time_index = 3u;
47 [ + - ]: 9 : rssStateSnapshotT3.default_ego_vehicle_rss_dynamics = getEgoRssDynamics();
48 [ + - ]: 9 : rssStateSnapshotT3.individual_responses.push_back(rssStateT3O1);
49 [ + - ]: 9 : rssStateSnapshotT3.individual_responses.push_back(rssStateT3O2);
50 : :
51 [ + - ]: 9 : resetRssState(resultProperResponseT1);
52 [ + - ]: 9 : resetRssState(resultProperResponseT2);
53 [ + - ]: 9 : resetRssState(resultProperResponseT3);
54 : 9 : }
55 : :
56 : 9 : void TearDown() override
57 : : {
58 : 9 : }
59 : :
60 : 14 : void testResultStateNone(state::ProperResponse &resultProperResponse)
61 : : {
62 [ + - ]: 14 : testResultState(
63 : : resultProperResponse, true, LongitudinalResponse::None, LateralResponse::None, LateralResponse::None);
64 : 14 : }
65 : :
66 : 23 : void testResultState(state::ProperResponse &resultProperResponse,
67 : : bool is_safe,
68 : : LongitudinalResponse lonResponse,
69 : : LateralResponse latResponseLeft,
70 : : LateralResponse latResponseRight,
71 : : world::ObjectIdVector dangerous_objects = world::ObjectIdVector())
72 : : {
73 [ + - - + : 23 : EXPECT_EQ(is_safe, resultProperResponse.is_safe);
- - - - -
- ]
74 [ + - - + : 23 : EXPECT_EQ(lonResponse, resultProperResponse.longitudinal_response);
- - - - -
- ]
75 [ + - - + : 23 : EXPECT_EQ(latResponseLeft, resultProperResponse.lateral_response_left);
- - - - -
- ]
76 [ + - - + : 23 : EXPECT_EQ(latResponseRight, resultProperResponse.lateral_response_right);
- - - - -
- ]
77 [ + - - + : 23 : EXPECT_EQ(dangerous_objects, resultProperResponse.dangerous_objects);
- - - - -
- ]
78 : 23 : }
79 : :
80 : 9 : void performTest(bool expectedResultT1 = true, bool expectedResultT2 = true, bool expectedResultT3 = true)
81 : : {
82 : : RssResponseResolving provider;
83 : :
84 [ + - + - : 9 : EXPECT_EQ(expectedResultT1, provider.provideProperResponse(rssStateSnapshotT1, resultProperResponseT1));
- + - - -
- - - ]
85 [ + - + - : 9 : EXPECT_EQ(expectedResultT2, provider.provideProperResponse(rssStateSnapshotT2, resultProperResponseT2));
- + - - -
- - - ]
86 [ + - + - : 9 : EXPECT_EQ(expectedResultT3, provider.provideProperResponse(rssStateSnapshotT3, resultProperResponseT3));
- + - - -
- - - ]
87 : 9 : }
88 : :
89 : : state::RssStateSnapshot rssStateSnapshotT1;
90 : : state::RssStateSnapshot rssStateSnapshotT2;
91 : : state::RssStateSnapshot rssStateSnapshotT3;
92 : :
93 : : state::ProperResponse resultProperResponseT1;
94 : : state::ProperResponse resultProperResponseT2;
95 : : state::ProperResponse resultProperResponseT3;
96 : : };
97 : :
98 : 4 : TEST_F(RssResponseResolvingTests, validateTestSetup)
99 : : {
100 : 1 : performTest(true);
101 : 1 : testResultStateNone(resultProperResponseT1);
102 : 1 : testResultStateNone(resultProperResponseT2);
103 : 1 : testResultStateNone(resultProperResponseT3);
104 : 1 : }
105 : :
106 : 4 : TEST_F(RssResponseResolvingTests, invalidState)
107 : : {
108 : 1 : rssStateSnapshotT1.individual_responses[0].longitudinal_state.response = LongitudinalResponse(-1);
109 : 1 : performTest(false);
110 : 1 : }
111 : :
112 : 4 : TEST_F(RssResponseResolvingTests, provideProperResponseLateralLeft)
113 : : {
114 : 1 : setRssStateUnsafe(rssStateSnapshotT1.individual_responses[0].longitudinal_state, LongitudinalResponse::None);
115 : 1 : setRssStateUnsafe(rssStateSnapshotT2.individual_responses[0].longitudinal_state, LongitudinalResponse::None);
116 : 1 : setRssStateUnsafe(rssStateSnapshotT2.individual_responses[0].lateral_state_left, LateralResponse::BrakeMin);
117 : :
118 : 1 : performTest();
119 : 1 : testResultStateNone(resultProperResponseT1);
120 [ + - ]: 2 : testResultState(
121 [ + - ]: 1 : resultProperResponseT2, false, LongitudinalResponse::None, LateralResponse::BrakeMin, LateralResponse::None, {1});
122 : 1 : testResultStateNone(resultProperResponseT3);
123 : 1 : }
124 : :
125 : 4 : TEST_F(RssResponseResolvingTests, provideProperResponseLateralRight)
126 : : {
127 : 1 : setRssStateUnsafe(rssStateSnapshotT1.individual_responses[0].longitudinal_state, LongitudinalResponse::BrakeMin);
128 : 1 : setRssStateUnsafe(rssStateSnapshotT2.individual_responses[0].longitudinal_state, LongitudinalResponse::BrakeMin);
129 : 1 : setRssStateUnsafe(rssStateSnapshotT2.individual_responses[0].lateral_state_right, LateralResponse::BrakeMin);
130 : :
131 : 1 : performTest();
132 : 1 : testResultStateNone(resultProperResponseT1);
133 [ + - + - ]: 1 : testResultState(resultProperResponseT2,
134 : : false,
135 : : LongitudinalResponse::BrakeMin,
136 : : LateralResponse::None,
137 : : LateralResponse::BrakeMin,
138 : : {1});
139 : 1 : testResultStateNone(resultProperResponseT3);
140 : 1 : }
141 : :
142 : 4 : TEST_F(RssResponseResolvingTests, provideProperResponseLongitudinal)
143 : : {
144 : 1 : setRssStateUnsafe(rssStateSnapshotT1.individual_responses[0].lateral_state_right, LateralResponse::BrakeMin);
145 : 1 : setRssStateUnsafe(rssStateSnapshotT2.individual_responses[0].longitudinal_state, LongitudinalResponse::BrakeMin);
146 : 1 : setRssStateUnsafe(rssStateSnapshotT2.individual_responses[0].lateral_state_right, LateralResponse::BrakeMin);
147 : :
148 : 1 : performTest();
149 : 1 : testResultStateNone(resultProperResponseT1);
150 [ + - + - ]: 1 : testResultState(resultProperResponseT2,
151 : : false,
152 : : LongitudinalResponse::BrakeMin,
153 : : LateralResponse::None,
154 : : LateralResponse::BrakeMin,
155 : : {1});
156 : 1 : testResultStateNone(resultProperResponseT3);
157 : 1 : }
158 : :
159 : 4 : TEST_F(RssResponseResolvingTests, provideProperResponseLongitudinal_None)
160 : : {
161 : 1 : setRssStateUnsafe(rssStateSnapshotT1.individual_responses[0].lateral_state_right, LateralResponse::BrakeMin);
162 : 1 : setRssStateUnsafe(rssStateSnapshotT2.individual_responses[0].longitudinal_state, LongitudinalResponse::None);
163 : 1 : setRssStateUnsafe(rssStateSnapshotT2.individual_responses[0].lateral_state_right, LateralResponse::BrakeMin);
164 : :
165 : 1 : performTest();
166 : 1 : testResultStateNone(resultProperResponseT1);
167 [ + - ]: 2 : testResultState(
168 [ + - ]: 1 : resultProperResponseT2, false, LongitudinalResponse::None, LateralResponse::None, LateralResponse::BrakeMin, {1});
169 : 1 : }
170 : :
171 : 4 : TEST_F(RssResponseResolvingTests, provideProperResponseBothDirections)
172 : : {
173 : 1 : setRssStateUnsafe(rssStateSnapshotT1.individual_responses[0].longitudinal_state, LongitudinalResponse::BrakeMin);
174 : 1 : setRssStateUnsafe(rssStateSnapshotT1.individual_responses[0].lateral_state_right, LateralResponse::BrakeMin);
175 : :
176 : 1 : performTest();
177 [ + - + - ]: 1 : testResultState(resultProperResponseT1,
178 : : false,
179 : : LongitudinalResponse::BrakeMin,
180 : : LateralResponse::None,
181 : : LateralResponse::BrakeMin,
182 : : {1});
183 : 1 : testResultStateNone(resultProperResponseT2);
184 : 1 : testResultStateNone(resultProperResponseT3);
185 : 1 : }
186 : :
187 : 4 : TEST_F(RssResponseResolvingTests, provideProperResponseLongitudinalMoreSevere)
188 : : {
189 : 1 : setRssStateUnsafe(rssStateSnapshotT1.individual_responses[0].lateral_state_right, LateralResponse::BrakeMin);
190 : 1 : setRssStateUnsafe(rssStateSnapshotT2.individual_responses[0].longitudinal_state,
191 : : LongitudinalResponse::BrakeMinCorrect);
192 : 1 : setRssStateUnsafe(rssStateSnapshotT2.individual_responses[0].lateral_state_right, LateralResponse::BrakeMin);
193 : 1 : setRssStateUnsafe(rssStateSnapshotT3.individual_responses[0].longitudinal_state, LongitudinalResponse::BrakeMin);
194 : 1 : setRssStateUnsafe(rssStateSnapshotT3.individual_responses[0].lateral_state_right, LateralResponse::BrakeMin);
195 : :
196 : 1 : performTest();
197 : 1 : testResultStateNone(resultProperResponseT1);
198 [ + - + - ]: 1 : testResultState(resultProperResponseT2,
199 : : false,
200 : : LongitudinalResponse::BrakeMinCorrect,
201 : : LateralResponse::None,
202 : : LateralResponse::BrakeMin,
203 : : {1});
204 [ + - + - ]: 1 : testResultState(resultProperResponseT3,
205 : : false,
206 : : LongitudinalResponse::BrakeMin,
207 : : LateralResponse::None,
208 : : LateralResponse::BrakeMin,
209 : : {1});
210 : 1 : }
211 : :
212 : 4 : TEST_F(RssResponseResolvingTests, provideProperResponseDangerousInitialState)
213 : : {
214 : 1 : setRssStateUnsafe(rssStateSnapshotT1.individual_responses[0].lateral_state_right, LateralResponse::BrakeMin);
215 : 1 : setRssStateUnsafe(rssStateSnapshotT1.individual_responses[0].longitudinal_state, LongitudinalResponse::BrakeMin);
216 : 1 : setRssStateUnsafe(rssStateSnapshotT2.individual_responses[0].lateral_state_right, LateralResponse::BrakeMin);
217 : 1 : setRssStateUnsafe(rssStateSnapshotT2.individual_responses[0].longitudinal_state, LongitudinalResponse::BrakeMin);
218 : :
219 : 1 : performTest();
220 [ + - + - ]: 1 : testResultState(resultProperResponseT1,
221 : : false,
222 : : LongitudinalResponse::BrakeMin,
223 : : LateralResponse::None,
224 : : LateralResponse::BrakeMin,
225 : : {1});
226 [ + - + - ]: 1 : testResultState(resultProperResponseT2,
227 : : false,
228 : : LongitudinalResponse::BrakeMin,
229 : : LateralResponse::None,
230 : : LateralResponse::BrakeMin,
231 : : {1});
232 : 1 : testResultStateNone(resultProperResponseT3);
233 : 1 : }
234 : :
235 : : } // namespace core
236 : : } // namespace rss
237 : : } // namespace ad
|