~lib2geom-hackers/lib2geom/trunk

« back to all changes in this revision

Viewing changes to translate-test.h

  • Committer: njh
  • Date: 2006-05-22 11:50:24 UTC
  • Revision ID: svn-v4:4601daaa-0314-0410-9a8b-c964a3c23b6b:trunk/lib2geom:1
initial commit

Show diffs side-by-side

added added

removed removed

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