Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Message from discussion ten small Python programs

View parsed - Show only message text

Path: g2news1.google.com!news1.google.com!news2.google.com!news.glorb.com!newsgate.cistron.nl!xs4all!transit3.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path: <showel...@yahoo.com>
X-Original-To: python-l...@python.org
Delivered-To: python-l...@bag.python.org
X-Spam-Status: OK 0.022
X-YMail-OSG: PikT21kVM1mN77OINorlg76widYdRz5RQ26SdZ7.Q0bI7czRRz7xonPZUxpeM2yY9IS6V5ZzOYQs1kKjqBugSUGJ9_AQ54xamLQGxNeF4dECYQgBBspnTwWRe74Umw--
Date: Sun, 27 May 2007 11:10:52 -0700 (PDT)
From: Steve Howell <showel...@yahoo.com>
Subject: Re: ten small Python programs
To: Steven Bethard <steven.beth...@gmail.com>, python-l...@python.org
In-Reply-To: <I4OdnWQN3OqCJsTbnZ2dnUVZ_qiqnZ2d@comcast.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8bit
X-BeenThere: python-l...@python.org
X-Mailman-Version: 2.1.9
Precedence: list
List-Id: General discussion list for the Python programming language
	<python-list.python.org>
List-Unsubscribe: <http://mail.python.org/mailman/listinfo/python-list>,
	<mailto:python-list-requ...@python.org?subject=unsubscribe>
List-Archive: <http://mail.python.org/pipermail/python-list>
List-Post: <mailto:python-l...@python.org>
List-Help: <mailto:python-list-requ...@python.org?subject=help>
List-Subscribe: <http://mail.python.org/mailman/listinfo/python-list>,
	<mailto:python-list-requ...@python.org?subject=subscribe>
Newsgroups: comp.lang.python
Message-ID: <mailman.8269.1180289458.32031.python-list@python.org>
Lines: 37
NNTP-Posting-Host: 194.109.207.14
X-Trace: 1180289458 news.xs4all.nl 326 [::ffff:194.109.207.14]:44853
X-Complaints-To: abuse@xs4all.nl


--- 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+kids&cs=bz 

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