From 938274fce5ea93743f0c11fd7622089b3ee39281 Mon Sep 17 00:00:00 2001 From: Matthias Grob Date: Wed, 4 Sep 2019 23:45:09 +0200 Subject: [PATCH] helper test: add extensive wrap tests --- test/helper.cpp | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/test/helper.cpp b/test/helper.cpp index a21c90a76c..7fe23820ef 100644 --- a/test/helper.cpp +++ b/test/helper.cpp @@ -5,22 +5,35 @@ using namespace matrix; int main() { - TEST(fabs(wrap_pi(4.0) - (4.0 - 2*M_PI)) < FLT_EPSILON); - TEST(fabs(wrap_pi(-4.0) - (-4.0 + 2*M_PI)) < FLT_EPSILON); - TEST(fabs(wrap_pi(3.0) - (3.0)) < FLT_EPSILON); - TEST(!is_finite(wrap_pi(1000.0f))); - TEST(!is_finite(wrap_pi(-1000.0f))); - wrap_pi(NAN); + // general wraps + TEST(fabs(wrap(4.0, 0.0, 10.0) - 4.0) < FLT_EPSILON); + TEST(fabs(wrap(4.0, 0.0, 1.0)) < FLT_EPSILON); + TEST(fabs(wrap(-4.0, 0.0, 10.0) - 6.0) < FLT_EPSILON); + TEST(fabs(wrap(-18.0, 0.0, 10.0) - 2.0) < FLT_EPSILON); + TEST(fabs(wrap(-1.5, 3.0, 5.0) - 4.5) < FLT_EPSILON); + TEST(fabs(wrap(15.5, 3.0, 5.0) - 3.5) < FLT_EPSILON); + TEST(fabs(wrap(-1.0, 30.0, 40.0) - 39.0) < FLT_EPSILON); + TEST(fabs(wrap(-8000.0, -555.0, 1.0) - (-216.0)) < FLT_EPSILON); + TEST(!is_finite(wrap(1000.,0.,.01))); + // wrap pi + TEST(fabs(wrap_pi(4.0) - (4.0 - M_TWOPI)) < FLT_EPSILON); + TEST(fabs(wrap_pi(-4.0) - (-4.0 + M_TWOPI)) < FLT_EPSILON); + TEST(fabs(wrap_pi(3.0) - (3.0)) < FLT_EPSILON); + TEST(fabs(wrap_pi(100.0f) - (100.0f - 32 * float(M_PI))) < 10e-5); + TEST(fabs(wrap_pi(-100.0f) - (-100.0f + 32 * float(M_PI))) < 10e-5); + TEST(fabs(wrap_pi(-101.0f) - (-101.0f + 32 * float(M_PI))) < 10e-5); + TEST(!is_finite(wrap_pi(NAN))); + + // wrap 2pi TEST(fabs(wrap_2pi(-4.0) - (-4.0 + 2*M_PI)) < FLT_EPSILON); TEST(fabs(wrap_2pi(3.0) - (3.0)) < FLT_EPSILON); - TEST(!is_finite(wrap_2pi(1000.0f))); - TEST(!is_finite(wrap_2pi(-1000.0f))); - wrap_2pi(NAN); + TEST(fabs(wrap_2pi(200.0f) - (200.0f - 31 * float(M_TWOPI))) < 10e-5); + TEST(fabs(wrap_2pi(-201.0f) - (-201.0f + 32 * float(M_TWOPI))) < 10e-5); + TEST(!is_finite(wrap_2pi(NAN))); Vector3f a(1, 2, 3); Vector3f b(4, 5, 6); - a.T().print(); TEST(!isEqual(a, b)); TEST(isEqual(a, a));