Copyright 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

O'Reilly logo

Chapter 14. Change

Change is worth embracing (especially if you have a book out with “embrace change” in the title). Here, however, we are thinking about a much simpler form of change—we have two francs and we want a dollar. That sounds like a test case already:

public void testReduceMoneyDifferentCurrency() {
   Bank bank= new Bank();
   bank.addRate("CHF", "USD", 2);
   Money result= bank.reduce(Money.franc(2), "USD");
   assertEquals(Money.dollar(1), result);
}

When I convert francs to dollars, I divide by two. (We're still studiously ignoring all of those nasty numerical problems.) We can make the bar green in one piece ...

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