From 57942a50a1fb8debb6a9399af50addb3909b7f57 Mon Sep 17 00:00:00 2001 From: Yoshi Ri Date: Wed, 9 Nov 2022 15:06:34 +0900 Subject: [PATCH] refactor(perception_utils): add test in object_classification (#2083) * add test for isVehicle Signed-off-by: Yoshi Ri * add isCarLikeVehicle test Signed-off-by: Yoshi Ri * add isLargeVehicle test Signed-off-by: Yoshi Ri * fix namespace range Signed-off-by: Yoshi Ri * ci(pre-commit): autofix * remove unnecessary forloop Signed-off-by: Yoshi Ri * fix cpplint message Signed-off-by: Yoshi Ri * added edge case to iscarlikevehicle Signed-off-by: Yoshi Ri * run precommit Signed-off-by: Yoshi Ri * add possibe edge cases with comment Signed-off-by: Yoshi Ri Signed-off-by: Yoshi Ri Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Signed-off-by: Kotaro Yoshimoto --- .../test/src/test_object_classification.cpp | 131 ++++++++++++++++++ 1 file changed, 131 insertions(+) diff --git a/common/perception_utils/test/src/test_object_classification.cpp b/common/perception_utils/test/src/test_object_classification.cpp index be389634ef5a2..9c1fe50294025 100644 --- a/common/perception_utils/test/src/test_object_classification.cpp +++ b/common/perception_utils/test/src/test_object_classification.cpp @@ -64,6 +64,137 @@ TEST(object_classification, test_getHighestProbLabel) } } +// Test isVehicle +TEST(object_classification, test_isVehicle) +{ + using autoware_auto_perception_msgs::msg::ObjectClassification; + using perception_utils::isVehicle; + + { // True Case with uint8_t + EXPECT_TRUE(isVehicle(ObjectClassification::BICYCLE)); + EXPECT_TRUE(isVehicle(ObjectClassification::BUS)); + EXPECT_TRUE(isVehicle(ObjectClassification::CAR)); + EXPECT_TRUE(isVehicle(ObjectClassification::MOTORCYCLE)); + EXPECT_TRUE(isVehicle(ObjectClassification::TRAILER)); + EXPECT_TRUE(isVehicle(ObjectClassification::TRUCK)); + } + + // False Case with uint8_t + { + EXPECT_FALSE(isVehicle(ObjectClassification::UNKNOWN)); + EXPECT_FALSE(isVehicle(ObjectClassification::PEDESTRIAN)); + } + + // True Case with object_classifications + { // normal case + std::vector classification; + classification.push_back(createObjectClassification(ObjectClassification::CAR, 0.5)); + classification.push_back(createObjectClassification(ObjectClassification::TRUCK, 0.8)); + classification.push_back(createObjectClassification(ObjectClassification::BUS, 0.7)); + EXPECT_TRUE(isVehicle(classification)); + } + + // False Case with object_classifications + { // false case + std::vector classification; + classification.push_back(createObjectClassification(ObjectClassification::PEDESTRIAN, 0.8)); + classification.push_back(createObjectClassification(ObjectClassification::BICYCLE, 0.7)); + EXPECT_FALSE(isVehicle(classification)); + } +} // TEST isVehicle + +// TEST isCarLikeVehicle +TEST(object_classification, test_isCarLikeVehicle) +{ + using autoware_auto_perception_msgs::msg::ObjectClassification; + using perception_utils::isCarLikeVehicle; + + { // True Case with uint8_t + EXPECT_TRUE(isCarLikeVehicle(ObjectClassification::BUS)); + EXPECT_TRUE(isCarLikeVehicle(ObjectClassification::CAR)); + EXPECT_TRUE(isCarLikeVehicle(ObjectClassification::TRAILER)); + EXPECT_TRUE(isCarLikeVehicle(ObjectClassification::TRUCK)); + } + + // False Case with uint8_t + { + EXPECT_FALSE(isCarLikeVehicle(ObjectClassification::UNKNOWN)); + EXPECT_FALSE(isCarLikeVehicle(ObjectClassification::BICYCLE)); + EXPECT_FALSE(isCarLikeVehicle(ObjectClassification::PEDESTRIAN)); + EXPECT_FALSE(isCarLikeVehicle(ObjectClassification::MOTORCYCLE)); + } + + // True Case with object_classifications + { // normal case + std::vector classification; + classification.push_back(createObjectClassification(ObjectClassification::CAR, 0.5)); + classification.push_back(createObjectClassification(ObjectClassification::TRUCK, 0.8)); + classification.push_back(createObjectClassification(ObjectClassification::BICYCLE, 0.7)); + EXPECT_TRUE(isCarLikeVehicle(classification)); + } + + // False Case with object_classifications + { // false case + std::vector classification; + classification.push_back(createObjectClassification(ObjectClassification::MOTORCYCLE, 0.8)); + classification.push_back(createObjectClassification(ObjectClassification::BICYCLE, 0.8)); + EXPECT_FALSE(isCarLikeVehicle(classification)); + } + + // Edge case + // When classification has more multiple labels with same maximum probability + // getHighestProbLabel() returns only first highest-scored label. + // so, in edge case it returns a label earlier added. + { // When car and non-car label has same probability + std::vector classification; + classification.push_back(createObjectClassification(ObjectClassification::MOTORCYCLE, 0.8)); + classification.push_back(createObjectClassification(ObjectClassification::CAR, 0.8)); + EXPECT_FALSE( + isCarLikeVehicle(classification)); // evaluated with earlier appended "MOTORCYCLE" label + } +} // TEST isCarLikeVehicle + +// TEST isLargeVehicle +TEST(object_classification, test_isLargeVehicle) +{ + using autoware_auto_perception_msgs::msg::ObjectClassification; + using perception_utils::isLargeVehicle; + + { // True Case with uint8_t + EXPECT_TRUE(isLargeVehicle(ObjectClassification::BUS)); + EXPECT_TRUE(isLargeVehicle(ObjectClassification::TRAILER)); + EXPECT_TRUE(isLargeVehicle(ObjectClassification::TRUCK)); + } + + // False Case with uint8_t + { + EXPECT_FALSE(isLargeVehicle(ObjectClassification::UNKNOWN)); + EXPECT_FALSE(isLargeVehicle(ObjectClassification::BICYCLE)); + EXPECT_FALSE(isLargeVehicle(ObjectClassification::PEDESTRIAN)); + EXPECT_FALSE(isLargeVehicle(ObjectClassification::MOTORCYCLE)); + EXPECT_FALSE(isLargeVehicle(ObjectClassification::CAR)); + } + + { // false case + std::vector classification; + classification.push_back(createObjectClassification(ObjectClassification::MOTORCYCLE, 0.8)); + classification.push_back(createObjectClassification(ObjectClassification::BICYCLE, 0.8)); + classification.push_back(createObjectClassification(ObjectClassification::CAR, 0.8)); + EXPECT_FALSE(isLargeVehicle(classification)); + } + + // Edge case + // When classification has more multiple labels with same maximum probability + // getHighestProbLabel() returns only first highest-scored label. + // so, in edge case it returns a label earlier added. + { // When large-vehicle and non-large-vehicle label has same probability + std::vector classification; + classification.push_back(createObjectClassification(ObjectClassification::BUS, 0.8)); + classification.push_back(createObjectClassification(ObjectClassification::CAR, 0.8)); + EXPECT_TRUE(isLargeVehicle(classification)); // evaluated with earlier appended "BUS" label + } +} // TEST isLargeVehicle + TEST(object_classification, test_getHighestProbClassification) { using autoware_auto_perception_msgs::msg::ObjectClassification;