第3章
"""
テスト駆動開発入門3章
"""
import unittest
class TestMoney(unittest.TestCase):
def testMultiplication(self):
five = Dollar(5)
product = five.times(2)
self.assertEqual(10, product.amount)
product = five.times(3)
self.assertEqual(15, product.amount)
def testEuality(self):
self.assert_(Dollar(5).equals(Dollar(5) ) )
self.assert_(not Dollar(5).equals(Dollar(6) ) )
class Dollar(object):
amount = 0
def __init__(self, amount):
self.amount = amount
def times(self, multiplier):
return Dollar(self.amount * multiplier)
def equals(self, object):
dollar = object
return self.amount == dollar.amount
if __name__ == "__main__":
unittest.main()