def test_mixed_addition(): five_dollars = Money.dollar(5) ten_francs = Money.franc(10) bank = Bank() bank.add_rate("CHF", "USD", 2) result = bank.reduce(five_dollars + ten_francs, "USD") assert result == Money.dollar(10)
def test_mixed_addition(self): five_bucks = Money.dollar(5) ten_francs = Money.franc(10) bank = Bank() bank.add_rate('CHF', 'USD', 2) result = bank.reduce(five_bucks.plus(ten_francs), 'USD') self.assertTrue(result.equals(Money.dollar(10)))
def test_sum_times(): five_dollars = Money.dollar(5) ten_francs = Money.franc(10) bank = Bank() bank.add_rate("CHF", "USD", 2) sum_ = Sum(five_dollars, ten_francs) * 2 result = bank.reduce(sum_, "USD") assert result == Money.dollar(20)
def test_simple_addition(): five: Money = Money.dollar(5) # "sum" is a reserved keyword in Python, so everything that is named "sum" # in the books example will be named "sum_" for consistencies sake sum_ = five + five bank = Bank() reduced = bank.reduce(sum_, "USD") assert reduced == Money.dollar(10)
def test_sum_times(self): five_bucks = Money.dollar(5) ten_francs = Money.franc(10) bank = Bank() bank.add_rate('CHF', 'USD', 2) sum = Sum(five_bucks, ten_francs).times(2) result = bank.reduce(sum, 'USD') self.assertTrue(result.equals(Money.dollar(20)))
def test_identity_rate(): assert Bank().rate("USD", "USD") == 1
def test_reduce_money_different_currency(): bank = Bank() bank.add_rate("CHF", "USD", 2) result = bank.reduce(Money.franc(2), "USD") assert result == Money.dollar(1)
def test_reduce_money(): bank = Bank() result = bank.reduce(Money.dollar(1), "USD") assert result == Money.dollar(1)
def test_reduce_sum(): sum_ = Sum(Money.dollar(3), Money.dollar(4)) bank = Bank() result = bank.reduce(sum_, "USD") assert result == Money.dollar(7)
def test_identity_rate(self): self.assertEquals(1, Bank().rate('USD', 'USD'))
def test_reduce_money_different_currency(self): bank = Bank() bank.add_rate('CHF', 'USD', 2) result = bank.reduce(Money.franc(2), 'USD') self.assertTrue(Money.dollar(1).equals(result))
def test_reduce_money(self): bank = Bank() result = bank.reduce(Money.dollar(1), 'USD') self.assertTrue(Money.dollar(1).equals(result))
def test_simple_addition(self): sum = Sum(Money.dollar(3), Money.dollar(4)) bank = Bank() reduced = bank.reduce(sum, 'USD') self.assertTrue(reduced.equals(Money.dollar(7)))