df

Dependencies:   mbed

Fork of APP1 by Team APP

Committer:
dupm2216
Date:
Tue Jan 17 00:06:38 2017 +0000
Revision:
15:b38d9d210e32
Parent:
13:bb9669053eb3
Child:
18:a21199781d20
Fini?

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();
GaiSensei 12:1c341b119b23 13 test_update_bit();
GaiSensei 12:1c341b119b23 14 test_update_bit_for_values_greater_than_one_byte();
GaiSensei 13:bb9669053eb3 15 test_update_bits();
dupm2216 6:3facf0329142 16 }
dupm2216 6:3facf0329142 17
dupm2216 6:3facf0329142 18 void test_is_almost_equal()
dupm2216 6:3facf0329142 19 {
dupm2216 6:3facf0329142 20 assert(is_almost_equal(0, 0, 0.01));
dupm2216 6:3facf0329142 21 assert(is_almost_equal(0.50, 0.51, 0.02));
dupm2216 6:3facf0329142 22 assert(!is_almost_equal(0.50, 0.52, 0.01));
dupm2216 6:3facf0329142 23 assert(!is_almost_equal(0, 0.50, 0.1));
dupm2216 6:3facf0329142 24 }
dupm2216 6:3facf0329142 25
dupm2216 6:3facf0329142 26 void test_degree_from_radian()
dupm2216 6:3facf0329142 27 {
dupm2216 6:3facf0329142 28 const double tolerance = 0.05;
dupm2216 6:3facf0329142 29 assert(is_almost_equal(0, degree_from_radian(0.0), tolerance));
dupm2216 6:3facf0329142 30 assert(is_almost_equal(90, degree_from_radian(PI/2.0), tolerance));
dupm2216 6:3facf0329142 31 assert(is_almost_equal(180, degree_from_radian(PI), tolerance));
dupm2216 6:3facf0329142 32 assert(is_almost_equal(270, degree_from_radian(3.0*PI/2.0), tolerance));
dupm2216 6:3facf0329142 33 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 34 assert(is_almost_equal(270, degree_from_radian(-PI/2.0), tolerance));
dupm2216 6:3facf0329142 35 }
dupm2216 6:3facf0329142 36
dupm2216 6:3facf0329142 37 void test_wrap_angle()
dupm2216 6:3facf0329142 38 {
dupm2216 6:3facf0329142 39 const double tolerance = 0.05;
dupm2216 6:3facf0329142 40 assert(is_almost_equal(0, wrap_angle(0.0), tolerance));
dupm2216 6:3facf0329142 41 assert(is_almost_equal(90, wrap_angle(90), tolerance));
dupm2216 6:3facf0329142 42 assert(is_almost_equal(180, wrap_angle(180), tolerance));
dupm2216 6:3facf0329142 43 assert(is_almost_equal(0, wrap_angle(360), tolerance) || is_almost_equal(360, wrap_angle(360), tolerance));
dupm2216 6:3facf0329142 44 assert(is_almost_equal(90, wrap_angle(360+90), tolerance));
dupm2216 6:3facf0329142 45 assert(is_almost_equal(270, wrap_angle(360-90), tolerance));
dupm2216 6:3facf0329142 46 }
GaiSensei 12:1c341b119b23 47
GaiSensei 12:1c341b119b23 48 void test_update_bit()
GaiSensei 12:1c341b119b23 49 {
GaiSensei 12:1c341b119b23 50 assert(4 == sizeof(int));
GaiSensei 12:1c341b119b23 51 assert(0x00 == update_bit(0x00, 0, 0));
GaiSensei 12:1c341b119b23 52 assert(0x01 == update_bit(0x00, 0, 1));
GaiSensei 12:1c341b119b23 53 assert(0x00 == update_bit(0x01, 0, 0));
GaiSensei 12:1c341b119b23 54 assert(0x05 == update_bit(0x07, 1, 0));
GaiSensei 12:1c341b119b23 55 }
GaiSensei 12:1c341b119b23 56
GaiSensei 12:1c341b119b23 57 void test_update_bit_for_values_greater_than_one_byte()
GaiSensei 12:1c341b119b23 58 {
GaiSensei 12:1c341b119b23 59 assert(0x7FFF == update_bit(0xFFFF, 15, 0));
GaiSensei 12:1c341b119b23 60 assert(0x7FFFFFFF == update_bit(0xFFFFFFFF, 31, 0));
GaiSensei 12:1c341b119b23 61 }
GaiSensei 13:bb9669053eb3 62
GaiSensei 13:bb9669053eb3 63 void test_update_bits()
GaiSensei 13:bb9669053eb3 64 {
dupm2216 15:b38d9d210e32 65 assert(0x0F == update_bits(0x00, 0, 3, 0xFFFFFFFF, 0x0F));
dupm2216 15:b38d9d210e32 66 assert(0x1E == update_bits(0x00, 1, 4, 0xFFFFFFFF, 0x0F));
dupm2216 15:b38d9d210e32 67 assert(0x00 == update_bits(0x00, 0, 3, 0x00000000, 0x0F));
dupm2216 15:b38d9d210e32 68 assert(0x00 == update_bits(0x00, 1, 4, 0x00000000, 0x0F));
GaiSensei 13:bb9669053eb3 69 }
dupm2216 9:12519f9dd3cd 70 }