From da90b7e015970e30b8e95893b9f7745cf6a48176 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Thu, 9 Apr 2009 17:07:00 +0000 Subject: Patch #2735283: GSOC09: A few unit tests for Common::Rect svn-id: r39907 --- test/common/rect.h | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 test/common/rect.h (limited to 'test/common') diff --git a/test/common/rect.h b/test/common/rect.h new file mode 100644 index 0000000000..07353f7aea --- /dev/null +++ b/test/common/rect.h @@ -0,0 +1,48 @@ +#include + +#include "common/rect.h" + +class RectTestSuite : public CxxTest::TestSuite +{ + public: + void test_point_sqrDist( void ) + { + Common::Point p0; + Common::Point p11(1, 1); + Common::Point p21(2, 1); + Common::Point p23(2, 3); + Common::Point p32(3, 2); + TS_ASSERT_EQUALS( p0.sqrDist(p11), (uint) 2 ); + TS_ASSERT_EQUALS( p0.sqrDist(p21), (uint) 5 ); + TS_ASSERT_EQUALS( p0.sqrDist(p23), p0.sqrDist(p32) ); + TS_ASSERT_EQUALS( p11.sqrDist(p11), (uint) 0 ); + TS_ASSERT_EQUALS( p11.sqrDist(p23), (uint) 5 ); + } + + void test_intersects( void ) + { + TS_ASSERT( Common::Rect(0, 0, 2, 2).intersects(Common::Rect(0, 0, 1, 1)) ); + TS_ASSERT( Common::Rect(0, 0, 2, 2).intersects(Common::Rect(1, 1, 2, 2)) ); + TS_ASSERT( !Common::Rect(0, 0, 1, 1).intersects(Common::Rect(1, 1, 2, 2)) ); + } + + void test_extend( void ) + { + Common::Rect r0; + Common::Rect r1(0, 0, 1, 1); + Common::Rect r2(0, 0, 2, 2); + TS_ASSERT( !r0.contains(r1) ); + r0.extend(r1); +// TS_ASSERT( r0.contains(r1) ); + TS_ASSERT_EQUALS(r0.top, 0); + TS_ASSERT_EQUALS(r0.left, 0); + TS_ASSERT_EQUALS(r0.bottom, 1); + TS_ASSERT_EQUALS(r0.right, 1); + r2.extend(r1); + TS_ASSERT_EQUALS(r2.top, 0); + TS_ASSERT_EQUALS(r2.left, 0); + TS_ASSERT_EQUALS(r2.bottom, 2); + TS_ASSERT_EQUALS(r2.right, 2); + } + +}; -- cgit v1.2.3