1 #include <cxxtest/TestSuite.h>
3 #include <libnr/nr-scale.h>
4 #include <libnr/nr-scale-ops.h>
5 using NR::X;
6 using NR::Y;
8 class NrScaleTest : public CxxTest::TestSuite
9 {
10 public:
12 NrScaleTest() :
13 sa( 1.5, 2.0 ),
14 b( -2.0, 3.0 ),
15 sb( b )
16 {
17 }
18 virtual ~NrScaleTest() {}
20 // createSuite and destroySuite get us per-suite setup and teardown
21 // without us having to worry about static initialization order, etc.
22 static NrScaleTest *createSuite() { return new NrScaleTest(); }
23 static void destroySuite( NrScaleTest *suite ) { delete suite; }
25 NR::scale const sa;
26 NR::Point const b;
27 NR::scale const sb;
31 void testXY_CtorArrayOperator(void)
32 {
33 TS_ASSERT_EQUALS( sa[X], 1.5 );
34 TS_ASSERT_EQUALS( sa[Y], 2.0 );
35 TS_ASSERT_EQUALS( sa[0u], 1.5 );
36 TS_ASSERT_EQUALS( sa[1u], 2.0 );
37 }
40 void testCopyCtor_AssignmentOp_NotEquals(void)
41 {
42 NR::scale const sa_copy(sa);
43 TS_ASSERT_EQUALS( sa, sa_copy );
44 TS_ASSERT(!( sa != sa_copy ));
45 TS_ASSERT( sa != sb );
46 }
48 void testAssignmentOp(void)
49 {
50 NR::scale sa_eq(sb);
51 sa_eq = sa;
52 TS_ASSERT_EQUALS( sa, sa_eq );
53 }
55 void testPointCtor(void)
56 {
57 TS_ASSERT_EQUALS( sb[X], b[X] );
58 TS_ASSERT_EQUALS( sb[Y], b[Y] );
59 }
61 void testOpStarPointScale(void)
62 {
63 NR::Point const ab( b * sa );
64 TS_ASSERT_EQUALS( ab, NR::Point(-3.0, 6.0) );
65 }
67 void testOpStarScaleScale(void)
68 {
69 NR::scale const sab( sa * sb );
70 TS_ASSERT_EQUALS( sab, NR::scale(-3.0, 6.0) );
71 }
73 void testOpDivScaleScale(void)
74 {
75 NR::scale const sa_b( sa / sb );
76 NR::scale const exp_sa_b(-0.75, 2./3.);
77 TS_ASSERT_EQUALS( sa_b[0], exp_sa_b[0] );
78 // TS_ASSERT_EQUALS( fabs( sa_b[1] - exp_sa_b[1] ) < 1e-10 );
79 TS_ASSERT_DELTA( sa_b[1], exp_sa_b[1], 1e-10 );
80 }
81 };
83 /*
84 Local Variables:
85 mode:c++
86 c-file-style:"stroustrup"
87 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
88 indent-tabs-mode:nil
89 fill-column:99
90 End:
91 */
92 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :