|
| 1 | +class Building: |
| 2 | + def __init__(self, south, west, width_WE, width_NS, height=10): |
| 3 | + self.south = south |
| 4 | + self.west = west |
| 5 | + self.width_WE = width_WE |
| 6 | + self.width_NS = width_NS |
| 7 | + self.height = height |
| 8 | + |
| 9 | + def corners(self): |
| 10 | + corners = dict() |
| 11 | + corners['north-west']=[self.south+self.width_NS,self.west] |
| 12 | + corners['north-east']=[self.south+self.width_NS,self.west+self.width_WE] |
| 13 | + corners['south-west']=[self.south,self.west] |
| 14 | + corners['south-east']=[self.south,self.west+self.width_WE] |
| 15 | + |
| 16 | + return corners |
| 17 | + |
| 18 | + def area(self): |
| 19 | + return self.width_WE*self.width_NS; |
| 20 | + |
| 21 | + def volume(self): |
| 22 | + return self.width_WE*self.width_NS*self.height |
| 23 | + |
| 24 | + def __repr__(self): |
| 25 | + return "Building({}, {}, {}, {}, {})".format(self.south, self.west, self.width_WE,self.width_NS,self.height) |
| 26 | + |
| 27 | + |
| 28 | +if __name__ == '__main__': |
| 29 | + #These "asserts" using only for self-checking and not necessary for auto-testing |
| 30 | + def json_dict(d): |
| 31 | + return dict((k, list(v)) for k, v in d.items()) |
| 32 | + |
| 33 | + b = Building(1, 2, 2, 3) |
| 34 | + b2 = Building(1, 2, 2, 3, 5) |
| 35 | + assert json_dict(b.corners()) == {'north-east': [4, 4], 'south-east': [1, 4], |
| 36 | + 'south-west': [1, 2], 'north-west': [4, 2]}, "Corners" |
| 37 | + assert b.area() == 6, "Area" |
| 38 | + assert b.volume() == 60, "Volume" |
| 39 | + assert b2.volume() == 30, "Volume2" |
| 40 | + assert str(b) == "Building(1, 2, 2, 3, 10)", "String" |
0 commit comments