Formula Student Autonomous Systems
The code for the main driverless system
Loading...
Searching...
No Matches
grid_test.cpp
Go to the documentation of this file.
1
2
#include <gtest/gtest.h>
3
4
#include <
clustering/grid_clustering.hpp
>
5
#include <memory>
6
#include <sensor_msgs/msg/point_cloud2.hpp>
7
#include <
test_utils/pointcloud2_helper.hpp
>
8
13
class
GridClusteringTest
:
public
::testing::Test {
14
protected
:
15
void
SetUp
()
override
{
16
pts
= {{1.0, 2.0, 0.0, 0.1, 39}, {4.0, 5.0, 0.0, 0.2, 39}, {7.0, 8.0, 0.0, 0.3, 39},
17
{4.0, 3.5, 0.0, 0.4, 39}, {0.0, 7.0, 0.0, 0.5, 39}, {4.0, 4.0, 0.0, 0.6, 39},
18
{5.0, 4.5, 0.0, 0.7, 39}, {40.0, 40.0, 0.0, 0.8, 39}};
19
}
20
std::vector<std::array<float, 5>>
pts
;
21
};
22
27
TEST_F
(
GridClusteringTest
, TestZeroGrid) {
28
auto
input_cloud =
test_utils::make_lidar_pointcloud2
(pts);
29
auto
clustering = std::make_unique<GridClustering>(0.01, 0.01, 0, 0, 360);
30
std::vector<Cluster> clusters;
31
clustering->clustering(input_cloud, &clusters);
32
ASSERT_EQ(clusters.size(), 8);
33
}
34
39
TEST_F
(
GridClusteringTest
, TestLargeGrid) {
40
auto
input_cloud =
test_utils::make_lidar_pointcloud2
(pts);
41
auto
clustering = std::make_unique<GridClustering>(90, 100, 0, 0, 360);
42
std::vector<Cluster> clusters;
43
clustering->clustering(input_cloud, &clusters);
44
ASSERT_EQ(clusters.size(), 1);
45
}
46
51
TEST_F
(
GridClusteringTest
, TestMinClusterSize) {
52
auto
input_cloud =
test_utils::make_lidar_pointcloud2
(pts);
53
auto
clustering = std::make_unique<GridClustering>(90, 100, 0, 0, 360);
54
std::vector<Cluster> clusters;
55
clustering->clustering(input_cloud, &clusters);
56
ASSERT_EQ(clusters.size(), 1);
57
}
58
63
TEST_F
(
GridClusteringTest
, TestVeryLargeGrid) {
64
auto
input_cloud =
test_utils::make_lidar_pointcloud2
(pts);
65
auto
clustering = std::make_unique<GridClustering>(1000, 1000, 0, 0, 360);
66
std::vector<Cluster> clusters;
67
clustering->clustering(input_cloud, &clusters);
68
ASSERT_EQ(clusters.size(), 1);
69
}
70
75
TEST_F
(
GridClusteringTest
, TestSmallGrid) {
76
auto
input_cloud =
test_utils::make_lidar_pointcloud2
(pts);
77
auto
clustering = std::make_unique<GridClustering>(1, 1, 0, 0, 360);
78
std::vector<Cluster> clusters;
79
clustering->clustering(input_cloud, &clusters);
80
ASSERT_GE(clusters.size(), 5);
81
}
82
87
TEST_F
(
GridClusteringTest
, TestMinClusterSize2) {
88
auto
input_cloud =
test_utils::make_lidar_pointcloud2
(pts);
89
auto
clustering = std::make_unique<GridClustering>(1, 1, 0, 0, 360);
90
std::vector<Cluster> clusters;
91
clustering->clustering(input_cloud, &clusters);
92
ASSERT_GE(clusters.size(), 1);
93
}
94
99
TEST_F
(
GridClusteringTest
, TestTinyGrid) {
100
auto
input_cloud =
test_utils::make_lidar_pointcloud2
(pts);
101
auto
clustering = std::make_unique<GridClustering>(0.01, 0.01, 0, 0, 360);
102
std::vector<Cluster> clusters;
103
clustering->clustering(input_cloud, &clusters);
104
ASSERT_EQ(clusters.size(), 8);
105
}
106
111
TEST_F
(
GridClusteringTest
, TestAggregate2Points) {
112
auto
input_cloud =
test_utils::make_lidar_pointcloud2
(pts);
113
auto
clustering = std::make_unique<GridClustering>(0.6, 0.6, 0, 0, 360);
114
std::vector<Cluster> clusters;
115
clustering->clustering(input_cloud, &clusters);
116
ASSERT_LE(clusters.size(), 8);
117
}
118
123
TEST_F
(
GridClusteringTest
, TestMorePointsThanThreshold) {
124
auto
input_cloud =
test_utils::make_lidar_pointcloud2
(pts);
125
auto
clustering = std::make_unique<GridClustering>(1000, 1000, 0, 0, 360);
126
std::vector<Cluster> clusters;
127
clustering->clustering(input_cloud, &clusters);
128
ASSERT_GE(clusters.size(), 1);
129
}
130
135
TEST_F
(
GridClusteringTest
, TestMinClusterWithSmallGrid) {
136
auto
input_cloud =
test_utils::make_lidar_pointcloud2
(pts);
137
auto
clustering = std::make_unique<GridClustering>(0.01, 0.01, 0, 0, 360);
138
std::vector<Cluster> clusters;
139
clustering->clustering(input_cloud, &clusters);
140
ASSERT_EQ(clusters.size(), 8);
141
}
GridClusteringTest
Test fixture for the GridClustering class.
Definition
grid_test.cpp:13
GridClusteringTest::SetUp
void SetUp() override
Definition
grid_test.cpp:15
GridClusteringTest::pts
std::vector< std::array< float, 5 > > pts
Definition
grid_test.cpp:20
grid_clustering.hpp
TEST_F
TEST_F(GridClusteringTest, TestZeroGrid)
Minimum values for cluster size and distance threshold.
Definition
grid_test.cpp:27
test_utils::make_lidar_pointcloud2
sensor_msgs::msg::PointCloud2::SharedPtr make_lidar_pointcloud2(const std::vector< std::array< float, 5 > > &pts)
Definition
pointcloud2_helper.hpp:6
pointcloud2_helper.hpp
src
perception
test
clustering
grid_test.cpp
Generated by
1.9.8