diff options
author | Max Horn | 2009-04-09 17:07:00 +0000 |
---|---|---|
committer | Max Horn | 2009-04-09 17:07:00 +0000 |
commit | da90b7e015970e30b8e95893b9f7745cf6a48176 (patch) | |
tree | 402f18bf4f453e53941b549613c07e79513c45db | |
parent | d3d641e4874344788d35fbb387c011672f4ea050 (diff) | |
download | scummvm-rg350-da90b7e015970e30b8e95893b9f7745cf6a48176.tar.gz scummvm-rg350-da90b7e015970e30b8e95893b9f7745cf6a48176.tar.bz2 scummvm-rg350-da90b7e015970e30b8e95893b9f7745cf6a48176.zip |
Patch #2735283: GSOC09: A few unit tests for Common::Rect
svn-id: r39907
-rw-r--r-- | test/common/rect.h | 48 |
1 files changed, 48 insertions, 0 deletions
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 <cxxtest/TestSuite.h> + +#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); + } + +}; |