Formula Student Autonomous Systems
The code for the main driverless system
Loading...
Searching...
No Matches
test.cpp
Go to the documentation of this file.
1#include <chrono>
2#include <fstream>
3#include <set>
4
5#include "gtest/gtest.h"
6#include "utils/mocks.hpp"
7#include "rclcpp/rclcpp.hpp"
8
9// Test case for valid input
10TEST(GTruthFromFileTest, ValidInput) {
11 std::string mockFileContent("header asdasd\n-1.0,0,3.1416\n4.0,5.0,6.0\n7.5,-8.5,9.8");
12 std::istringstream mockFileStream(mockFileContent);
13
14 custom_interfaces::msg::PathPointArray result = planning_gtruth_fromfile(mockFileStream);
15
16 // Uncomment the following lines to see each value in case of bugs
17 // std::cout << result.pathpoint_array[0].x << " , " << result.pathpoint_array[0].y
18 // << " , " << result.pathpoint_array[0].v << std::endl;
19 // std::cout << result.pathpoint_array[1].x << " , " << result.pathpoint_array[1].y
20 // << " , " << result.pathpoint_array[1].v << std::endl;
21 // std::cout << result.pathpoint_array[2].x << " , " << result.pathpoint_array[2].y
22 // << " , " << result.pathpoint_array[2].v << std::endl;
23
24 ASSERT_EQ(result.pathpoint_array.size(), 3); // Three points should be added
25 EXPECT_FLOAT_EQ(result.pathpoint_array[0].x, -1.0);
26 EXPECT_FLOAT_EQ(result.pathpoint_array[0].y, 0.0);
27 EXPECT_FLOAT_EQ(result.pathpoint_array[0].v, 3.1416);
28 EXPECT_FLOAT_EQ(result.pathpoint_array[1].x, 4.0);
29 EXPECT_FLOAT_EQ(result.pathpoint_array[1].y, 5.0);
30 EXPECT_FLOAT_EQ(result.pathpoint_array[1].v, 6.0);
31 EXPECT_FLOAT_EQ(result.pathpoint_array[2].x, 7.5);
32 EXPECT_FLOAT_EQ(result.pathpoint_array[2].y, -8.5);
33 EXPECT_FLOAT_EQ(result.pathpoint_array[2].v, 9.8);
34}
35
36// Test case for empty input
37TEST(GTruthFromFileTest, EmptyInput) {
38 std::string mockFileContent("");
39 std::istringstream mockFileStream(mockFileContent);
40
41 custom_interfaces::msg::PathPointArray result = planning_gtruth_fromfile(mockFileStream);
42
43 ASSERT_EQ(result.pathpoint_array.size(), 0); // No points should be added
44}
45
46// Test case for invalid input
47TEST(GTruthFromFileTest, InvalidInput) {
48 std::string mockFileContent("header\n-1.0,0,3.1416\n4.0,5.0,6.0\n7.5,-8.5,9.8\ninvalid");
49 std::istringstream mockFileStream(mockFileContent);
50
51 custom_interfaces::msg::PathPointArray result = planning_gtruth_fromfile(mockFileStream);
52
53 ASSERT_EQ(result.pathpoint_array.size(),
54 3); // Three points should be added; the other line should be ignored
55}
TEST(invictasim, example_test)
Example test.
Definition test.cpp:6
custom_interfaces::msg::PathPointArray planning_gtruth_fromfile(std::istream &in)
read planning ground truth information from stream and place it in an array of PathPoint objects
Definition mocks.cpp:11