Code

Unit test cleanup.
[inkscape.git] / src / libnr / nr-translate-test.h
1 #include <cxxtest/TestSuite.h>
3 #include <libnr/nr-point-ops.h>
4 #include <libnr/nr-matrix.h>
5 #include <libnr/nr-matrix-fns.h>
6 #include <libnr/nr-matrix-ops.h>
7 #include <libnr/nr-point-matrix-ops.h>
8 #include <libnr/nr-translate.h>
9 #include <libnr/nr-translate-ops.h>
11 class NrTranslateTest : public CxxTest::TestSuite
12 {
13 public:
15     NrTranslateTest() :
16         b( -2.0, 3.0 ),
17         tb( b ),
18         tc( -3.0, -2.0 ),
19         tbc( tb * tc ),
20         t_id( 0.0, 0.0 ),
21         m_id( NR::identity() )
22     {
23     }
24     virtual ~NrTranslateTest() {}
26 // createSuite and destroySuite get us per-suite setup and teardown
27 // without us having to worry about static initialization order, etc.
28     static NrTranslateTest *createSuite() { return new NrTranslateTest(); }
29     static void destroySuite( NrTranslateTest *suite ) { delete suite; }
31     NR::Point const b;
32     NR::translate const tb;
33     NR::translate const tc;
34     NR::translate const tbc;
35     NR::translate const t_id;
36     NR::Matrix const m_id;
39     void testCtorsArrayOperator(void)
40     {
41         TS_ASSERT_EQUALS( tc[NR::X], -3.0 );
42         TS_ASSERT_EQUALS( tc[NR::Y], -2.0 );
44         TS_ASSERT_EQUALS( tb[0], b[NR::X] );
45         TS_ASSERT_EQUALS( tb[1], b[NR::Y] );
46     }
48     void testAssignmentOperator(void)
49     {
50         NR::translate tb_eq(tc);
51         tb_eq = tb;
52         TS_ASSERT_EQUALS( tb, tb_eq );
53         TS_ASSERT_DIFFERS( tb_eq, tc );
54     }
56     void testOpStarTranslateTranslate(void)
57     {
58         TS_ASSERT_EQUALS( tbc.offset, NR::Point(-5.0, 1.0) );
59         TS_ASSERT_EQUALS( tbc.offset, ( tc * tb ).offset );
60         TS_ASSERT_EQUALS( NR::Matrix(tbc), NR::Matrix(tb) * NR::Matrix(tc) );
61     }
63     void testOpStarPointTranslate(void)
64     {
65         TS_ASSERT_EQUALS( tbc.offset, b * tc );
66         TS_ASSERT_EQUALS( b * tc, b * NR::Matrix(tc) );
67     }
69     void testIdentity(void)
70     {
71         TS_ASSERT_EQUALS( b * t_id, b );
72         TS_ASSERT_EQUALS( NR::Matrix(t_id), m_id );
73     }
74 };
76 /*
77   Local Variables:
78   mode:c++
79   c-file-style:"stroustrup"
80   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
81   indent-tabs-mode:nil
82   fill-column:99
83   End:
84 */
85 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :