示例#1
0
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)
示例#2
0
 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)))
示例#3
0
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)
示例#4
0
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)
示例#5
0
 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)))
示例#6
0
def test_identity_rate():
    assert Bank().rate("USD", "USD") == 1
示例#7
0
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)
示例#8
0
def test_reduce_money():
    bank = Bank()
    result = bank.reduce(Money.dollar(1), "USD")
    assert result == Money.dollar(1)
示例#9
0
def test_reduce_sum():
    sum_ = Sum(Money.dollar(3), Money.dollar(4))
    bank = Bank()
    result = bank.reduce(sum_, "USD")
    assert result == Money.dollar(7)
示例#10
0
 def test_identity_rate(self):
     self.assertEquals(1, Bank().rate('USD', 'USD'))
示例#11
0
 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))
示例#12
0
 def test_reduce_money(self):
     bank = Bank()
     result = bank.reduce(Money.dollar(1), 'USD')
     self.assertTrue(Money.dollar(1).equals(result))
示例#13
0
 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)))