def test_sum_times(): five_bucks = Money.dollar(5) ten_francs = Money.franc(10) sum = Sum(five_bucks, ten_francs).times(2) bank = Bank() bank.add_rate("CHF", "USD", 2) reduced = bank.reduce(sum, "USD") assert Money.dollar(20).equals(reduced)
def test_sum_plus_money(): five_bucks = Money.dollar(5) ten_francs = Money.franc(10) sum = Sum(five_bucks, ten_francs).plus(Money.dollar(5)) bank = Bank() bank.add_rate("CHF", "USD", 2) reduced = bank.reduce(sum, "USD") assert Money.dollar(15).equals(reduced)
def test_sum_different_currency(): current_value = Money.franc(5) sum = current_value.plus(Money.dollar(5)) bank = Bank() bank.add_rate("CHF", "USD", 2) reduced = bank.reduce(sum, "USD") assert Money.dollar(7.5).equals(reduced) sum = Money.dollar(5).plus(current_value) reduced = bank.reduce(sum, "USD") assert Money.dollar(7.5).equals(reduced)
def test_currency(): assert Money.dollar(5).currency() == "USD" assert Money.franc(5).currency() == "CHF"
def test_equal_different_currency(): assert not Money.dollar(5).equals(Money.franc(5)) assert not Money.dollar(12).equals(Money.franc(12)) assert not Money.dollar(5).equals(Money.franc(6)) assert not Money.franc(5).equals(Money.dollar(6))