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.cc66
1 files changed, 66 insertions, 0 deletions
diff --git a/src/tests/testRectangleUtil.cc b/src/tests/testRectangleUtil.cc
new file mode 100644
index 0000000..f10b6af
--- /dev/null
+++ b/src/tests/testRectangleUtil.cc
@@ -0,0 +1,66 @@
1#include "RectangleUtil.hh"
2
3#include <cstdio>
4
5struct Rect {
6
7 int x() const { return m_x; }
8 int y() const { return m_y; }
9 int width() const { return m_width; }
10 int height() const { return m_height; }
11
12 int m_x, m_y, m_width, m_height;
13};
14
15
16
17
18int test_insideBorder() {
19
20 printf("testing RectangleUtil::insideBorder()\n");
21
22 struct _t {
23 struct Rect rect;
24 int x;
25 int y;
26 int bw;
27 int truth;
28 };
29
30 _t tests[] = {
31 { { 0, 0, 10, 10 }, 0, 0, 2, false }, // on the (outer) edge
32 { { 0, 0, 10, 10 }, 1, 1, 2, false }, // on the (inner) edge
33 { { 0, 0, 10, 10 }, 5, 5, 2, true }, // really inside
34 { { 0, 0, 10, 10 }, -5, 0, 2, false }, // somewhere outside
35 { { 0, 0, 10, 10 }, 20, 20, 2, false } // outside for sure
36 };
37
38 int i;
39 for (i = 0; i < sizeof(tests)/sizeof(_t); ++i) {
40 const _t& t = tests[i];
41 int result = RectangleUtil::insideBorder<Rect>(t.rect, t.x, t.y, t.bw);
42
43 printf(" %d: is (%02d|%02d) inside [%d %d]-[%d %d] with border %d: %s, %s\n",
44 i,
45 t.x, t.y,
46 t.rect.x(), t.rect.y(),
47 t.rect.x() + (int)t.rect.width(),
48 t.rect.y() + (int)t.rect.height(),
49 t.bw,
50 result ? "yes" : "no", result == t.truth ? "ok" : "failed");
51 }
52
53 printf("done.\n");
54
55 return 0;
56}
57
58
59
60
61int main(int argc, char **argv) {
62
63 test_insideBorder();
64
65 return 0;
66}