-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_circle.py
More file actions
78 lines (61 loc) · 1.41 KB
/
test_circle.py
File metadata and controls
78 lines (61 loc) · 1.41 KB
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
#!/usr/bin/env python
"""
code that tests the circle class defined in circle.py
When run, should result in:
the radius: 4
the diameter: 8
the area: 50.2654824574
the repr(): Circle(4.000000)
the str(): Circle Object with radius: 4.000000
setting the radius to 2:
the radius: 2
the diameter: 4
the area: 12.5663706144
setting the diameter to 6:
the radius: 3.0
the diameter: 6.0
the area: 28.2743338823
trying to delete the diameter
Whoops: can't delete attribute
trying to set the area
Whoops: can't set attribute
adding two circles together
Circle Object with radius: 6.000000
"""
from circle import Circle
print "creating a Circle with radius 4"
c = Circle(4)
print "the radius:", c.radius
print "the diameter:", c.diameter
print "the area:", c.area
print "the repr():", repr(c)
print "the str():", str(c)
print
print "setting the radius to 2:"
c.radius = 2
print "the radius:", c.radius
print "the diameter:", c.diameter
print "the area:", c.area
print
print "setting the diameter to 6:"
c.diameter = 6
print "the radius:", c.radius
print "the diameter:", c.diameter
print "the area:", c.area
print
print "trying to delete the diameter"
try:
del c.diameter
except Exception as err:
print "Whoops:", err
print
print "trying to set the area"
try:
c.area = 40.0
except Exception as err:
print "Whoops:", err
c1 = Circle(2)
c2 = Circle(4)
print
print "adding two circles together"
print c1 + c2