df

Dependencies:   mbed

Fork of APP1 by Team APP

Committer:
dupm2216
Date:
Sun Jan 15 02:04:23 2017 +0000
Revision:
6:3facf0329142
Child:
9:12519f9dd3cd
Move utility functions out of Accelerometer

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dupm2216 6:3facf0329142 1 #include "TestUtility.hpp"
dupm2216 6:3facf0329142 2 #include "Utility.hpp"
dupm2216 6:3facf0329142 3
dupm2216 6:3facf0329142 4 #include <cassert>
dupm2216 6:3facf0329142 5
dupm2216 6:3facf0329142 6 namespace utility
dupm2216 6:3facf0329142 7 {
dupm2216 6:3facf0329142 8 void run_all_tests()
dupm2216 6:3facf0329142 9 {
dupm2216 6:3facf0329142 10 test_is_almost_equal();
dupm2216 6:3facf0329142 11 test_degree_from_radian();
dupm2216 6:3facf0329142 12 test_wrap_angle();
dupm2216 6:3facf0329142 13 }
dupm2216 6:3facf0329142 14
dupm2216 6:3facf0329142 15 void test_is_almost_equal()
dupm2216 6:3facf0329142 16 {
dupm2216 6:3facf0329142 17 assert(is_almost_equal(0, 0, 0.01));
dupm2216 6:3facf0329142 18 assert(is_almost_equal(0.50, 0.51, 0.02));
dupm2216 6:3facf0329142 19 assert(!is_almost_equal(0.50, 0.52, 0.01));
dupm2216 6:3facf0329142 20 assert(!is_almost_equal(0, 0.50, 0.1));
dupm2216 6:3facf0329142 21 }
dupm2216 6:3facf0329142 22
dupm2216 6:3facf0329142 23 void test_degree_from_radian()
dupm2216 6:3facf0329142 24 {
dupm2216 6:3facf0329142 25 const double tolerance = 0.05;
dupm2216 6:3facf0329142 26 assert(is_almost_equal(0, degree_from_radian(0.0), tolerance));
dupm2216 6:3facf0329142 27 assert(is_almost_equal(90, degree_from_radian(PI/2.0), tolerance));
dupm2216 6:3facf0329142 28 assert(is_almost_equal(180, degree_from_radian(PI), tolerance));
dupm2216 6:3facf0329142 29 assert(is_almost_equal(270, degree_from_radian(3.0*PI/2.0), tolerance));
dupm2216 6:3facf0329142 30 assert(is_almost_equal(0, degree_from_radian(2.0*PI), tolerance) || is_almost_equal(360, degree_from_radian(2.0*PI), tolerance));
dupm2216 6:3facf0329142 31 assert(is_almost_equal(270, degree_from_radian(-PI/2.0), tolerance));
dupm2216 6:3facf0329142 32 }
dupm2216 6:3facf0329142 33
dupm2216 6:3facf0329142 34 void test_wrap_angle()
dupm2216 6:3facf0329142 35 {
dupm2216 6:3facf0329142 36 const double tolerance = 0.05;
dupm2216 6:3facf0329142 37 assert(is_almost_equal(0, wrap_angle(0.0), tolerance));
dupm2216 6:3facf0329142 38 assert(is_almost_equal(90, wrap_angle(90), tolerance));
dupm2216 6:3facf0329142 39 assert(is_almost_equal(180, wrap_angle(180), tolerance));
dupm2216 6:3facf0329142 40 assert(is_almost_equal(0, wrap_angle(360), tolerance) || is_almost_equal(360, wrap_angle(360), tolerance));
dupm2216 6:3facf0329142 41 assert(is_almost_equal(90, wrap_angle(360+90), tolerance));
dupm2216 6:3facf0329142 42 assert(is_almost_equal(270, wrap_angle(360-90), tolerance));
dupm2216 6:3facf0329142 43 }
dupm2216 6:3facf0329142 44 };