forked from UWPCE-PythonCert/IntroToPython-2014
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_circle2.py
More file actions
124 lines (73 loc) · 1.7 KB
/
test_circle2.py
File metadata and controls
124 lines (73 loc) · 1.7 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/usr/bin/env python
"""code that tests the circle class defined in circle.py
This version adds more tests
can be run with py.test
"""
import math
import pytest # used for the exception testing
from circle import Circle
def test_create():
c = Circle(4)
assert c.radius == 4
def test_change_radius():
c = Circle(3)
c.radius = 4
assert c.radius == 4
def test_diameter():
c = Circle(4)
assert c.diameter == 8
def test_change_diameter():
c = Circle(2)
assert c.radius == 2
assert c.diameter == 4
c.diameter = 6
assert c.radius == 3
assert c.diameter == 6
def test_area():
c = Circle(4)
assert c.area == math.pi*16
def test_set_area():
c = Circle(4)
with pytest.raises(AttributeError):
c.area = 44
## the extra credit: classmethod:
# def test_alternate_constructor():
# c = Circle.from_diameter(8)
# assert c.diameter == 8
# assert c.radius == 4
## the magic methods:
def test_str():
c = Circle(3)
assert str(c) == 'Circle with radius: 3.000000'
def test_repr():
c = Circle(3)
assert repr(c) == 'Circle(3)'
def test_addition():
c1 = Circle(2)
c2 = Circle(3)
c3 = c1 + c2
assert c3.radius == 5
def test_multiplication():
c1 = Circle(2)
c3 = c1 * 4
assert c3.radius == 8
def test_equal():
c1 = Circle(3)
c2 = Circle(3.0)
assert c1 == c2
assert c1 <= c2
assert c1 >= c2
def test_not_equal():
c1 = Circle(2.9)
c2 = Circle(3.0)
assert c1 != c2
def test_greater():
c1 = Circle(2)
c2 = Circle(3)
assert c2 > c1
assert c2 >= c1
def test_less():
c1 = Circle(2)
c2 = Circle(3)
assert c1 < c2
assert c1 <= c2