示例#1
0
 @Test
 public void testReduceSum() {
   Expression sum = new Sum(Money.dollar(3), Money.dollar(4));
   Bank bank = new Bank();
   Money result = bank.reduce(sum, "USD");
   assertEquals(Money.dollar(7), result);
 }
示例#2
0
 @Test
 public void testAddition() {
   Money five = Money.dollar(5);
   Expression sum = five.plus(five);
   Bank bank = new Bank();
   Money reduced = bank.reduce(sum, "USD");
   assertEquals(Money.dollar(10), reduced);
 }
示例#3
0
  @Test
  public void testPlusReturnsSum() {
    Money five = Money.dollar(5);
    Expression result = five.plus(five);
    Sum sum = (Sum) result;

    assertEquals(five, sum.augend);
    assertEquals(five, sum.addend);
  }
示例#4
0
  @Test
  public void testMixedAddiction() {
    Expression fiveBucks = Money.dollar(5);
    Expression tenFranks = Money.franc(10);
    Bank bank = new Bank();
    bank.addRate("CHF", "USD", 2);
    Money result = bank.reduce(fiveBucks.plus(tenFranks), "USD");

    assertEquals(Money.dollar(10), result);
  }
示例#5
0
  @Test
  public void testSumTimes() {
    Expression fiveBucks = Money.dollar(5);
    Expression tenFranks = Money.franc(10);
    Bank bank = new Bank();
    bank.addRate("CHF", "USD", 2);

    Expression sum = new Sum(fiveBucks, tenFranks).times(2);
    Money result = bank.reduce(sum, "USD");
    assertEquals(Money.dollar(20), result);
  }
示例#6
0
 @Test
 public void testEquality() {
   assertTrue(Money.dollar(5).equals(Money.dollar(5)));
   assertFalse(Money.dollar(5).equals(Money.dollar(6)));
   assertFalse(Money.franc(5).equals(Money.dollar(5)));
 }
示例#7
0
 @Test
 public void testReduceMoneyDifferentCurrency() {
   Bank bank = new Bank();
   bank.addRate("CHF", "USD", 2);
   assertEquals(Money.dollar(1), bank.reduce(Money.franc(2), "USD"));
 }
示例#8
0
 @Test
 public void testReduceMoney() {
   Bank bank = new Bank();
   Money result = bank.reduce(Money.dollar(1), "USD");
   assertEquals(Money.dollar(1), result);
 }
示例#9
0
 @Test
 public void testCurrency() {
   assertEquals("USD", Money.dollar(5).currency());
   assertEquals("CHF", Money.franc(5).currency());
 }
示例#10
0
 @Test
 public void logCashDispensed() {
   Money money = new Money(22, 55);
   log.logCashDispensed(money);
   assertTrue(mock_simulator.getLastLog().equals("Dispensed: " + money.toString()));
 }
 @Test
 public void testPlusSameCurrencyReturnsMoney() {
   Money result = Money.dollar(1).plus(Money.dollar(1));
   assertEquals(Money.dollar(2), result);
 }
 @Test
 public void testReduce() {
   Money dollar = Money.dollar(1);
   Money reduce = dollar.reduce(new Bank(), dollar.currency());
   assertEquals(dollar, reduce);
 }
 @Test
 public void testCurrency() {
   assertEquals(USD, Money.dollar(1).currency());
   assertEquals(CHF, Money.franc(1).currency());
 }
 @Test
 public void testEquality() {
   Money fiveFrancs = Money.franc(5);
   Money fiveDollars = Money.dollar(5);
   assertFalse(fiveFrancs.equals(fiveDollars));
 }