aboutsummaryrefslogtreecommitdiff
path: root/src/tests/testRectangleUtil.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/tests/testRectangleUtil.cc')
-rw-r--r--src/tests/testRectangleUtil.cc55
1 files changed, 55 insertions, 0 deletions
diff --git a/src/tests/testRectangleUtil.cc b/src/tests/testRectangleUtil.cc
index f10b6af..2da2a4e 100644
--- a/src/tests/testRectangleUtil.cc
+++ b/src/tests/testRectangleUtil.cc
@@ -55,12 +55,67 @@ int test_insideBorder() {
55 return 0; 55 return 0;
56} 56}
57 57
58int test_overlapRectangles() {
58 59
60 printf("testing RectangleUtil::overlapRectangles()\n");
61
62 struct _t {
63 struct Rect a;
64 struct Rect b;
65 int truth;
66 };
67
68 struct _test {
69 bool operator()(const Rect& a, const Rect& b, int truth, int i) {
70
71 int result = RectangleUtil::overlapRectangles(a, b);
72
73 printf(" %d: [%2d %2d]-[%2d %2d] %s [%2d %2d]-[%2d %2d]: %s\n",
74 i,
75 a.x(), a.y(),
76 a.x() + (int)a.width(),
77 a.y() + (int)a.height(),
78 result ? "overlaps" : "does not overlap",
79 b.x(), b.y(),
80 b.x() + (int)b.width(),
81 b.y() + (int)b.height(),
82 result == truth ? "ok" : "failed");
83 return result == truth;
84 }
85 };
86
87 const _t tests[] = {
88
89 { { 0, 0, 8, 8 }, { 0, 0, 8, 8 }, true }, // b equals a
90 { { 0, 0, 8, 8 }, { 3, 3, 3, 3 }, true }, // b completely inside a
91 { { 0, 0, 8, 8 }, { 4, 4, 8, 8 }, true }, // b overlaps a in one corner
92 { { 0, 0, 8, 8 }, { 4,-1, 2, 9 }, true }, // b overlaps a in the middle
93
94 { { 0, 0, 8, 8 }, { -8, 0, 5, 8 }, false }, // b completely left from a
95 { { 0, 0, 8, 8 }, { 9, 0, 5, 8 }, false }, // b completely right from a
96 { { 0, 0, 8, 8 }, { 0,-9, 5, 8 }, false }, // b completely down below a
97 { { 0, 0, 8, 8 }, { 0, 9, 5, 8 }, false }, // b completely up above a
98 };
99
100
101
102 _test test;
103 int i;
104 for (i = 0; i < sizeof(tests)/sizeof(_t); ++i) {
105 test(tests[i].a, tests[i].b, tests[i].truth, i);
106 test(tests[i].b, tests[i].a, tests[i].truth, i);
107 }
108
109 printf("done.\n");
110
111 return 0;
112}
59 113
60 114
61int main(int argc, char **argv) { 115int main(int argc, char **argv) {
62 116
63 test_insideBorder(); 117 test_insideBorder();
118 test_overlapRectangles();
64 119
65 return 0; 120 return 0;
66} 121}