Skip to content

Commit

Permalink
add circle tests
Browse files Browse the repository at this point in the history
  • Loading branch information
maxipalay committed Mar 16, 2024
1 parent 6ef4388 commit a17f353
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
5 changes: 3 additions & 2 deletions turtlelib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
36 changes: 36 additions & 0 deletions turtlelib/tests/circle_tests.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include <catch2/catch_test_macros.hpp>
#include <catch2/matchers/catch_matchers_floating_point.hpp>
#include "turtlelib/landmark_detection.hpp"
#include <armadillo>

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));
}

}

0 comments on commit a17f353

Please sign in to comment.