
df
Fork of APP1 by
Diff: TestAccelerometer.cpp
- Revision:
- 5:f59b51ac4b40
- Parent:
- 4:303fb83498fd
- Child:
- 6:3facf0329142
--- a/TestAccelerometer.cpp Sat Jan 14 23:32:29 2017 +0000 +++ b/TestAccelerometer.cpp Sun Jan 15 01:34:25 2017 +0000 @@ -3,6 +3,7 @@ #include "mbed.h" #include <cassert> +#include <cmath> namespace accelerometer { @@ -51,4 +52,46 @@ assert(!is_almost_equal(0.50, 0.52, 0.01)); assert(!is_almost_equal(0, 0.50, 0.1)); } + + void test_angle_from_int_axis_data() + { + const double tolerance = 0.05; + assert(is_almost_equal(0, angle_from_int_axis_data(64), tolerance)); + assert(is_almost_equal(0, angle_from_int_axis_data(-64), tolerance)); + assert(is_almost_equal(60, angle_from_int_axis_data(32), tolerance)); + assert(is_almost_equal(60, angle_from_int_axis_data(-32), tolerance)); + } + + void test_g_force_from_int_axis_data() + { + const double tolerance = 0.05; + assert(is_almost_equal(1, g_force_from_int_axis_data(64), tolerance)); + assert(is_almost_equal(-1, g_force_from_int_axis_data(-64), tolerance)); + assert(is_almost_equal(2, g_force_from_int_axis_data(128), tolerance)); + assert(is_almost_equal(-2, g_force_from_int_axis_data(-128), tolerance)); + assert(is_almost_equal(0.5, g_force_from_int_axis_data(32), tolerance)); + assert(is_almost_equal(-0.5, g_force_from_int_axis_data(-32), tolerance)); + } + + void test_degree_from_radian() + { + const double tolerance = 0.05; + assert(is_almost_equal(0, degree_from_radian(0.0), tolerance)); + assert(is_almost_equal(90, degree_from_radian(PI/2.0), tolerance)); + assert(is_almost_equal(180, degree_from_radian(PI), tolerance)); + assert(is_almost_equal(270, degree_from_radian(3.0*PI/2.0), tolerance)); + assert(is_almost_equal(0, degree_from_radian(2.0*PI), tolerance) || is_almost_equal(360, degree_from_radian(2.0*PI), tolerance)); + assert(is_almost_equal(270, degree_from_radian(-PI/2.0), tolerance)); + } + + void test_wrap_angle() + { + const double tolerance = 0.05; + assert(is_almost_equal(0, wrap_angle(0.0), tolerance)); + assert(is_almost_equal(90, wrap_angle(90), tolerance)); + assert(is_almost_equal(180, wrap_angle(180), tolerance)); + assert(is_almost_equal(0, wrap_angle(360), tolerance) || is_almost_equal(360, wrap_angle(360), tolerance)); + assert(is_almost_equal(90, wrap_angle(360+90), tolerance)); + assert(is_almost_equal(270, wrap_angle(360-90), tolerance)); + } } \ No newline at end of file