From f50a7939715840083645b669b882b0ea8343bc6d Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 14 Feb 2021 13:20:17 +0000 Subject: Add test-maths --- test/Jamfile.jam | 1 + test/test-maths.cpp | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 test/test-maths.cpp diff --git a/test/Jamfile.jam b/test/Jamfile.jam index f5d56eb..c6e6d5e 100644 --- a/test/Jamfile.jam +++ b/test/Jamfile.jam @@ -15,3 +15,4 @@ project : requirements ; run test-collection.cpp ; +run test-maths.cpp ; diff --git a/test/test-maths.cpp b/test/test-maths.cpp new file mode 100644 index 0000000..aed51d0 --- /dev/null +++ b/test/test-maths.cpp @@ -0,0 +1,51 @@ +#define BOOST_TEST_MODULE test_maths + +#include +#include +#include + +#include +constexpr auto quarter_pi = pi / 4.F; + +using vecter_to_angle = std::tuple; +BOOST_DATA_TEST_CASE(test_flat_angle, + boost::unit_test::data::make( + {{north, 0}, {south, pi}, {west, half_pi}, {east, -half_pi}, {north + east, -quarter_pi}, + {south + east, quarter_pi * -3}, {north + west, quarter_pi}, {south + west, quarter_pi * 3}}), + v, a) +{ + BOOST_CHECK_CLOSE(flat_angle(v), a, 1.F); +} + +using normalize_angle = std::tuple; +BOOST_DATA_TEST_CASE(test_angle_normalize, + boost::unit_test::data::make({ + {0, 0}, + {two_pi, 0}, + {-two_pi, 0}, + {half_pi, half_pi}, + {-half_pi, -half_pi}, + {half_pi * 3, -half_pi}, + {-half_pi * 3, half_pi}, + }), + in, exp) +{ + BOOST_CHECK_CLOSE(normalize(in), exp, 1); +} + +using pos3_to_arc = std::tuple; +BOOST_DATA_TEST_CASE(test_create_arc, + boost::unit_test::data::make({ + {{0, 0, 0}, north, east, {0, half_pi * 3}}, + {{0, 0, 0}, west, east, {half_pi, half_pi * 3}}, + {{0, 0, 0}, south, east, {pi, half_pi * 3}}, + {{0, 0, 0}, east, north, {-half_pi, 0}}, + {{0, 0, 0}, south, north, {pi, two_pi}}, + }), + c, s, e, a) +{ + const Arc arc {c, s, e}; + BOOST_REQUIRE_LT(arc.first, arc.second); + BOOST_CHECK_CLOSE(arc.first, a.first, 1.F); + BOOST_CHECK_CLOSE(arc.second, a.second, 1.F); +} -- cgit v1.2.3