1 #include <utest/utest.h>
2 #include "mod360.h"
3 #include <glib.h>
4 #include <math.h>
6 /** Note: doesn't distinguish between 0.0 and -0.0. */
7 static bool same_double(double const x, double const y)
8 {
9 return ( ( isnan(x) && isnan(y) )
10 || ( x == y ) );
11 }
13 int main(int argc, char **argv)
14 {
15 double const inf = 1e400;
16 double const nan = inf - inf;
18 utest_start("mod360.cpp");
20 UTEST_TEST("same_double") {
21 double const sd_cases[] = {inf, -inf, nan, 0.0, -1.0, 1.0, 8.0};
22 for (unsigned i = 0; i < G_N_ELEMENTS(sd_cases); ++i) {
23 for (unsigned j = 0; j < G_N_ELEMENTS(sd_cases); ++j) {
24 UTEST_ASSERT( same_double(sd_cases[i], sd_cases[j])
25 == ( i == j ) );
26 }
27 }
28 }
30 UTEST_TEST("mod360") {
31 struct Case {
32 double x;
33 double y;
34 } const cases[] = {
35 {0, 0},
36 {10, 10},
37 {360, 0},
38 {361, 1},
39 {-1, 359},
40 {-359, 1},
41 {-360, -0},
42 {-361, 359},
43 {inf, 0},
44 {-inf, 0},
45 {nan, 0},
46 {720, 0},
47 {-721, 359},
48 {-1000, 80}
49 };
50 for(unsigned i = 0; i < G_N_ELEMENTS(cases); ++i) {
51 Case const &c = cases[i];
52 UTEST_ASSERT(same_double(mod360(c.x), c.y));
53 }
54 }
56 return ( utest_end()
57 ? EXIT_SUCCESS
58 : EXIT_FAILURE );
59 }
61 /*
62 Local Variables:
63 mode:c++
64 c-file-style:"stroustrup"
65 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
66 indent-tabs-mode:nil
67 fill-column:99
68 End:
69 */
70 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :