mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-05-23 12:57:34 +08:00
helper test: add extensive wrap tests
This commit is contained in:
+23
-10
@@ -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));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user