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"
31 * Define this macro before including TestUtil.hpp to compare with a
34 #define ACCURACY 10000
42 is_zero(const fixed value
, const int accuracy
=ACCURACY
)
44 return (long)(fabs(value
) * accuracy
) == 0;
48 is_one(const fixed value
, const int accuracy
=ACCURACY
)
50 return is_zero(value
- fixed(1), accuracy
);
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
);
64 equals(const fixed a
, double b
)
66 return equals(a
, fixed(b
));
71 equals(const fixed a
, int b
)
73 return equals(a
, fixed(b
));
78 between(double x
, double a
, double b
)
80 return x
>= a
&& x
<= b
;
85 between(fixed x
, fixed a
, fixed b
)
87 return x
>= a
&& x
<= b
;
93 between(fixed x
, double a
, double b
)
95 return between(x
, fixed(a
), fixed(b
));
101 equals(const Angle a
, int b
)
103 return equals(a
.Degrees(), fixed(b
));
107 equals(const Angle a
, double b
)
109 return equals(a
.Degrees(), fixed(b
));
113 equals(const Angle a
, const Angle b
)
115 return is_zero((a
- b
).AsDelta().Degrees());
119 equals(const GeoPoint a
, double lat
, double lon
)
121 return equals(a
.latitude
, lat
) && equals(a
.longitude
, lon
);
125 equals(const GeoPoint a
, const Angle lat
, const Angle lon
)
127 return equals(a
.latitude
, lat
) && equals(a
.longitude
, lon
);
131 equals(const GeoPoint a
, const GeoPoint b
)
133 return equals(a
.latitude
, b
.latitude
) && equals(a
.longitude
, b
.longitude
);