[Edu-sig] a Circle type with radius, area both properties (fixed)
kirby urner
kirby.urner at gmail.com
Fri Oct 21 15:37:10 EDT 2016
>
>
>> Uh oh... I'm in the middle of teaching Session 10
>> and couldn't figure out why my radius for a smaller
>> area was bigger. Couldn't be. I did my algebra
>> wrong, duh.
>>
>
>
> https://docs.python.org/2/library/unittest.html
>
> if __name__ == "__main__":
> # import unittest
> unittest.main()
>
>
>
Yeah, seriously good advice.
I've added unittests to the latest version, which I'll push to Github when
the site once again becomes available.
http://gizmodo.com/this-is-probably-why-half-the-internet-shut-down-today-1788062835
Kirby
class TestCircle(unittest.TestCase):
def testArea(self):
the_circle = Circle(1)
self.assertEqual(the_circle.area, math.pi, "Uh oh")
def testRadius(self):
the_circle = Circle(1)
the_circle.area = math.pi * 4 # power rule
self.assertEqual(the_circle.radius, 2, "Uh oh")
a = TestCircle() # the test suite
suite = unittest.TestLoader().loadTestsFromModule(a)
unittest.TextTestRunner().run(suite) # run the test suite
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/edu-sig/attachments/20161021/16d7da9c/attachment.html>
More information about the Edu-sig
mailing list