Skip to content

Commit

Permalink
refactoring and fix cppcheck error
Browse files Browse the repository at this point in the history
Signed-off-by: Zulfaqar Azmi <[email protected]>
  • Loading branch information
zulfaqar-azmi-t4 committed Nov 20, 2024
1 parent 4520801 commit 64e5ef4
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 27 deletions.
2 changes: 1 addition & 1 deletion common/autoware_test_utils/src/mock_data_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ std::optional<PathWithLaneId> parse(const std::string & filename)

if (
!yaml_node["header"] || !yaml_node["points"] || !yaml_node["left_bound"] ||

Check warning on line 399 in common/autoware_test_utils/src/mock_data_parser.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

❌ New issue: Complex Conditional

parse has 1 complex conditionals with 3 branches, threshold = 2. A complex conditional is an expression inside a branch (e.g. if, for, while) which consists of multiple, logical operators such as AND/OR. The more logical operators in an expression, the more severe the code smell.
!yaml_node["left_bound"] || !yaml_node["right_bound"]) {
!yaml_node["right_bound"]) {
return std::nullopt;

Check warning on line 401 in common/autoware_test_utils/src/mock_data_parser.cpp

View check run for this annotation

Codecov / codecov/patch

common/autoware_test_utils/src/mock_data_parser.cpp#L401

Added line #L401 was not covered by tests
}

Expand Down
54 changes: 28 additions & 26 deletions common/autoware_test_utils/test/test_mock_data_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -582,27 +582,28 @@ TEST(ParseFunction, CompleteFromFilename)
autoware_test_utils_dir + "/test_data/lanelet_route_parser_test.yaml";

if (const auto lanelet_route_opt = parse<std::optional<LaneletRoute>>(parser_test_route)) {
EXPECT_DOUBLE_EQ(lanelet_route_opt->start_pose.position.x, 1.0);
EXPECT_DOUBLE_EQ(lanelet_route_opt->start_pose.position.y, 2.0);
EXPECT_DOUBLE_EQ(lanelet_route_opt->start_pose.position.z, 3.0);
const auto & lanelet_route = *lanelet_route_opt;
EXPECT_DOUBLE_EQ(lanelet_route.start_pose.position.x, 1.0);
EXPECT_DOUBLE_EQ(lanelet_route.start_pose.position.y, 2.0);
EXPECT_DOUBLE_EQ(lanelet_route.start_pose.position.z, 3.0);

EXPECT_DOUBLE_EQ(lanelet_route_opt->start_pose.orientation.x, 0.1);
EXPECT_DOUBLE_EQ(lanelet_route_opt->start_pose.orientation.y, 0.2);
EXPECT_DOUBLE_EQ(lanelet_route_opt->start_pose.orientation.z, 0.3);
EXPECT_DOUBLE_EQ(lanelet_route_opt->start_pose.orientation.w, 0.4);
EXPECT_DOUBLE_EQ(lanelet_route.start_pose.orientation.x, 0.1);
EXPECT_DOUBLE_EQ(lanelet_route.start_pose.orientation.y, 0.2);
EXPECT_DOUBLE_EQ(lanelet_route.start_pose.orientation.z, 0.3);
EXPECT_DOUBLE_EQ(lanelet_route.start_pose.orientation.w, 0.4);

EXPECT_DOUBLE_EQ(lanelet_route_opt->goal_pose.position.x, 4.0);
EXPECT_DOUBLE_EQ(lanelet_route_opt->goal_pose.position.y, 5.0);
EXPECT_DOUBLE_EQ(lanelet_route_opt->goal_pose.position.z, 6.0);
EXPECT_DOUBLE_EQ(lanelet_route_opt->goal_pose.orientation.x, 0.5);
EXPECT_DOUBLE_EQ(lanelet_route_opt->goal_pose.orientation.y, 0.6);
EXPECT_DOUBLE_EQ(lanelet_route_opt->goal_pose.orientation.z, 0.7);
EXPECT_DOUBLE_EQ(lanelet_route_opt->goal_pose.orientation.w, 0.8);
EXPECT_DOUBLE_EQ(lanelet_route.goal_pose.position.x, 4.0);
EXPECT_DOUBLE_EQ(lanelet_route.goal_pose.position.y, 5.0);
EXPECT_DOUBLE_EQ(lanelet_route.goal_pose.position.z, 6.0);
EXPECT_DOUBLE_EQ(lanelet_route.goal_pose.orientation.x, 0.5);
EXPECT_DOUBLE_EQ(lanelet_route.goal_pose.orientation.y, 0.6);
EXPECT_DOUBLE_EQ(lanelet_route.goal_pose.orientation.z, 0.7);
EXPECT_DOUBLE_EQ(lanelet_route.goal_pose.orientation.w, 0.8);

ASSERT_EQ(
lanelet_route_opt->segments.size(),
lanelet_route.segments.size(),
uint64_t(2)); // Assuming only one segment in the provided YAML for this test
const auto & segment1 = lanelet_route_opt->segments[1];
const auto & segment1 = lanelet_route.segments[1];
EXPECT_EQ(segment1.preferred_primitive.id, 44);
EXPECT_EQ(segment1.primitives.size(), uint64_t(4));
EXPECT_EQ(segment1.primitives[0].id, 55);
Expand All @@ -625,11 +626,12 @@ TEST(ParseFunction, ParsePathWithLaneID)
const auto parser_test_path =
autoware_test_utils_dir + "/test_data/path_with_lane_id_parser_test.yaml";

if (const auto path = parse<std::optional<PathWithLaneId>>(parser_test_path)) {
EXPECT_EQ(path->header.stamp.sec, 20);
EXPECT_EQ(path->header.stamp.nanosec, 5);
if (const auto path_opt = parse<std::optional<PathWithLaneId>>(parser_test_path)) {
const auto & path = *path_opt;
EXPECT_EQ(path.header.stamp.sec, 20);
EXPECT_EQ(path.header.stamp.nanosec, 5);

const auto path_points = path->points;
const auto path_points = path.points;
const auto & p1 = path_points.front();
EXPECT_DOUBLE_EQ(p1.point.pose.position.x, 12.9);
EXPECT_DOUBLE_EQ(p1.point.pose.position.y, 3.8);
Expand Down Expand Up @@ -658,13 +660,13 @@ TEST(ParseFunction, ParsePathWithLaneID)
EXPECT_FALSE(p2.point.is_final);
EXPECT_EQ(p2.lane_ids.front(), 205);

EXPECT_DOUBLE_EQ(path->left_bound.front().x, 55.0);
EXPECT_DOUBLE_EQ(path->left_bound.front().y, 66.0);
EXPECT_DOUBLE_EQ(path->left_bound.front().z, 77.0);
EXPECT_DOUBLE_EQ(path.left_bound.front().x, 55.0);
EXPECT_DOUBLE_EQ(path.left_bound.front().y, 66.0);
EXPECT_DOUBLE_EQ(path.left_bound.front().z, 77.0);

EXPECT_DOUBLE_EQ(path->right_bound.front().x, 0.55);
EXPECT_DOUBLE_EQ(path->right_bound.front().y, 0.66);
EXPECT_DOUBLE_EQ(path->right_bound.front().z, 0.77);
EXPECT_DOUBLE_EQ(path.right_bound.front().x, 0.55);
EXPECT_DOUBLE_EQ(path.right_bound.front().y, 0.66);
EXPECT_DOUBLE_EQ(path.right_bound.front().z, 0.77);
} else {
FAIL() << "Yaml file might've corrupted.";
}
Expand Down

0 comments on commit 64e5ef4

Please sign in to comment.