Skip to content

Commit

Permalink
refactor(perception_utils): add test in object_classification (autowa…
Browse files Browse the repository at this point in the history
…refoundation#2083)

* add test for isVehicle

Signed-off-by: Yoshi Ri <yoshi.ri@tier4.jp>

* add isCarLikeVehicle test

Signed-off-by: Yoshi Ri <yoshi.ri@tier4.jp>

* add isLargeVehicle test

Signed-off-by: Yoshi Ri <yoshi.ri@tier4.jp>

* fix namespace range

Signed-off-by: Yoshi Ri <yoshi.ri@tier4.jp>

* ci(pre-commit): autofix

* remove unnecessary forloop

Signed-off-by: Yoshi Ri <yoshi.ri@tier4.jp>

* fix cpplint message

Signed-off-by: Yoshi Ri <yoshi.ri@tier4.jp>

* added edge case to iscarlikevehicle

Signed-off-by: Yoshi Ri <yoshi.ri@tier4.jp>

* run precommit

Signed-off-by: Yoshi Ri <yoshi.ri@tier4.jp>

* add possibe edge cases with comment

Signed-off-by: Yoshi Ri <yoshi.ri@tier4.jp>

Signed-off-by: Yoshi Ri <yoshi.ri@tier4.jp>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Signed-off-by: yoshiri <yoshiyoshidetteiu@gmail.com>
  • Loading branch information
YoshiRi and pre-commit-ci[bot] committed Jan 11, 2023
1 parent def28d3 commit 92c6f0c
Showing 1 changed file with 131 additions and 0 deletions.
131 changes: 131 additions & 0 deletions common/perception_utils/test/src/test_object_classification.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<autoware_auto_perception_msgs::msg::ObjectClassification> 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<autoware_auto_perception_msgs::msg::ObjectClassification> 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<autoware_auto_perception_msgs::msg::ObjectClassification> 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<autoware_auto_perception_msgs::msg::ObjectClassification> 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<autoware_auto_perception_msgs::msg::ObjectClassification> 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<autoware_auto_perception_msgs::msg::ObjectClassification> 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<autoware_auto_perception_msgs::msg::ObjectClassification> 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;
Expand Down

0 comments on commit 92c6f0c

Please sign in to comment.