prePEP: Money data type

Batista, Facundo FBatista at uniFON.com.ar
Mon Oct 20 17:13:47 EDT 2003


#- > #-
#- > #- class Money(object):
#- > #-     def __init__(self, amount): self.amount = amount
#- > #-     def __add__(self, other):
#- > #-         return self.__class__(self.amount + other)
#- > 
#- > Very good idea, Alex. Any test case that test this?
#- 
#- You mean, as in (method of the appropriate TestCase subclass):
#- 
#-     def testSameclass(self):
#-         class MyMoney(Money): pass
#-         x = MyMoney() + 3
#-         self.assertEquals(type(x), MyMoney)
#- 
#- ???

That's right. There I'm testing if I return a MyMoney type in the __add__. 

I will include a test of this on *each* test method.

Thank you.

.	Facundo





More information about the Python-list mailing list