]>
Commit | Line | Data |
---|---|---|
3e8f9a49 WS |
1 | /////////////////////////////////////////////////////////////////////////////// |
2 | // Name: tests/geometry/point.cpp | |
3 | // Purpose: wxPoint unit test | |
4 | // Author: Wlodzimierz ABX Skiba | |
5 | // Created: 2004-12-14 | |
6 | // RCS-ID: $Id$ | |
7 | // Copyright: (c) 2004 wxWindows | |
8 | /////////////////////////////////////////////////////////////////////////////// | |
9 | ||
10 | // ---------------------------------------------------------------------------- | |
11 | // headers | |
12 | // ---------------------------------------------------------------------------- | |
13 | ||
14 | #include "testprec.h" | |
15 | ||
16 | #ifdef __BORLANDC__ | |
17 | #pragma hdrstop | |
18 | #endif | |
19 | ||
20 | #ifndef WX_PRECOMP | |
21 | #include "wx/gdicmn.h" | |
22 | #endif // WX_PRECOMP | |
23 | ||
24 | // ---------------------------------------------------------------------------- | |
25 | // test class | |
26 | // ---------------------------------------------------------------------------- | |
27 | ||
28 | class PointTestCase : public CppUnit::TestCase | |
29 | { | |
30 | public: | |
31 | PointTestCase() { } | |
32 | ||
33 | private: | |
34 | CPPUNIT_TEST_SUITE( PointTestCase ); | |
35 | CPPUNIT_TEST( Operators ); | |
36 | CPPUNIT_TEST_SUITE_END(); | |
37 | ||
38 | void Operators(); | |
39 | ||
40 | DECLARE_NO_COPY_CLASS(PointTestCase) | |
41 | }; | |
42 | ||
43 | class RealPointTestCase : public CppUnit::TestCase | |
44 | { | |
45 | public: | |
46 | RealPointTestCase() { } | |
47 | ||
48 | private: | |
49 | CPPUNIT_TEST_SUITE( RealPointTestCase ); | |
50 | CPPUNIT_TEST( Operators ); | |
51 | CPPUNIT_TEST_SUITE_END(); | |
52 | ||
53 | void Operators(); | |
54 | ||
55 | DECLARE_NO_COPY_CLASS(RealPointTestCase) | |
56 | }; | |
57 | ||
58 | // register in the unnamed registry so that these tests are run by default | |
59 | CPPUNIT_TEST_SUITE_REGISTRATION( PointTestCase ); | |
60 | CPPUNIT_TEST_SUITE_REGISTRATION( RealPointTestCase ); | |
61 | ||
62 | // also include in it's own registry so that these tests can be run alone | |
63 | CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( PointTestCase, "PointTestCase" ); | |
64 | CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( RealPointTestCase, "RealPointTestCase" ); | |
65 | ||
66 | void PointTestCase::Operators() | |
67 | { | |
68 | wxPoint p1(1,2); | |
69 | wxPoint p2(6,3); | |
70 | wxPoint p3(7,5); | |
71 | wxPoint p4(5,1); | |
72 | wxPoint p5 = p2 + p1; | |
73 | wxPoint p6 = p2 - p1; | |
74 | CPPUNIT_ASSERT( p3.x == p5.x && p3.y == p5.y ); | |
75 | CPPUNIT_ASSERT( p4.x == p6.x && p4.y == p6.y ); | |
76 | CPPUNIT_ASSERT( p3 == p5 ); | |
77 | CPPUNIT_ASSERT( p4 == p6 ); | |
78 | CPPUNIT_ASSERT( p3 != p4 ); | |
79 | p5 = p2; p5 += p1; | |
80 | p6 = p2; p6 -= p1; | |
81 | CPPUNIT_ASSERT( p3 == p5 ); | |
82 | CPPUNIT_ASSERT( p4 == p6 ); | |
83 | wxSize s(p1.x,p1.y); | |
84 | p5 = p2; p5 = p2 + s; | |
85 | p6 = p2; p6 = p2 - s; | |
86 | CPPUNIT_ASSERT( p3 == p5 ); | |
87 | CPPUNIT_ASSERT( p4 == p6 ); | |
88 | p5 = p2; p5 += s; | |
89 | p6 = p2; p6 -= s; | |
90 | CPPUNIT_ASSERT( p3 == p5 ); | |
91 | CPPUNIT_ASSERT( p4 == p6 ); | |
92 | } | |
93 | ||
94 | void RealPointTestCase::Operators() | |
95 | { | |
96 | const double EPSILON = 0.00001; | |
97 | wxRealPoint p1(1.2,3.4); | |
98 | wxRealPoint p2(8.7,5.4); | |
99 | wxRealPoint p3(9.9,8.8); | |
100 | wxRealPoint p4(7.5,2.0); | |
101 | wxRealPoint p5 = p2 + p1; | |
102 | wxRealPoint p6 = p2 - p1; | |
103 | /* | |
104 | CPPUNIT_ASSERT( p3 == p5 ); | |
105 | CPPUNIT_ASSERT( p4 == p6 ); | |
106 | CPPUNIT_ASSERT( p3 != p4 ); | |
107 | */ | |
108 | CPPUNIT_ASSERT( fabs( p3.x - p5.x ) < EPSILON && fabs( p3.y - p5.y ) < EPSILON ); | |
109 | CPPUNIT_ASSERT( fabs( p4.x - p6.x ) < EPSILON && fabs( p4.y - p6.y ) < EPSILON ); | |
110 | } |