diff options
author | Mathias Gumz <akira at fluxbox dot org> | 2011-03-19 13:56:45 (GMT) |
---|---|---|
committer | Mathias Gumz <akira at fluxbox dot org> | 2011-03-19 13:56:45 (GMT) |
commit | a798e0e0ffe327b405206a561538e88d1e8db7da (patch) | |
tree | a822c1133de1031cd7c78c32a4926336e98e2b5b /src/tests | |
parent | cea6887f650730da25d72fd1bcaef7d48d5f53e7 (diff) | |
download | fluxbox_pavel-a798e0e0ffe327b405206a561538e88d1e8db7da.zip fluxbox_pavel-a798e0e0ffe327b405206a561538e88d1e8db7da.tar.bz2 |
added RectangleUtil::overlapRectangles() + test cases
Diffstat (limited to 'src/tests')
-rw-r--r-- | src/tests/testRectangleUtil.cc | 55 |
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 | ||
58 | int 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 | ||
61 | int main(int argc, char **argv) { | 115 | int 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 | } |