File tree Expand file tree Collapse file tree 2 files changed +20
-14
lines changed
Students/imdavis/session07 Expand file tree Collapse file tree 2 files changed +20
-14
lines changed Original file line number Diff line number Diff line change @@ -16,22 +16,28 @@ def radius(self):
1616
1717 @radius .setter
1818 def radius (self , radius ):
19- assert radius > 0 , "radius must be nonzero and non-negative"
20- self .__radius = radius
19+ if radius <= 0 :
20+ raise ValueError ("radius must be nonzero and non-negative" )
21+ else :
22+ self .__radius = radius
2123
2224 @classmethod
2325 def from_diameter (cls , diameter ):
24- assert diameter > 0 , "diameter must be nonzero and non-negative"
25- return cls (diameter / 2.0 )
26+ if diameter <= 0 :
27+ raise ValueError ("diameter must be nonzero and non-negative" )
28+ else :
29+ return cls (diameter / 2.0 )
2630
2731 @property
2832 def diameter (self ):
2933 return self .radius * 2.0
3034
3135 @diameter .setter
3236 def diameter (self , value ):
33- assert value > 0 , "diameter must be nonzero and non-negative"
34- self .radius = value / 2.0
37+ if value <= 0 :
38+ raise ValueError ("diameter must be nonzero and non-negative" )
39+ else :
40+ self .radius = value / 2.0
3541
3642 @property
3743 def area (self ):
Original file line number Diff line number Diff line change @@ -123,27 +123,27 @@ def test_nonsense_radius():
123123 Make sure we can't create a Circle object with a negative or zero
124124 radius.
125125 """
126- with pytest .raises (AssertionError ):
126+ with pytest .raises (ValueError ):
127127 c = Circle (- 1.234 )
128- with pytest .raises (AssertionError ):
128+ with pytest .raises (ValueError ):
129129 c = Circle (0 )
130130 c = Circle (1.234 )
131- with pytest .raises (AssertionError ):
131+ with pytest .raises (ValueError ):
132132 c .radius = - 1.234
133- with pytest .raises (AssertionError ):
133+ with pytest .raises (ValueError ):
134134 c .radius = 0
135135
136136def test_nonsense_diameter ():
137137 """
138138 Make sure we can't create a Circle object with a negative or zero
139139 diameter.
140140 """
141- with pytest .raises (AssertionError ):
141+ with pytest .raises (ValueError ):
142142 c = Circle .from_diameter (- 2.468 )
143- with pytest .raises (AssertionError ):
143+ with pytest .raises (ValueError ):
144144 c = Circle .from_diameter (0 )
145145 c = Circle .from_diameter (2.468 )
146- with pytest .raises (AssertionError ):
146+ with pytest .raises (ValueError ):
147147 c .diameter = - 2.468
148- with pytest .raises (AssertionError ):
148+ with pytest .raises (ValueError ):
149149 c .diameter = 0
You can’t perform that action at this time.
0 commit comments