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 Sum.plus() to finish Expression.plus, and then we need Expression.times(), and then we're finished with the whole example. Here's the test for Sum.plus():

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 books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.