android/GlueIOIOPort: fix spurious errors after IOIO baud rate change
[xcsoar.git] / test / src / TestUtil.hpp
blob597a63f08ae366504087f67630f58041c75a4623
1 /* Copyright_License {
3 XCSoar Glide Computer - http://www.xcsoar.org/
4 Copyright (C) 2000-2013 The XCSoar Project
5 A detailed list of copyright holders can be found in the file "AUTHORS".
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; either version 2
10 of the License, or (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 #ifndef XCSOAR_TEST_UTIL_HPP
24 #define XCSOAR_TEST_UTIL_HPP
26 #include "Geo/GeoPoint.hpp"
27 #include "Math/Angle.hpp"
29 #ifndef ACCURACY
30 /**
31 * Define this macro before including TestUtil.hpp to compare with a
32 * different accuracy.
34 #define ACCURACY 10000
35 #endif
37 extern "C" {
38 #include "tap.h"
41 static inline bool
42 is_zero(const fixed value, const int accuracy=ACCURACY)
44 return (long)(fabs(value) * accuracy) == 0;
47 static inline bool
48 is_one(const fixed value, const int accuracy=ACCURACY)
50 return is_zero(value - fixed(1), accuracy);
53 static inline bool
54 equals(const fixed a, const fixed b, const int accuracy=ACCURACY)
56 if (is_zero(a, accuracy) || is_zero(b, accuracy))
57 return is_zero(a, accuracy) && is_zero(b, accuracy);
59 return is_one(a / b, accuracy);
62 #ifdef FIXED_MATH
63 static inline bool
64 equals(const fixed a, double b)
66 return equals(a, fixed(b));
68 #endif
70 static inline bool
71 equals(const fixed a, int b)
73 return equals(a, fixed(b));
76 #ifdef FIXED_MATH
77 static inline bool
78 between(double x, double a, double b)
80 return x >= a && x <= b;
82 #endif
84 static inline bool
85 between(fixed x, fixed a, fixed b)
87 return x >= a && x <= b;
90 #ifdef FIXED_MATH
92 static inline bool
93 between(fixed x, double a, double b)
95 return between(x, fixed(a), fixed(b));
98 #endif
100 static inline bool
101 equals(const Angle a, int b)
103 return equals(a.Degrees(), fixed(b));
106 static inline bool
107 equals(const Angle a, double b)
109 return equals(a.Degrees(), fixed(b));
112 static inline bool
113 equals(const Angle a, const Angle b)
115 return is_zero((a - b).AsDelta().Degrees());
118 static inline bool
119 equals(const GeoPoint a, double lat, double lon)
121 return equals(a.latitude, lat) && equals(a.longitude, lon);
124 static inline bool
125 equals(const GeoPoint a, const Angle lat, const Angle lon)
127 return equals(a.latitude, lat) && equals(a.longitude, lon);
130 static inline bool
131 equals(const GeoPoint a, const GeoPoint b)
133 return equals(a.latitude, b.latitude) && equals(a.longitude, b.longitude);
136 #endif