| 1 | #include <cxxtest/TestSuite.h> |
| 2 | |
| 3 | #include "common/rect.h" |
| 4 | |
| 5 | class RectTestSuite : public CxxTest::TestSuite |
| 6 | { |
| 7 | public: |
| 8 | void test_point_sqrDist( void ) |
| 9 | { |
| 10 | Common::Point p0; |
| 11 | Common::Point p11(1, 1); |
| 12 | Common::Point p21(2, 1); |
| 13 | Common::Point p23(2, 3); |
| 14 | Common::Point p32(3, 2); |
| 15 | TS_ASSERT_EQUALS( p0.sqrDist(p11), (uint) 2 ); |
| 16 | TS_ASSERT_EQUALS( p0.sqrDist(p21), (uint) 5 ); |
| 17 | TS_ASSERT_EQUALS( p0.sqrDist(p23), p0.sqrDist(p32) ); |
| 18 | TS_ASSERT_EQUALS( p11.sqrDist(p11), (uint) 0 ); |
| 19 | TS_ASSERT_EQUALS( p11.sqrDist(p23), (uint) 5 ); |
| 20 | } |
| 21 | |
| 22 | void test_intersects( void ) |
| 23 | { |
| 24 | TS_ASSERT( Common::Rect(0, 0, 2, 2).intersects(Common::Rect(0, 0, 1, 1)) ); |
| 25 | TS_ASSERT( Common::Rect(0, 0, 2, 2).intersects(Common::Rect(1, 1, 2, 2)) ); |
| 26 | TS_ASSERT( !Common::Rect(0, 0, 1, 1).intersects(Common::Rect(1, 1, 2, 2)) ); |
| 27 | } |
| 28 | |
| 29 | void test_extend( void ) |
| 30 | { |
| 31 | Common::Rect r0; |
| 32 | Common::Rect r1(0, 0, 1, 1); |
| 33 | Common::Rect r2(0, 0, 2, 2); |
| 34 | TS_ASSERT( !r0.contains(r1) ); |
| 35 | r0.extend(r1); |
| 36 | // TS_ASSERT( r0.contains(r1) ); |
| 37 | TS_ASSERT_EQUALS(r0.top, 0); |
| 38 | TS_ASSERT_EQUALS(r0.left, 0); |
| 39 | TS_ASSERT_EQUALS(r0.bottom, 1); |
| 40 | TS_ASSERT_EQUALS(r0.right, 1); |
| 41 | r2.extend(r1); |
| 42 | TS_ASSERT_EQUALS(r2.top, 0); |
| 43 | TS_ASSERT_EQUALS(r2.left, 0); |
| 44 | TS_ASSERT_EQUALS(r2.bottom, 2); |
| 45 | TS_ASSERT_EQUALS(r2.right, 2); |
| 46 | } |
| 47 | |
| 48 | }; |