-
Notifications
You must be signed in to change notification settings - Fork 0
/
RectangleUnitTest.py
101 lines (59 loc) · 4 KB
/
RectangleUnitTest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import unittest
from classes.rectangle import Rectangle
from classes.coordinate import Coordinate
class TestContain(unittest.TestCase):
'''
Unit Testing Package for Rectangle-Problem
'''
def testContainOne(self):
#One rectangle contains another
rectangleOne = Rectangle(Coordinate(1, 5), Coordinate(7, 5), Coordinate(1, 1), Coordinate(7, 1))
rectangleTwo = Rectangle(Coordinate(2,4), Coordinate(5, 4), Coordinate(2, 2), Coordinate(5, 2))
result = rectangleTwo.rectangleContains(rectangleOne)
self.assertEquals(result, True, "True")
def testContainTwo(self):
#Rectangles contain each other
rectangleOne = Rectangle(Coordinate(1, 5), Coordinate(7, 5), Coordinate(1, 1), Coordinate(7, 1))
rectangleTwo = Rectangle(Coordinate(1,5), Coordinate(7, 5), Coordinate(1, 1), Coordinate(7, 1))
resultOne = rectangleTwo.rectangleContains(rectangleOne)
resultTwo= rectangleOne.rectangleContains(rectangleTwo)
result = resultOne or resultTwo
self.assertEquals(result, True, "True")
def testContainThree(self):
#Rectangles are seperate
rectangleOne = Rectangle(Coordinate(1, 5), Coordinate(7, 5), Coordinate(1, 1), Coordinate(7, 1))
rectangleTwo = Rectangle(Coordinate(1,8), Coordinate(4, 8), Coordinate(1, 6), Coordinate(4, 6))
resultOne = rectangleTwo.rectangleContains(rectangleOne)
resultTwo= rectangleOne.rectangleContains(rectangleTwo)
result = resultOne or resultTwo
self.assertEquals(result, False, "False")
def intersectTestOne(self):
#Rectangles intersect
rectangleOne = Rectangle(Coordinate(2, 4), Coordinate(5, 4), Coordinate(2, 2), Coordinate(5, 2))
rectangleTwo = Rectangle(Coordinate(3, 5), Coordinate(4, 5), Coordinate(3, 3), Coordinate(4, 3))
result = rectangleOne.rectangleIntersects(rectangleTwo)
self.assertEquals(result, True, "True")
def intersectTestTwo(self):
#Rectangles are seperate
rectangleOne = Rectangle(Coordinate(1, 5), Coordinate(7, 5), Coordinate(1, 1), Coordinate(7, 1))
rectangleTwo = Rectangle(Coordinate(1,8), Coordinate(4, 8), Coordinate(1, 6), Coordinate(4, 6))
result = rectangleOne.rectangleIntersects(rectangleTwo)
self.assertEquals(result, False, "False")
def AdjacencyTestOne(self):
#Rectangles are adjacent on the x-axis
rectangleOne = Rectangle(Coordinate(1, 4), Coordinate(3, 4), Coordinate(1, 2), Coordinate(3, 2))
rectangleTwo = Rectangle(Coordinate(3, 4), Coordinate(5, 4), Coordinate(3, 2), Coordinate(5, 2))
result = rectangleOne.rectangleAdjacent(rectangleTwo) or rectangleTwo.rectangleAdjacent(rectangleOne)
self.assertEquals(result, True, "True")
def AdjacencyTestTwo(self):
#Rectangles are adjacent on the y-axis
rectangleOne = Rectangle(Coordinate(1, 3), Coordinate(3, 3), Coordinate(1, 1), Coordinate(3, 1))
rectangleTwo = Rectangle(Coordinate(1, 5), Coordinate(3, 5), Coordinate(1, 3), Coordinate(3, 3))
result = rectangleOne.rectangleAdjacent(rectangleTwo) or rectangleTwo.rectangleAdjacent(rectangleOne)
self.assertEquals(result, True, "True")
def AdjacenyTestThree(self):
#Rectangles are seperate
rectangleOne = Rectangle(Coordinate(1, 5), Coordinate(7, 5), Coordinate(1, 1), Coordinate(7, 1))
rectangleTwo = Rectangle(Coordinate(1,8), Coordinate(4, 8), Coordinate(1, 6), Coordinate(4, 6))
result = rectangleOne.rectangleIntersects(rectangleTwo)
self.assertEquals(result, False, "False")