Code

Disable the page selector when there's only one page
[inkscape.git] / src / libnr / nr-point-fns-test.h
1 // nr-point-fns-test.h
2 #include <cxxtest/TestSuite.h>
4 #include <cassert>
5 #include <cmath>
6 #include <glib/gmacros.h>
7 #include <stdlib.h>
9 #include "libnr/nr-point-fns.h"
10 #include "isnan.h"
12 using NR::Point;
14 class NrPointFnsTest : public CxxTest::TestSuite
15 {
16 public:
17     NrPointFnsTest() :
18         setupValid(true),
19         p3n4( 3.0, -4.0 ),
20         p0( 0.0, 0.0 ),
21         small( pow( 2.0, -1070 ) ),
22         inf( 1e400 ),
23         nan( inf - inf ),
24         small_left( -small, 0.0 ),
25         small_n3_4( -3.0 * small, 4.0 * small ),
26         part_nan( 3., nan ),
27         inf_left( -inf, 5.0 )
28     {
29         TS_ASSERT( isNaN(nan) );
30         TS_ASSERT( !isNaN(small) );
32         setupValid &= isNaN(nan);
33         setupValid &= !isNaN(small);
34     }
35     virtual ~NrPointFnsTest() {}
37 // createSuite and destroySuite get us per-suite setup and teardown
38 // without us having to worry about static initialization order, etc.
39     static NrPointFnsTest *createSuite() { return new NrPointFnsTest(); }
40     static void destroySuite( NrPointFnsTest *suite ) { delete suite; }
42 // Called before each test in this suite
43     void setUp()
44     {
45         TS_ASSERT( setupValid );
46     }
48     bool setupValid;
49     Point const p3n4;
50     Point const p0;
51     double const small;
52     double const inf;
53     double const nan;
55     Point const small_left;
56     Point const small_n3_4;
57     Point const part_nan;
58     Point const inf_left;
61     void testL1(void)
62     {
63         TS_ASSERT_EQUALS( NR::L1(p0), 0.0  );
64         TS_ASSERT_EQUALS( NR::L1(p3n4), 7.0  );
65         TS_ASSERT_EQUALS( NR::L1(small_left), small  );
66         TS_ASSERT_EQUALS( NR::L1(inf_left), inf  );
67         TS_ASSERT_EQUALS( NR::L1(small_n3_4), 7.0 * small  );
68         TS_ASSERT(isNaN(NR::L1(part_nan)));
69     }
71     void testL2(void)
72     {
73         TS_ASSERT_EQUALS( NR::L2(p0), 0.0 );
74         TS_ASSERT_EQUALS( NR::L2(p3n4), 5.0 );
75         TS_ASSERT_EQUALS( NR::L2(small_left), small );
76         TS_ASSERT_EQUALS( NR::L2(inf_left), inf );
77         TS_ASSERT_EQUALS( NR::L2(small_n3_4), 5.0 * small );
78         TS_ASSERT( isNaN(NR::L2(part_nan)) );
79     }
81     void testLInfty(void)
82     {
83         TS_ASSERT_EQUALS( NR::LInfty(p0), 0.0 );
84         TS_ASSERT_EQUALS( NR::LInfty(p3n4), 4.0 );
85         TS_ASSERT_EQUALS( NR::LInfty(small_left), small );
86         TS_ASSERT_EQUALS( NR::LInfty(inf_left), inf );
87         TS_ASSERT_EQUALS( NR::LInfty(small_n3_4), 4.0 * small );
88         TS_ASSERT( isNaN(NR::LInfty(part_nan)) );
89     }
91     void testIsZero(void)
92     {
93         TS_ASSERT( NR::is_zero(p0) );
94         TS_ASSERT( !NR::is_zero(p3n4) );
95         TS_ASSERT( !NR::is_zero(small_left) );
96         TS_ASSERT( !NR::is_zero(inf_left) );
97         TS_ASSERT( !NR::is_zero(small_n3_4) );
98         TS_ASSERT( !NR::is_zero(part_nan) );
99     }
101     void testAtan2(void)
102     {
103         TS_ASSERT_EQUALS( NR::atan2(p3n4), atan2(-4.0, 3.0) );
104         TS_ASSERT_EQUALS( NR::atan2(small_left), atan2(0.0, -1.0) );
105         TS_ASSERT_EQUALS( NR::atan2(small_n3_4), atan2(4.0, -3.0) );
106     }
108     void testUnitVector(void)
109     {
110         TS_ASSERT_EQUALS( NR::unit_vector(p3n4), Point(.6, -0.8) );
111         TS_ASSERT_EQUALS( NR::unit_vector(small_left), Point(-1.0, 0.0) );
112         TS_ASSERT_EQUALS( NR::unit_vector(small_n3_4), Point(-.6, 0.8) );
113     }
115     void testIsUnitVector(void)
116     {
117         TS_ASSERT( !NR::is_unit_vector(p3n4) );
118         TS_ASSERT( !NR::is_unit_vector(small_left) );
119         TS_ASSERT( !NR::is_unit_vector(small_n3_4) );
120         TS_ASSERT( !NR::is_unit_vector(part_nan) );
121         TS_ASSERT( !NR::is_unit_vector(inf_left) );
122         TS_ASSERT( !NR::is_unit_vector(Point(.5, 0.5)) );
123         TS_ASSERT( NR::is_unit_vector(Point(.6, -0.8)) );
124         TS_ASSERT( NR::is_unit_vector(Point(-.6, 0.8)) );
125         TS_ASSERT( NR::is_unit_vector(Point(-1.0, 0.0)) );
126         TS_ASSERT( NR::is_unit_vector(Point(1.0, 0.0)) );
127         TS_ASSERT( NR::is_unit_vector(Point(0.0, -1.0)) );
128         TS_ASSERT( NR::is_unit_vector(Point(0.0, 1.0)) );
129     }
130 };
132 /*
133   Local Variables:
134   mode:c++
135   c-file-style:"stroustrup"
136   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
137   indent-tabs-mode:nil
138   fill-column:99
139   End:
140 */
141 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :