]>
git.saurik.com Git - wxWidgets.git/blob - tests/geometry/point.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/geometry/point.cpp
3 // Purpose: wxPoint unit test
4 // Author: Wlodzimierz ABX Skiba
6 // Copyright: (c) 2004 wxWindows
7 ///////////////////////////////////////////////////////////////////////////////
9 // ----------------------------------------------------------------------------
11 // ----------------------------------------------------------------------------
20 #include "wx/gdicmn.h"
25 // ----------------------------------------------------------------------------
27 // ----------------------------------------------------------------------------
29 class PointTestCase
: public CppUnit::TestCase
35 CPPUNIT_TEST_SUITE( PointTestCase
);
36 CPPUNIT_TEST( Operators
);
37 CPPUNIT_TEST_SUITE_END();
41 DECLARE_NO_COPY_CLASS(PointTestCase
)
44 class RealPointTestCase
: public CppUnit::TestCase
47 RealPointTestCase() { }
50 CPPUNIT_TEST_SUITE( RealPointTestCase
);
51 CPPUNIT_TEST( Operators
);
52 CPPUNIT_TEST_SUITE_END();
56 DECLARE_NO_COPY_CLASS(RealPointTestCase
)
59 // register in the unnamed registry so that these tests are run by default
60 CPPUNIT_TEST_SUITE_REGISTRATION( PointTestCase
);
61 CPPUNIT_TEST_SUITE_REGISTRATION( RealPointTestCase
);
63 // also include in its own registry so that these tests can be run alone
64 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( PointTestCase
, "PointTestCase" );
65 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( RealPointTestCase
, "RealPointTestCase" );
67 void PointTestCase::Operators()
75 CPPUNIT_ASSERT( p3
.x
== p5
.x
&& p3
.y
== p5
.y
);
76 CPPUNIT_ASSERT( p4
.x
== p6
.x
&& p4
.y
== p6
.y
);
77 CPPUNIT_ASSERT( p3
== p5
);
78 CPPUNIT_ASSERT( p4
== p6
);
79 CPPUNIT_ASSERT( p3
!= p4
);
82 CPPUNIT_ASSERT( p3
== p5
);
83 CPPUNIT_ASSERT( p4
== p6
);
87 CPPUNIT_ASSERT( p3
== p5
);
88 CPPUNIT_ASSERT( p4
== p6
);
91 CPPUNIT_ASSERT( p3
== p5
);
92 CPPUNIT_ASSERT( p4
== -p6
);
95 CPPUNIT_ASSERT( p3
== p5
);
96 CPPUNIT_ASSERT( p4
== p6
);
99 void RealPointTestCase::Operators()
101 const double EPSILON
= 0.00001;
102 wxRealPoint
p1(1.2,3.4);
103 wxRealPoint
p2(8.7,5.4);
104 wxRealPoint
p3(9.9,8.8);
105 wxRealPoint
p4(7.5,2.0);
106 wxRealPoint p5
= p2
+ p1
;
107 wxRealPoint p6
= p2
- p1
;
109 CPPUNIT_ASSERT( p3 == p5 );
110 CPPUNIT_ASSERT( p4 == p6 );
111 CPPUNIT_ASSERT( p3 != p4 );
113 CPPUNIT_ASSERT( fabs( p3
.x
- p5
.x
) < EPSILON
&& fabs( p3
.y
- p5
.y
) < EPSILON
);
114 CPPUNIT_ASSERT( fabs( p4
.x
- p6
.x
) < EPSILON
&& fabs( p4
.y
- p6
.y
) < EPSILON
);