--- Steven Bethard <[EMAIL PROTECTED]> wrote:
> 
> I think I would rewrite the current unit-testing
> example to use the 
> standard library unittest module::
> 
>      # Let's write reusable code, and unit test it.
>      def add_money(amounts):
>          # do arithmetic in pennies so as not to
> accumulate float errors
>          pennies = sum([round(int(amount * 100)) for
> amount in amounts])
>          return float(pennies / 100.0)
>      import unittest
>      class TestAddMoney(unittest.TestCase):
>          def test_float_errors(self):
>              self.failUnlessEqual(add_money([0.13,
> 0.02]), 0.15)
>              self.failUnlessEqual(add_money([100.01,
> 99.99]), 200)
>              self.failUnlessEqual(add_money([0,
> -13.00, 13.00]), 0)
>      if __name__ == '__main__':
>          unittest.main()
> 

Just a minor quibble, but wouldn't you want the import
and test class to only get executed in the ___main__
context?



       
____________________________________________________________________________________Got
 a little couch potato? 
Check out fun summer activities for kids.
http://search.yahoo.com/search?fr=oni_on_mail&p=summer+activities+for+kids&cs=bz
 
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to