]> git.saurik.com Git - wxWidgets.git/blob - tests/geometry/point.cpp
32b46c7700d43d918435c70dd30b2b35f5b80cfb
[wxWidgets.git] / tests / geometry / point.cpp
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 #include "wx/math.h"
25
26 // ----------------------------------------------------------------------------
27 // test class
28 // ----------------------------------------------------------------------------
29
30 class PointTestCase : public CppUnit::TestCase
31 {
32 public:
33 PointTestCase() { }
34
35 private:
36 CPPUNIT_TEST_SUITE( PointTestCase );
37 CPPUNIT_TEST( Operators );
38 CPPUNIT_TEST_SUITE_END();
39
40 void Operators();
41
42 DECLARE_NO_COPY_CLASS(PointTestCase)
43 };
44
45 class RealPointTestCase : public CppUnit::TestCase
46 {
47 public:
48 RealPointTestCase() { }
49
50 private:
51 CPPUNIT_TEST_SUITE( RealPointTestCase );
52 CPPUNIT_TEST( Operators );
53 CPPUNIT_TEST_SUITE_END();
54
55 void Operators();
56
57 DECLARE_NO_COPY_CLASS(RealPointTestCase)
58 };
59
60 // register in the unnamed registry so that these tests are run by default
61 CPPUNIT_TEST_SUITE_REGISTRATION( PointTestCase );
62 CPPUNIT_TEST_SUITE_REGISTRATION( RealPointTestCase );
63
64 // also include in its own registry so that these tests can be run alone
65 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( PointTestCase, "PointTestCase" );
66 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( RealPointTestCase, "RealPointTestCase" );
67
68 void PointTestCase::Operators()
69 {
70 wxPoint p1(1,2);
71 wxPoint p2(6,3);
72 wxPoint p3(7,5);
73 wxPoint p4(5,1);
74 wxPoint p5 = p2 + p1;
75 wxPoint p6 = p2 - p1;
76 CPPUNIT_ASSERT( p3.x == p5.x && p3.y == p5.y );
77 CPPUNIT_ASSERT( p4.x == p6.x && p4.y == p6.y );
78 CPPUNIT_ASSERT( p3 == p5 );
79 CPPUNIT_ASSERT( p4 == p6 );
80 CPPUNIT_ASSERT( p3 != p4 );
81 p5 = p2; p5 += p1;
82 p6 = p2; p6 -= p1;
83 CPPUNIT_ASSERT( p3 == p5 );
84 CPPUNIT_ASSERT( p4 == p6 );
85 wxSize s(p1.x,p1.y);
86 p5 = p2; p5 = p2 + s;
87 p6 = p2; p6 = p2 - s;
88 CPPUNIT_ASSERT( p3 == p5 );
89 CPPUNIT_ASSERT( p4 == p6 );
90 p5 = p2; p5 = s + p2;
91 p6 = p2; p6 = s - p2;
92 CPPUNIT_ASSERT( p3 == p5 );
93 CPPUNIT_ASSERT( p4 == -p6 );
94 p5 = p2; p5 += s;
95 p6 = p2; p6 -= s;
96 CPPUNIT_ASSERT( p3 == p5 );
97 CPPUNIT_ASSERT( p4 == p6 );
98 }
99
100 void RealPointTestCase::Operators()
101 {
102 const double EPSILON = 0.00001;
103 wxRealPoint p1(1.2,3.4);
104 wxRealPoint p2(8.7,5.4);
105 wxRealPoint p3(9.9,8.8);
106 wxRealPoint p4(7.5,2.0);
107 wxRealPoint p5 = p2 + p1;
108 wxRealPoint p6 = p2 - p1;
109 /*
110 CPPUNIT_ASSERT( p3 == p5 );
111 CPPUNIT_ASSERT( p4 == p6 );
112 CPPUNIT_ASSERT( p3 != p4 );
113 */
114 CPPUNIT_ASSERT( fabs( p3.x - p5.x ) < EPSILON && fabs( p3.y - p5.y ) < EPSILON );
115 CPPUNIT_ASSERT( fabs( p4.x - p6.x ) < EPSILON && fabs( p4.y - p6.y ) < EPSILON );
116 }