comparison tests/core_tests/test_rect.cpp @ 44:5a2db5e7ab54

renamed unittest++ based tests as they were with boost
author jasoka@33b003aa-7bff-0310-803a-e67f0ece8222
date Sun, 13 Jul 2008 07:52:58 +0000
parents tests/core_tests/test_rect++.cpp@4c8334b0ab30
children 8c073dd2d3a3
comparison
equal deleted inserted replaced
43:6daa907234e1 44:5a2db5e7ab54
1 /***************************************************************************
2 * Copyright (C) 2005-2008 by the FIFE team *
3 * http://www.fifengine.de *
4 * This file is part of FIFE. *
5 * *
6 * FIFE is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the *
18 * Free Software Foundation, Inc., *
19 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *
20 ***************************************************************************/
21
22 // Standard C++ library includes
23 #include <ctime>
24 #include <vector>
25
26 // Platform specific includes
27 #include "fife_unittest++.h"
28
29 // 3rd party library includes
30
31 // FIFE includes
32 // These includes are split up in two parts, separated by one empty line
33 // First block: files included from the FIFE root src directory
34 // Second block: files included from the same folder
35 #include "util/structures/rect.h"
36
37 using namespace FIFE;
38
39 TEST(rectangle_interesection)
40 {
41 Rect a(0,0,10,10);
42
43 std::vector<Rect> do_intersect;
44 #define ADD_RECT(x,y,w,h) do_intersect.push_back( Rect(x,y,w,h) )
45
46 ADD_RECT(5,5,10,10);
47 ADD_RECT(-5,5,10,10);
48 ADD_RECT(-5,-5,10,10);
49 ADD_RECT(5,-5,10,10);
50
51 ADD_RECT(-5,5,20,1);
52 ADD_RECT(-5,5,10,1);
53
54 ADD_RECT(5,-5,1,20);
55 ADD_RECT(5,-5,1,10);
56
57 ADD_RECT(5,5,3,3);
58
59 ADD_RECT(-5,-5,30,30);
60
61 for(size_t i=0; i<do_intersect.size(); ++i) {
62 CHECK(a.intersects(do_intersect[i]));
63 CHECK(do_intersect[i].intersects(a));
64 }
65
66 std::vector<Rect> dont_intersect;
67
68 #undef ADD_RECT
69 #define ADD_RECT(x,y,w,h) dont_intersect.push_back( Rect(x,y,w,h) )
70
71 ADD_RECT(-5,-5,4,4);
72 ADD_RECT(-5,-5,40,4);
73 ADD_RECT(-5,-5,4,40);
74 ADD_RECT(-5,-5,4,4);
75
76 ADD_RECT(15,15,4,4);
77 ADD_RECT(15,15,40,4);
78 ADD_RECT(15,15,4,40);
79
80 for(size_t i=0; i<dont_intersect.size(); ++i) {
81 CHECK(!a.intersects(dont_intersect[i]));
82 CHECK(!dont_intersect[i].intersects(a));
83 }
84 }
85
86 int main() {
87 return UnitTest::RunAllTests();
88 }