From 58e84594c98e3ac11fa7e574537b3801f0ec3c4f Mon Sep 17 00:00:00 2001 From: Patrick Roche Date: Wed, 12 Feb 2020 19:12:02 -0500 Subject: [PATCH 1/6] testing try two --- Dockerfile | 4 +-- src/suas_planning/CMakeLists.txt | 32 +++++++++++-------- src/suas_planning/test/test_suas_planning.cpp | 13 ++++++++ 3 files changed, 33 insertions(+), 16 deletions(-) create mode 100644 src/suas_planning/test/test_suas_planning.cpp diff --git a/Dockerfile b/Dockerfile index fc2cbb5..69d97e3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -26,7 +26,7 @@ WORKDIR /catkin_ws/src COPY src . COPY entrypoint.sh . RUN touch ./suas_sim/CATKIN_IGNORE \ - && /bin/bash -c 'source /opt/ros/melodic/setup.sh && cd /catkin_ws && catkin_make' \ + && /bin/bash -c 'source /opt/ros/melodic/setup.sh && cd /catkin_ws && catkin_make && catkin_make run_tests' \ && chown -R $USERNAME:$USER_GID /catkin_ws \ && echo "source /catkin_ws/devel/setup.sh" > /home/${USERNAME}/.bashrc \ && chmod 0755 entrypoint.sh @@ -35,4 +35,4 @@ ENV DEBIAN_FRONTEND dialog USER $USERNAME ENTRYPOINT ["/catkin_ws/src/entrypoint.sh"] -CMD bash \ No newline at end of file +CMD bash diff --git a/src/suas_planning/CMakeLists.txt b/src/suas_planning/CMakeLists.txt index 7dec70c..bcff4e2 100644 --- a/src/suas_planning/CMakeLists.txt +++ b/src/suas_planning/CMakeLists.txt @@ -193,19 +193,6 @@ include_directories( # DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION} # ) -############# -## Testing ## -############# - -## Add gtest based cpp test target and link libraries -# catkin_add_gtest(${PROJECT_NAME}-test test/test_suas_planning.cpp) -# if(TARGET ${PROJECT_NAME}-test) -# target_link_libraries(${PROJECT_NAME}-test ${PROJECT_NAME}) -# endif() - -## Add folders to be run by python nosetests -# catkin_add_nosetests(test) - set(NODE_SOURCES src/Obstacle.cpp src/CircularObstacle.cpp @@ -215,4 +202,21 @@ set(NODE_SOURCES src/GlobalWaypointPlanner.cpp) add_executable(global_planner_node ${NODE_SOURCES}) -target_link_libraries(global_planner_node ${catkin_LIBRARIES}) \ No newline at end of file +target_link_libraries(global_planner_node ${catkin_LIBRARIES}) + +############# +## Testing ## +############# + +# statically link +add_library(global_planner_node_lib ${NODE_SOURCES}) + +## Add gtest based cpp test target and link libraries +catkin_add_gtest(${PROJECT_NAME}-test test/test_suas_planning.cpp) +if(TARGET ${PROJECT_NAME}-test) + target_link_libraries(${PROJECT_NAME}-test global_planner_node_lib) +endif() + +## Add folders to be run by python nosetests +# catkin_add_nosetests(test) + diff --git a/src/suas_planning/test/test_suas_planning.cpp b/src/suas_planning/test/test_suas_planning.cpp new file mode 100644 index 0000000..941fc42 --- /dev/null +++ b/src/suas_planning/test/test_suas_planning.cpp @@ -0,0 +1,13 @@ +#include "../include/PlanningPoints.hpp" +#include + +TEST(TestTest, testsWorking) +{ + EXPECT_TRUE(1); +} + +int main(int argc, char** argv) +{ + testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} From 9b73a6236d02ad521dc9af1adea2f26182d64fc8 Mon Sep 17 00:00:00 2001 From: Patrick Roche Date: Fri, 14 Feb 2020 10:05:44 -0500 Subject: [PATCH 2/6] more work on tests --- src/suas_planning/CMakeLists.txt | 1 + src/suas_planning/test/test_suas_planning.cpp | 86 ++++++++++++++++++- 2 files changed, 85 insertions(+), 2 deletions(-) diff --git a/src/suas_planning/CMakeLists.txt b/src/suas_planning/CMakeLists.txt index bcff4e2..29550e9 100644 --- a/src/suas_planning/CMakeLists.txt +++ b/src/suas_planning/CMakeLists.txt @@ -210,6 +210,7 @@ target_link_libraries(global_planner_node ${catkin_LIBRARIES}) # statically link add_library(global_planner_node_lib ${NODE_SOURCES}) +target_link_libraries(global_planner_node_lib ${catkin_LIBRARIES}) ## Add gtest based cpp test target and link libraries catkin_add_gtest(${PROJECT_NAME}-test test/test_suas_planning.cpp) diff --git a/src/suas_planning/test/test_suas_planning.cpp b/src/suas_planning/test/test_suas_planning.cpp index 941fc42..4f569a6 100644 --- a/src/suas_planning/test/test_suas_planning.cpp +++ b/src/suas_planning/test/test_suas_planning.cpp @@ -1,9 +1,91 @@ #include "../include/PlanningPoints.hpp" #include +#include +#include +#include +#include -TEST(TestTest, testsWorking) +#define MAP_DIM 100 + +class CircularObstacleTest : public testing::Test +{ +protected: + void SetUp() override + { + x = 8; + y = 8; + radius = 2; + map.resize(MAP_DIM * MAP_DIM); + test_obst = suas_planning::CircularObstacle((double)x, (double)y, (double)radius); + mmi = std::make_unique(map, MAP_DIM, MAP_DIM); + } + + void TearDown() override + { + + } + + std::vector map; + std::unique_ptr mmi; + suas_planning::CircularObstacle test_obst; + int x; + int y; + int radius; + const int8_t reference[64] = { + 0,0,0,1,1,0,0,0, + 0,0,1,0,0,1,0,0, + 0,1,0,0,0,0,1,0, + 1,0,0,0,0,0,0,1, + 1,0,0,0,0,0,0,1, + 0,1,0,0,0,0,1,0, + 0,0,1,0,0,1,0,0, + 0,0,0,1,1,0,0,0, + }; +}; + +TEST_F(CircularObstacleTest, TestCheckBounds) { - EXPECT_TRUE(1); + int x_min = x - radius; + int x_max = x + radius; + int y_min = y - radius; + int y_max = y + radius; + + EXPECT_EQ(x_min, test_obst.GetMinX()); + EXPECT_EQ(x_max, test_obst.GetMaxX()); + EXPECT_EQ(y_min, test_obst.GetMinY()); + EXPECT_EQ(y_max, test_obst.GetMaxY()); +} + +TEST_F(CircularObstacleTest, TestRasterize) +{ + test_obst.PlotObstacle(map, *mmi); + std::cout << "dump map" << std::endl; + for (int i = 0; i < MAP_DIM; i++) + { + for (int j = 0; j < MAP_DIM; j++) + { + std::cout << (int)map[i * MAP_DIM + j] << " "; + } + std::cout << std::endl; + } + int n = 0; + int hit = 0; + for (int i = 0; i < 8; i++) + { + for (int j = 0; j < 8; j++) + { + if ((int)map[i * 8 + j] == 1 && (int)(100 * reference[n]) == 1) + { + hit++; + } + n++; + std::cout << (int)map[i * 8 + j] << " "; + } + std::cout << std::endl; + } + + std::cout << "hit: " << hit << "/" << "16" << std::endl; + EXPECT_EQ(hit, 16); } int main(int argc, char** argv) From 56a5f15aa894bc48da977c5815b3380b7fee9de7 Mon Sep 17 00:00:00 2001 From: Patrick Roche Date: Thu, 20 Feb 2020 20:06:23 -0500 Subject: [PATCH 3/6] circle stuff --- build.sh | 3 ++ src/suas_planning/test/test_suas_planning.cpp | 47 +++++++++---------- 2 files changed, 25 insertions(+), 25 deletions(-) create mode 100755 build.sh diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..c5df5de --- /dev/null +++ b/build.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +docker build -t suas . diff --git a/src/suas_planning/test/test_suas_planning.cpp b/src/suas_planning/test/test_suas_planning.cpp index 4f569a6..e257c70 100644 --- a/src/suas_planning/test/test_suas_planning.cpp +++ b/src/suas_planning/test/test_suas_planning.cpp @@ -12,9 +12,9 @@ class CircularObstacleTest : public testing::Test protected: void SetUp() override { - x = 8; - y = 8; - radius = 2; + x = 32; + y = 32; + radius = 12; map.resize(MAP_DIM * MAP_DIM); test_obst = suas_planning::CircularObstacle((double)x, (double)y, (double)radius); mmi = std::make_unique(map, MAP_DIM, MAP_DIM); @@ -25,6 +25,7 @@ class CircularObstacleTest : public testing::Test } + // members std::vector map; std::unique_ptr mmi; suas_planning::CircularObstacle test_obst; @@ -43,6 +44,14 @@ class CircularObstacleTest : public testing::Test }; }; +TEST_F(CircularObstacleTest, TestGetLinearIndex) +{ + int expected_index = y * MAP_DIM + x; + EXPECT_EQ(expected_index, suas_planning::Obstacle::GetLinearIndex(y, x, MAP_DIM)); + EXPECT_EQ(MAP_DIM, suas_planning::Obstacle::GetLinearIndex(1, 0, MAP_DIM)); + EXPECT_EQ(0, suas_planning::Obstacle::GetLinearIndex(0, 0, MAP_DIM)); +} + TEST_F(CircularObstacleTest, TestCheckBounds) { int x_min = x - radius; @@ -58,34 +67,22 @@ TEST_F(CircularObstacleTest, TestCheckBounds) TEST_F(CircularObstacleTest, TestRasterize) { + test_obst.PlotObstacle(map, *mmi); - std::cout << "dump map" << std::endl; - for (int i = 0; i < MAP_DIM; i++) + int start_x = x - radius; + int start_y = y - radius; + int index = suas_planning::Obstacle::GetLinearIndex(y, x, MAP_DIM); + for (int i = 0; i < radius * 2 + 1; i++) { - for (int j = 0; j < MAP_DIM; j++) + for (int j = 0; j < radius * 2 + 1; j++) { - std::cout << (int)map[i * MAP_DIM + j] << " "; - } - std::cout << std::endl; - } - int n = 0; - int hit = 0; - for (int i = 0; i < 8; i++) - { - for (int j = 0; j < 8; j++) - { - if ((int)map[i * 8 + j] == 1 && (int)(100 * reference[n]) == 1) - { - hit++; - } - n++; - std::cout << (int)map[i * 8 + j] << " "; + int v = (int)map[suas_planning::Obstacle::GetLinearIndex(start_y + i, start_x + j, MAP_DIM)] / 100; + std::cout << v << " "; + + //EXPECT_EQ() } std::cout << std::endl; } - - std::cout << "hit: " << hit << "/" << "16" << std::endl; - EXPECT_EQ(hit, 16); } int main(int argc, char** argv) From c3e9f0fedf68bc18f71de6cd4612adf4e4a99738 Mon Sep 17 00:00:00 2001 From: Patrick Roche Date: Thu, 27 Feb 2020 19:18:15 -0500 Subject: [PATCH 4/6] latest --- src/suas_planning/test/test_suas_planning.cpp | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/src/suas_planning/test/test_suas_planning.cpp b/src/suas_planning/test/test_suas_planning.cpp index e257c70..5c35637 100644 --- a/src/suas_planning/test/test_suas_planning.cpp +++ b/src/suas_planning/test/test_suas_planning.cpp @@ -32,16 +32,6 @@ class CircularObstacleTest : public testing::Test int x; int y; int radius; - const int8_t reference[64] = { - 0,0,0,1,1,0,0,0, - 0,0,1,0,0,1,0,0, - 0,1,0,0,0,0,1,0, - 1,0,0,0,0,0,0,1, - 1,0,0,0,0,0,0,1, - 0,1,0,0,0,0,1,0, - 0,0,1,0,0,1,0,0, - 0,0,0,1,1,0,0,0, - }; }; TEST_F(CircularObstacleTest, TestGetLinearIndex) @@ -67,6 +57,7 @@ TEST_F(CircularObstacleTest, TestCheckBounds) TEST_F(CircularObstacleTest, TestRasterize) { + /* no equality checking, but circles can be visually confirmed */ test_obst.PlotObstacle(map, *mmi); int start_x = x - radius; @@ -78,8 +69,6 @@ TEST_F(CircularObstacleTest, TestRasterize) { int v = (int)map[suas_planning::Obstacle::GetLinearIndex(start_y + i, start_x + j, MAP_DIM)] / 100; std::cout << v << " "; - - //EXPECT_EQ() } std::cout << std::endl; } From 2724745a0f622ef6be64538f04944949509bd49a Mon Sep 17 00:00:00 2001 From: Patrick Roche Date: Thu, 27 Feb 2020 20:19:29 -0500 Subject: [PATCH 5/6] testrasterize works --- src/suas_planning/test/test_suas_planning.cpp | 38 ++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/src/suas_planning/test/test_suas_planning.cpp b/src/suas_planning/test/test_suas_planning.cpp index 5c35637..676fc97 100644 --- a/src/suas_planning/test/test_suas_planning.cpp +++ b/src/suas_planning/test/test_suas_planning.cpp @@ -32,6 +32,33 @@ class CircularObstacleTest : public testing::Test int x; int y; int radius; + int reference[25*25] = { + 0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0, + 0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0, + 0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0, + 0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0, + 0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0, + 0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0, + 0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0, + 0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0, + 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, + 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, + 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, + 1,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,1, + 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, + 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, + 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, + 0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0, + 0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0, + 0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0, + 0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0, + 0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0, + 0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0, + 0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0, + 0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0 + }; }; TEST_F(CircularObstacleTest, TestGetLinearIndex) @@ -55,6 +82,11 @@ TEST_F(CircularObstacleTest, TestCheckBounds) EXPECT_EQ(y_max, test_obst.GetMaxY()); } +TEST_F(CircularObstacleTest, TestPosition) +{ + +} + TEST_F(CircularObstacleTest, TestRasterize) { /* no equality checking, but circles can be visually confirmed */ @@ -63,12 +95,16 @@ TEST_F(CircularObstacleTest, TestRasterize) int start_x = x - radius; int start_y = y - radius; int index = suas_planning::Obstacle::GetLinearIndex(y, x, MAP_DIM); + + int ri = 0; for (int i = 0; i < radius * 2 + 1; i++) { for (int j = 0; j < radius * 2 + 1; j++) { int v = (int)map[suas_planning::Obstacle::GetLinearIndex(start_y + i, start_x + j, MAP_DIM)] / 100; - std::cout << v << " "; + EXPECT_EQ(v, reference[ri]); + //std::cout << v << " "; + ri++; } std::cout << std::endl; } From 150c45f77478b2c2213742274c1ec5a7477889f0 Mon Sep 17 00:00:00 2001 From: Patrick Roche Date: Thu, 5 Mar 2020 21:09:26 -0500 Subject: [PATCH 6/6] add latest changes from machine --- src/suas_planning/test/test_suas_planning.cpp | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/suas_planning/test/test_suas_planning.cpp b/src/suas_planning/test/test_suas_planning.cpp index 676fc97..a65c569 100644 --- a/src/suas_planning/test/test_suas_planning.cpp +++ b/src/suas_planning/test/test_suas_planning.cpp @@ -63,10 +63,10 @@ class CircularObstacleTest : public testing::Test TEST_F(CircularObstacleTest, TestGetLinearIndex) { - int expected_index = y * MAP_DIM + x; - EXPECT_EQ(expected_index, suas_planning::Obstacle::GetLinearIndex(y, x, MAP_DIM)); - EXPECT_EQ(MAP_DIM, suas_planning::Obstacle::GetLinearIndex(1, 0, MAP_DIM)); - EXPECT_EQ(0, suas_planning::Obstacle::GetLinearIndex(0, 0, MAP_DIM)); + int asserted_index = y * MAP_DIM + x; + ASSERT_EQ(asserted_index, suas_planning::Obstacle::GetLinearIndex(y, x, MAP_DIM)); + ASSERT_EQ(MAP_DIM, suas_planning::Obstacle::GetLinearIndex(1, 0, MAP_DIM)); + ASSERT_EQ(0, suas_planning::Obstacle::GetLinearIndex(0, 0, MAP_DIM)); } TEST_F(CircularObstacleTest, TestCheckBounds) @@ -76,21 +76,21 @@ TEST_F(CircularObstacleTest, TestCheckBounds) int y_min = y - radius; int y_max = y + radius; - EXPECT_EQ(x_min, test_obst.GetMinX()); - EXPECT_EQ(x_max, test_obst.GetMaxX()); - EXPECT_EQ(y_min, test_obst.GetMinY()); - EXPECT_EQ(y_max, test_obst.GetMaxY()); + ASSERT_EQ(x_min, test_obst.GetMinX()); + ASSERT_EQ(x_max, test_obst.GetMaxX()); + ASSERT_EQ(y_min, test_obst.GetMinY()); + ASSERT_EQ(y_max, test_obst.GetMaxY()); } TEST_F(CircularObstacleTest, TestPosition) { - + test_obst.PlotObstacle(map, *mmi); + int index = suas_planning::Obstacle::GetLinearIndex(y, x, MAP_DIM); + ASSERT_EQ(map[index], 100); } TEST_F(CircularObstacleTest, TestRasterize) { - /* no equality checking, but circles can be visually confirmed */ - test_obst.PlotObstacle(map, *mmi); int start_x = x - radius; int start_y = y - radius; @@ -102,11 +102,11 @@ TEST_F(CircularObstacleTest, TestRasterize) for (int j = 0; j < radius * 2 + 1; j++) { int v = (int)map[suas_planning::Obstacle::GetLinearIndex(start_y + i, start_x + j, MAP_DIM)] / 100; - EXPECT_EQ(v, reference[ri]); + ASSERT_EQ(v, reference[ri]); //std::cout << v << " "; ri++; } - std::cout << std::endl; + //std::cout << std::endl; } }