diff --git a/turtlelib/CMakeLists.txt b/turtlelib/CMakeLists.txt index f862230..cff593a 100644 --- a/turtlelib/CMakeLists.txt +++ b/turtlelib/CMakeLists.txt @@ -22,8 +22,9 @@ if(BUILD_TESTING) find_package(Catch2 3 REQUIRED) # A test is just an executable that is linked against the unit testing library - add_executable(turtlelib_test tests/test_geometry2d.cpp tests/test_se2d.cpp tests/test_svg.cpp tests/test_diff_drive.cpp) - target_link_libraries(turtlelib_test Catch2::Catch2WithMain turtlelib) + add_executable(turtlelib_test tests/test_geometry2d.cpp tests/test_se2d.cpp tests/test_svg.cpp tests/test_diff_drive.cpp tests/circle_tests.cpp) + target_link_libraries(turtlelib_test Catch2::Catch2WithMain turtlelib ${ARMADILLO_LIBRARIES}) + include_directories(turtlelib_test ${ARMADILLO_INCLUDE_DIRS}) # register the test with CTest, telling it what executable to run add_test(NAME turtlelib_test COMMAND turtlelib_test) diff --git a/turtlelib/tests/circle_tests.cpp b/turtlelib/tests/circle_tests.cpp new file mode 100644 index 0000000..d420c8f --- /dev/null +++ b/turtlelib/tests/circle_tests.cpp @@ -0,0 +1,36 @@ +#include +#include +#include "turtlelib/landmark_detection.hpp" +#include + +namespace turtlelib { + + TEST_CASE("Circle fitting - test 1", "[landmark]") { + arma::mat points = {{1,7},{2,6},{5,8},{7,7},{9,5},{3,7}}; + + double c_x; + double c_y; + double r; + std::tie(c_x, c_y, r) = fitCircle(points); + + + REQUIRE_THAT(c_x, Catch::Matchers::WithinAbs(4.615482, 1.0E-4)); + REQUIRE_THAT(c_y, Catch::Matchers::WithinAbs(2.807354, 1.0E-4)); + REQUIRE_THAT(r, Catch::Matchers::WithinAbs(4.8275, 1.0E-4)); + } + + TEST_CASE("Circle fitting - test 2", "[landmark]") { + arma::mat points = {{-1,0},{-0.3,-0.06},{0.3,0.1},{1,0}}; + + double c_x; + double c_y; + double r; + std::tie(c_x, c_y, r) = fitCircle(points); + + + REQUIRE_THAT(c_x, Catch::Matchers::WithinAbs(0.4908357, 1.0E-4)); + REQUIRE_THAT(c_y, Catch::Matchers::WithinAbs(-22.15212, 1.0E-4)); + REQUIRE_THAT(r, Catch::Matchers::WithinAbs(22.17979, 1.0E-4)); + } + +} \ No newline at end of file