O'Reilly logo

Test Driven Development: By Example by Kent Beck

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 15. Mixed Currencies

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

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, but I didn't want to disturb ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required