Skip to content

Commit

Permalink
test(detected_object_validation): add unit tests of utils (#7144)
Browse files Browse the repository at this point in the history
test: add unit tests

Signed-off-by: ktro2828 <[email protected]>
  • Loading branch information
ktro2828 authored May 28, 2024
1 parent f28a757 commit d482924
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 0 deletions.
6 changes: 6 additions & 0 deletions perception/detected_object_validation/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ rclcpp_components_register_node(occupancy_grid_based_validator
EXECUTABLE occupancy_grid_based_validator_node
)

if(BUILD_TESTING)
ament_auto_add_gtest(detection_object_validation_tests
test/test_utils.cpp
)
endif()

ament_auto_package(INSTALL_TO_SHARE
launch
config
Expand Down
67 changes: 67 additions & 0 deletions perception/detected_object_validation/test/test_utils.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// Copyright 2024 TIER IV, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include "detected_object_validation/utils/utils.hpp"

#include <autoware_auto_perception_msgs/msg/object_classification.hpp>

#include <gtest/gtest.h>

using AutowareLabel = autoware_auto_perception_msgs::msg::ObjectClassification;

utils::FilterTargetLabel createFilterTargetAll()
{
utils::FilterTargetLabel filter;
filter.UNKNOWN = true;
filter.CAR = true;
filter.TRUCK = true;
filter.BUS = true;
filter.TRAILER = true;
filter.MOTORCYCLE = true;
filter.BICYCLE = true;
filter.PEDESTRIAN = true;
return filter;
}

utils::FilterTargetLabel createFilterTargetVehicle()
{
utils::FilterTargetLabel filter;
filter.UNKNOWN = false;
filter.CAR = true;
filter.TRUCK = true;
filter.BUS = true;
filter.TRAILER = true;
filter.MOTORCYCLE = false;
filter.BICYCLE = false;
filter.PEDESTRIAN = false;
return filter;
}

TEST(IsTargetTest, AllTarget)
{
auto filter = createFilterTargetAll();
auto label = AutowareLabel::CAR;
EXPECT_TRUE(filter.isTarget(label));
}

TEST(IsTargetTest, VehicleTarget)
{
auto filter = createFilterTargetVehicle();

auto car_label = AutowareLabel::CAR;
EXPECT_TRUE(filter.isTarget(car_label));

auto unknown_label = AutowareLabel::UNKNOWN;
EXPECT_FALSE(filter.isTarget(unknown_label));
}

0 comments on commit d482924

Please sign in to comment.