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 O’Reilly online learning.

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