diff options
Diffstat (limited to 'tests/unit_tests/rect_test.coffee')
| -rw-r--r-- | tests/unit_tests/rect_test.coffee | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/tests/unit_tests/rect_test.coffee b/tests/unit_tests/rect_test.coffee index cfb26b05..0773dbcf 100644 --- a/tests/unit_tests/rect_test.coffee +++ b/tests/unit_tests/rect_test.coffee @@ -230,3 +230,59 @@ context "Rect subtraction", if resultComplement.length == 1 complementRect = resultComplement[0] assert.isTrue Rect.contains subtractRect, complementRect + +context "Rect overlaps", + should "detect that a rect overlaps itself", -> + rect = Rect.create 2, 2, 4, 4 + assert.isTrue Rect.rectsOverlap rect, rect + + should "detect that non-overlapping rectangles do not overlap on the left", -> + rect1 = Rect.create 2, 2, 4, 4 + rect2 = Rect.create 0, 2, 1, 4 + assert.isFalse Rect.rectsOverlap rect1, rect2 + + should "detect that non-overlapping rectangles do not overlap on the right", -> + rect1 = Rect.create 2, 2, 4, 4 + rect2 = Rect.create 5, 2, 6, 4 + assert.isFalse Rect.rectsOverlap rect1, rect2 + + should "detect that non-overlapping rectangles do not overlap on the top", -> + rect1 = Rect.create 2, 2, 4, 4 + rect2 = Rect.create 2, 0, 2, 1 + assert.isFalse Rect.rectsOverlap rect1, rect2 + + should "detect that non-overlapping rectangles do not overlap on the bottom", -> + rect1 = Rect.create 2, 2, 4, 4 + rect2 = Rect.create 2, 5, 2, 6 + assert.isFalse Rect.rectsOverlap rect1, rect2 + + should "detect overlapping rectangles on the left", -> + rect1 = Rect.create 2, 2, 4, 4 + rect2 = Rect.create 0, 2, 2, 4 + assert.isTrue Rect.rectsOverlap rect1, rect2 + + should "detect overlapping rectangles on the right", -> + rect1 = Rect.create 2, 2, 4, 4 + rect2 = Rect.create 4, 2, 5, 4 + assert.isTrue Rect.rectsOverlap rect1, rect2 + + should "detect overlapping rectangles on the top", -> + rect1 = Rect.create 2, 2, 4, 4 + rect2 = Rect.create 2, 4, 4, 5 + assert.isTrue Rect.rectsOverlap rect1, rect2 + + should "detect overlapping rectangles on the bottom", -> + rect1 = Rect.create 2, 2, 4, 4 + rect2 = Rect.create 2, 0, 4, 2 + assert.isTrue Rect.rectsOverlap rect1, rect2 + + should "detect overlapping rectangles when second rectangle is contained in first", -> + rect1 = Rect.create 1, 1, 4, 4 + rect2 = Rect.create 2, 2, 3, 3 + assert.isTrue Rect.rectsOverlap rect1, rect2 + + should "detect overlapping rectangles when first rectangle is contained in second", -> + rect1 = Rect.create 1, 1, 4, 4 + rect2 = Rect.create 2, 2, 3, 3 + assert.isTrue Rect.rectsOverlap rect2, rect1 + |
