Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Message from discussion ten small Python programs
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Steve Howell  
View profile  
 More options May 28 2007, 4:10 am
Newsgroups: comp.lang.python
From: Steve Howell <showel...@yahoo.com>
Date: Sun, 27 May 2007 11:10:52 -0700 (PDT)
Local: Mon, May 28 2007 4:10 am
Subject: Re: ten small Python programs

--- Steven Bethard <steven.beth...@gmail.com> 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...


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google