Code

304182fed71cbe4162455741c2aa762fc229e645
[inkscape.git] / src / libnr / in-svg-plane-test.h
1 #include <cxxtest/TestSuite.h>
3 #include <glib/gmacros.h>
4 #include <cmath>
6 #include "libnr/in-svg-plane.h"
7 #include "2geom/isnan.h"
9 class InSvgPlaneTest : public CxxTest::TestSuite
10 {
11 public:
13     InSvgPlaneTest() :
14         setupValid(true),
15         p3n4( 3.0, -4.0 ),
16         p0(0.0, 0.0),
17         small( pow(2.0, -1070) ),
18         inf( 1e400 ),
19         nan( inf - inf ),
20         small_left( -small, 0.0 ),
21         small_n3_4( -3.0 * small, 4.0 * small ),
22         part_nan( 3., nan )
23     {
24         setupValid &= IS_NAN(nan);
25         setupValid &= !IS_NAN(small);
26     }
27     virtual ~InSvgPlaneTest() {}
29 // createSuite and destroySuite get us per-suite setup and teardown
30 // without us having to worry about static initialization order, etc.
31     static InSvgPlaneTest *createSuite() { return new InSvgPlaneTest(); }
32     static void destroySuite( InSvgPlaneTest *suite ) { delete suite; }
34 // Called before each test in this suite
35     void setUp()
36     {
37         TS_ASSERT( setupValid );
38     }
40     bool setupValid;
41     NR::Point const p3n4;
42     NR::Point const p0;
43     double const small;
44     double const inf;
45     double const nan;
46     NR::Point const small_left;
47     NR::Point const small_n3_4;
48     NR::Point const part_nan;
51     void testInSvgPlane(void)
52     {
53         TS_ASSERT( in_svg_plane(p3n4) );
54         TS_ASSERT( in_svg_plane(p0) );
55         TS_ASSERT( in_svg_plane(small_left) );
56         TS_ASSERT( in_svg_plane(small_n3_4) );
57         TS_ASSERT_DIFFERS( nan, nan );
58         TS_ASSERT( !in_svg_plane(NR::Point(nan, 3.)) );
59         TS_ASSERT( !in_svg_plane(NR::Point(inf, nan)) );
60         TS_ASSERT( !in_svg_plane(NR::Point(0., -inf)) );
61         double const xs[] = {inf, -inf, nan, 1., -2., small, -small};
62         for (unsigned i = 0; i < G_N_ELEMENTS(xs); ++i) {
63             for (unsigned j = 0; j < G_N_ELEMENTS(xs); ++j) {
64                 TS_ASSERT_EQUALS( in_svg_plane(NR::Point(xs[i], xs[j])),
65                                   (fabs(xs[i]) < inf &&
66                                    fabs(xs[j]) < inf   ) );
67             }
68         }
69     }
70 };
72 /*
73   Local Variables:
74   mode:c++
75   c-file-style:"stroustrup"
76   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
77   indent-tabs-mode:nil
78   fill-column:99
79   End:
80 */
81 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :