Skip to content

Commit

Permalink
Updates to unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
paulbourelly999 committed Jun 18, 2024
1 parent 1e80c46 commit 31a3b0f
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 20 deletions.
11 changes: 10 additions & 1 deletion src/tmx/Messages/include/simulation/SensorDetectedObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <tmx/messages/message.hpp>
#include <MessageTypes.h>
#include <Point.h>

namespace tmx
{
Expand All @@ -26,8 +27,16 @@ namespace tmx

// // Message sub type for routing this message through TMX core
static constexpr const char *MessageSubType = MSGSUBTYPE_SENSOR_DETECTED_OBJECT_STRING;
};

std::string type;
double confidence;
std::string sensorId;
std::string projString;
int objectId;
tmx::utils::Point position;
tmx::utils::Point velocity;
long timestamp;
};
}
}

Expand Down
1 change: 1 addition & 0 deletions src/v2i-hub/MUSTSensorDriverPlugin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ TARGET_LINK_LIBRARIES(${PROJECT_NAME} PUBLIC tmxutils )
#############
enable_testing()
add_library(${PROJECT_NAME}_lib src/MUSTSensorDetection.cpp)
TARGET_LINK_LIBRARIES(${PROJECT_NAME}_lib PUBLIC tmxutils )

set(BINARY ${PROJECT_NAME}_test)
file(GLOB_RECURSE TEST_SOURCES LIST_DIRECTORIES false test/*.h test/*.cpp)
Expand Down
23 changes: 12 additions & 11 deletions src/v2i-hub/MUSTSensorDriverPlugin/src/MUSTSensorDetection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,20 @@ namespace MUSTSensorDriverPlugin {
std::getline(ss, substr, ',');
csv_values.push_back(substr);
}
if (csv.size() != 9 ){
throw std::runtime_error("Failed to parse csv MUST Detection data");
if (csv_values.size() != 9 ){
FILE_LOG(tmx::utils::logWARNING) << "CSV data " << csv <<" is size " << csv_values.size() << std::endl;
throw std::runtime_error("Failed to parse CSV MUST Detection data");
}
// Read out CSV information
detection.cl = fromStringToDetectionClassification(&csv.at(0));
detection.position_x = std::stod(&csv.at(1));
detection.position_y = std::stod(&csv.at(2));
detection.heading = std::stod(&csv.at(3));
detection.speed = std::stod(&csv.at(4));
detection.size = fromStringToDetectionSize(&csv.at(5));
detection.confidence = std::stod(&csv.at(6));
detection.trackID = std::stoi(&csv.at(7));
detection.timestamp = std::stoll(&csv.at(8));
detection.cl = fromStringToDetectionClassification(csv_values.at(0));
detection.position_x = std::stod(csv_values.at(1));
detection.position_y = std::stod(csv_values.at(2));
detection.heading = std::stod(csv_values.at(3));
detection.speed = std::stod(csv_values.at(4));
detection.size = fromStringToDetectionSize(csv_values.at(5));
detection.confidence = std::stod(csv_values.at(6));
detection.trackID = std::stoi(csv_values.at(7));
detection.timestamp = std::stoll(csv_values.at(8));
return detection;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <unordered_map>
#include <stdexcept> // std::out_of_range
#include <simulation/SensorDetectedObject.h>
#include <PluginLog.h>

namespace MUSTSensorDriverPlugin {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,32 @@ using namespace MUSTSensorDriverPlugin;

TEST(TestMUSTSensorDetection, fromStringToDetectionSize)
{
ASSERT_EQ(DetectionSize::SMALL, fromStringToDetectionSize("small"));
ASSERT_EQ(DetectionSize::MEDIUM, fromStringToDetectionSize("medium"));
ASSERT_EQ(DetectionSize::LARGE, fromStringToDetectionSize("large"));
ASSERT_EQ(DetectionSize::NA, fromStringToDetectionSize("not_a_size"));
EXPECT_EQ(DetectionSize::SMALL, fromStringToDetectionSize("small"));
EXPECT_EQ(DetectionSize::MEDIUM, fromStringToDetectionSize("medium"));
EXPECT_EQ(DetectionSize::LARGE, fromStringToDetectionSize("large"));
EXPECT_EQ(DetectionSize::NA, fromStringToDetectionSize("not_a_size"));

}

TEST(TestMUSTSensorDetection, fromStringToDetectionClassification)
{
ASSERT_EQ(DetectionClassification::SEDAN, fromStringToDetectionClassification("sedan"));
ASSERT_EQ(DetectionClassification::VAN, fromStringToDetectionClassification("van"));
ASSERT_EQ(DetectionClassification::TRUCK, fromStringToDetectionClassification("truck"));
ASSERT_EQ(DetectionClassification::NA, fromStringToDetectionClassification("not_a_classification"));
EXPECT_EQ(DetectionClassification::SEDAN, fromStringToDetectionClassification("sedan"));
EXPECT_EQ(DetectionClassification::VAN, fromStringToDetectionClassification("van"));
EXPECT_EQ(DetectionClassification::TRUCK, fromStringToDetectionClassification("truck"));
EXPECT_EQ(DetectionClassification::NA, fromStringToDetectionClassification("not_a_classification"));

}

TEST(TestMUSTSensorDetection, csvToDectection ){
std::string valid_csv_data = "truck,13.3,22.4,30.5,35.8,large,95.1,1,1714374738";
auto detection = csvToDectection(valid_csv_data);
EXPECT_EQ(detection.cl, DetectionClassification::TRUCK);
EXPECT_DOUBLE_EQ(detection.position_x, 13.3);
EXPECT_DOUBLE_EQ(detection.position_y, 22.4);
EXPECT_DOUBLE_EQ(detection.heading, 30.5);
EXPECT_DOUBLE_EQ(detection.speed, 35.8);
EXPECT_EQ(detection.size, DetectionSize::LARGE);
EXPECT_DOUBLE_EQ(detection.confidence, 95.1);
EXPECT_EQ(detection.trackID, 1);
EXPECT_EQ(detection.timestamp, 1714374738);
}

0 comments on commit 31a3b0f

Please sign in to comment.