Skip to content

Commit

Permalink
Added method to convert classification to string and added unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
paulbourelly999 committed Jun 19, 2024
1 parent 3eb7331 commit 10e1643
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
19 changes: 16 additions & 3 deletions src/v2i-hub/MUSTSensorDriverPlugin/src/MUSTSensorDetection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ namespace MUSTSensorDriverPlugin {
detectedObject.velocity = headingSpeedToVelocity(detection.heading, detection.speed);
return detectedObject;
}
const DetectionClassification fromStringToDetectionClassification(const std::string &str) noexcept {
DetectionClassification fromStringToDetectionClassification(const std::string &str) noexcept {
try {

return stringToDetectionClassificationMap.at(str);
Expand All @@ -49,7 +49,20 @@ namespace MUSTSensorDriverPlugin {
}
}

const DetectionSize fromStringToDetectionSize(const std::string &str) noexcept {
std::string detectionClassificationToString(const DetectionClassification &classification) {
for (auto const &[name, cl] : stringToDetectionClassificationMap){
if (classification == cl) {
std::string rtn = name;
std::transform(rtn.begin(), rtn.end(), rtn.begin(), ::toupper);
return rtn;
}
}
throw std::runtime_error("DetectionClassification type is not registered in stringToDetectionClassificationMap!");
}



DetectionSize fromStringToDetectionSize(const std::string &str) noexcept {
try {

return stringToDetectionSizeMap.at(str);
Expand All @@ -66,4 +79,4 @@ namespace MUSTSensorDriverPlugin {
velocity.Z = 0;
return velocity;
};
}
}
8 changes: 6 additions & 2 deletions src/v2i-hub/MUSTSensorDriverPlugin/src/MUSTSensorDetection.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include <SensorDetectedObject.h>
#include <PluginLog.h>
#include <Vector3d.h>
#include <algorithm>


namespace MUSTSensorDriverPlugin {

Expand Down Expand Up @@ -35,9 +37,11 @@ namespace MUSTSensorDriverPlugin {
{"van", DetectionClassification::VAN}
};

const DetectionSize fromStringToDetectionSize(const std::string &str) noexcept;
DetectionSize fromStringToDetectionSize(const std::string &str) noexcept;

DetectionClassification fromStringToDetectionClassification(const std::string &str) noexcept;

const DetectionClassification fromStringToDetectionClassification(const std::string &str) noexcept;
std::string detectionClassificationToString(const DetectionClassification &classifcation);

struct MUSTSensorDetection {
DetectionClassification cl = DetectionClassification::NA;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,12 @@ TEST(TestMUSTSensorDetection, mustDectionToSensorDetectedObject ) {
EXPECT_DOUBLE_EQ(detection.position_y, sensorDetectedObject.position.Y);
EXPECT_NEAR(4.33, sensorDetectedObject.velocity.Y, 0.001);
EXPECT_NEAR(2.5, sensorDetectedObject.velocity.X, 0.001);
}

TEST(TestMUSTSensorDetection, detectionClassificationToString ) {
EXPECT_STRCASEEQ("SEDAN", detectionClassificationToString(DetectionClassification::SEDAN).c_str());
EXPECT_STRCASEEQ("VAN", detectionClassificationToString(DetectionClassification::VAN).c_str());
EXPECT_STRCASEEQ("TRUCK", detectionClassificationToString(DetectionClassification::TRUCK).c_str());
EXPECT_THROW(detectionClassificationToString(DetectionClassification::NA).c_str(), std::runtime_error);

}

0 comments on commit 10e1643

Please sign in to comment.