Chapter 16. Abstraction, Finally

$5 + 10 CHF = $10 if rate is 2:1$5 + $5 = $10Return Money from $5 + $5Bank.reduce(Money)Reduce Money with conversionReduce(Bank, String)Sum.plusExpression.times

We need to implement to finish, and then we need Expression.times(), and then we're finished with the whole example. Here's the test for

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

We could have created a Sum by adding fiveBucks and tenFrancs ...

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

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.