Chapter 15

Mixed Currencies

Now we are finally ready to add the test that started it all, $5 + 10 CHF:

public void testMixedAddition() {
   Expression fiveBucks= Money.dollar(5);
   Expression tenFrancs= Money.franc(10);
   Bank bank= new Bank();
   bank.addRate("CHF", "USD", 2);
   Money result= bank.reduce(fiveBucks.plus(tenFrancs), "USD");
   assertEquals(Money.dollar(10), result);
}

This is what we’d like to write. Unfortunately, there are a host of compile errors. When we were generalizing from Money to Expression, we left a lot of loose ends laying around. I was worried about them, ...

Get Test Driven Development: By Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.