forked from UWPCE-PythonCert/IntroToPython-2014
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_circle1.py
More file actions
67 lines (38 loc) · 963 Bytes
/
test_circle1.py
File metadata and controls
67 lines (38 loc) · 963 Bytes
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
#!/usr/bin/env python
"""
code that tests the circle class defined in circle.py
can be run with py.test
"""
import pytest # used for the exception testing
import math
from circle import Circle
#from circle_solution1 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