Skip to content

Commit 1f74c5c

Browse files
committed
add initial unit test (for cut_predicted_path_beyond_line)
Signed-off-by: Maxime CLEMENT <maxime.clement@tier4.jp>
1 parent ee3f250 commit 1f74c5c

File tree

6 files changed

+74
-189
lines changed

6 files changed

+74
-189
lines changed

planning/motion_velocity_planner/autoware_motion_velocity_out_of_lane_module/CMakeLists.txt

+11
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,15 @@ ament_auto_add_library(${PROJECT_NAME} SHARED
99
DIRECTORY src
1010
)
1111

12+
if(BUILD_TESTING)
13+
find_package(ament_lint_auto REQUIRED)
14+
ament_lint_auto_find_test_dependencies()
15+
ament_add_ros_isolated_gtest(test_${PROJECT_NAME}
16+
test/test_filter_predicted_objects.cpp
17+
)
18+
target_link_libraries(test_${PROJECT_NAME}
19+
${PROJECT_NAME}
20+
)
21+
endif()
22+
1223
ament_auto_package(INSTALL_TO_SHARE config)

planning/motion_velocity_planner/autoware_motion_velocity_out_of_lane_module/package.xml

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212

1313
<license>Apache License 2.0</license>
1414

15-
<buildtool_depend>ament_cmake_auto</buildtool_depend>
1615
<buildtool_depend>autoware_cmake</buildtool_depend>
16+
1717
<depend>autoware_auto_perception_msgs</depend>
1818
<depend>autoware_auto_planning_msgs</depend>
1919
<depend>autoware_motion_velocity_planner_common</depend>
@@ -31,6 +31,7 @@
3131
<depend>vehicle_info_util</depend>
3232
<depend>visualization_msgs</depend>
3333

34+
<test_depend>ament_cmake_ros</test_depend>
3435
<test_depend>ament_lint_auto</test_depend>
3536
<test_depend>autoware_lint_common</test_depend>
3637

planning/motion_velocity_planner/autoware_motion_velocity_out_of_lane_module/src/filter_predicted_objects.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2024-2024 TIER IV, Inc.
1+
// Copyright 2024 TIER IV, Inc.
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -30,6 +30,8 @@ void cut_predicted_path_beyond_line(
3030
autoware_auto_perception_msgs::msg::PredictedPath & predicted_path,
3131
const lanelet::BasicLineString2d & stop_line, const double object_front_overhang)
3232
{
33+
if (predicted_path.path.empty() || stop_line.size() < 2) return;
34+
3335
auto stop_line_idx = 0UL;
3436
bool found = false;
3537
lanelet::BasicSegment2d path_segment;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// Copyright 2024 TIER IV, Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#include "../src/filter_predicted_objects.hpp"
16+
17+
#include <autoware_auto_perception_msgs/msg/predicted_object.hpp>
18+
#include <autoware_auto_perception_msgs/msg/predicted_objects.hpp>
19+
#include <autoware_auto_perception_msgs/msg/predicted_path.hpp>
20+
21+
#include <gtest/gtest.h>
22+
#include <lanelet2_core/geometry/LineString.h>
23+
24+
TEST(TestCollisionDistance, CutPredictedPathBeyondLine)
25+
{
26+
using autoware::motion_velocity_planner::out_of_lane::cut_predicted_path_beyond_line;
27+
autoware_auto_perception_msgs::msg::PredictedPath predicted_path;
28+
lanelet::BasicLineString2d stop_line;
29+
double object_front_overhang = 0.0;
30+
const auto eps = 1e-9;
31+
32+
EXPECT_NO_THROW(cut_predicted_path_beyond_line(predicted_path, stop_line, object_front_overhang));
33+
34+
geometry_msgs::msg::Pose pose;
35+
pose.position.x = 0.0;
36+
pose.position.y = 0.0;
37+
predicted_path.path.push_back(pose);
38+
pose.position.y = 1.0;
39+
predicted_path.path.push_back(pose);
40+
pose.position.y = 2.0;
41+
predicted_path.path.push_back(pose);
42+
pose.position.y = 3.0;
43+
predicted_path.path.push_back(pose);
44+
45+
cut_predicted_path_beyond_line(predicted_path, stop_line, object_front_overhang);
46+
EXPECT_EQ(predicted_path.path.size(), 4UL);
47+
for (auto i = 0UL; i < predicted_path.path.size(); ++i) {
48+
EXPECT_EQ(predicted_path.path[i].position.x, 0.0);
49+
EXPECT_NEAR(predicted_path.path[i].position.y, static_cast<double>(i), eps);
50+
}
51+
stop_line = {{-1.0, 2.0}, {1.0, 2.0}};
52+
cut_predicted_path_beyond_line(predicted_path, stop_line, object_front_overhang);
53+
EXPECT_EQ(predicted_path.path.size(), 2UL);
54+
for (auto i = 0UL; i < predicted_path.path.size(); ++i) {
55+
EXPECT_EQ(predicted_path.path[i].position.x, 0.0);
56+
EXPECT_NEAR(predicted_path.path[i].position.y, static_cast<double>(i), eps);
57+
}
58+
}

planning/motion_velocity_planner/autoware_motion_velocity_planner_common/CMakeLists.txt

-11
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,6 @@ autoware_package()
99
# DIRECTORY src
1010
# )
1111

12-
if(BUILD_TESTING)
13-
# ament_add_ros_isolated_gtest(test_${PROJECT_NAME}
14-
# test/src/test_node_interface.cpp TODO(Maxime)
15-
# )
16-
# target_link_libraries(test_${PROJECT_NAME}
17-
# gtest_main
18-
# ${PROJECT_NAME}_lib
19-
# )
20-
# target_include_directories(test_${PROJECT_NAME} PRIVATE src)
21-
endif()
22-
2312
ament_auto_package(INSTALL_TO_SHARE
2413
include
2514
)

planning/motion_velocity_planner/autoware_motion_velocity_planner_common/test/src/test_node_interface.cpp

-176
This file was deleted.

0 commit comments

Comments
 (0)