Passed
Push — master ( 3eb980...a5aa16 )
by Ken M.
01:11
created

building_base.Building.__repr__()   A

Complexity

Conditions 1

Size

Total Lines 3
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
__author__ = 'KenMercusLai'
2
3
4
class Building:
5
    def __init__(self, south, west, width_WE, width_NS, height=10):
6
        self.south = south
7
        self.west = west
8
        self.WE = width_WE
9
        self.NS = width_NS
10
        self.height = height
11
12
    def corners(self):
13
        return {
14
            "north-west": [self.south + self.NS, self.west],
15
            "north-east": [self.south + self.NS, self.west + self.WE],
16
            "south-west": [self.south, self.west],
17
            "south-east": [self.south, self.west + self.WE],
18
        }
19
20
    def area(self):
21
        return self.NS * self.WE
22
23
    def volume(self):
24
        return self.NS * self.WE * self.height
25
26
    def __repr__(self):
27
        return 'Building({}, {}, {}, {}, {})'.format(
28
            self.south, self.west, self.WE, self.NS, self.height
29
        )
30
31
32
if __name__ == '__main__':  # pragma: no cover
33
    # These "asserts" using only for self-checking and not necessary for
34
    # auto-testing
35
    def json_dict(d):
36
        return dict((k, list(v)) for k, v in d.items())
37
38
    b = Building(1, 2, 2, 3)
39
    b2 = Building(1, 2, 2, 3, 5)
40
    assert json_dict(b.corners()) == {
41
        'north-east': [4, 4],
42
        'south-east': [1, 4],
43
        'south-west': [1, 2],
44
        'north-west': [4, 2],
45
    }, "Corners"
46
    assert b.area() == 6, "Area"
47
    assert b.volume() == 60, "Volume"
48
    assert b2.volume() == 30, "Volume2"
49
    assert str(b) == "Building(1, 2, 2, 3, 10)", "String"
50