Code Kata Report

diff -r e7a4cf29bdca -r cc0637319340 src/test/java/com/nicholas/tuck/katas/SpellOutCheckTest.java --- a/src/test/java/com/nicholas/tuck/katas/SpellOutCheckTest.java Fri Jul 20 11:38:57 2012 -0500 +++ b/src/test/java/com/nicholas/tuck/katas/SpellOutCheckTest.java Fri Jul 20 12:03:19 2012 -0500 @@ -10,8 +10,15 @@ public class SpellOutCheckTest { @Test public void decimalValueOfZeroShouldPrintZero() { SpellOutCheck checkSpellerOuter = new SpellOutCheck(new BigDecimal(0)); - assertThat(checkSpellerOuter.toString(), is("Zero Dollars and 00/100")); + assertThat(checkSpellerOuter.toString(), is("Zero and 00/100 dollars")); } + + @Test + public void zeroDollarsandSomeCentsShouldPrintCorrectly() { + SpellOutCheck spellOutAgain = new SpellOutCheck(new BigDecimal("0.13")); + assertThat(spellOutAgain.toString(), is("Zero and 13/100 dollars")); + } + } diff -r e7a4cf29bdca -r cc0637319340 src/main/java/com/nicholas/tuck/katas/SpellOutCheck.java --- a/src/main/java/com/nicholas/tuck/katas/SpellOutCheck.java Fri Jul 20 11:38:57 2012 -0500 +++ b/src/main/java/com/nicholas/tuck/katas/SpellOutCheck.java Fri Jul 20 12:03:19 2012 -0500 @@ -1,16 +1,24 @@ package com.nicholas.tuck.katas; import java.math.BigDecimal; public class SpellOutCheck { + private BigDecimal decimalValue; + SpellOutCheck(BigDecimal value) { - + this.decimalValue = value; } @Override public String toString() { - return "Zero Dollars and 00/100"; + String s = decimalValue.toString(); + String[] pieces = s.split("\\."); + int cents = 0; + if (pieces.length > 1) { + cents = Integer.valueOf(pieces[1]); + } + return String.format("Zero and %02d/100 dollars", cents); } } ****************************************** ****************************************** ************ Next Diff ******************* ****************************************** ****************************************** diff -r cc0637319340 -r f7f7bd60a675 src/test/java/com/nicholas/tuck/katas/SpellOutCheckTest.java --- a/src/test/java/com/nicholas/tuck/katas/SpellOutCheckTest.java Fri Jul 20 12:03:19 2012 -0500 +++ b/src/test/java/com/nicholas/tuck/katas/SpellOutCheckTest.java Fri Jul 20 12:14:03 2012 -0500 @@ -14,11 +14,17 @@ SpellOutCheck checkSpellerOuter = new SpellOutCheck(new BigDecimal(0)); assertThat(checkSpellerOuter.toString(), is("Zero and 00/100 dollars")); } @Test - public void zeroDollarsandSomeCentsShouldPrintCorrectly() { + public void zeroDollarsAndSomeCentsShouldPrintCorrectly() { SpellOutCheck spellOutAgain = new SpellOutCheck(new BigDecimal("0.13")); assertThat(spellOutAgain.toString(), is("Zero and 13/100 dollars")); } + @Test + public void zeroDollarsAndPartialCentsShouldPrintCorrectly() { + SpellOutCheck spellOutCheck = new SpellOutCheck(new BigDecimal("0.139")); + assertThat(spellOutCheck.toString(), is("Zero and 14/100 dollars")); + } + } diff -r cc0637319340 -r f7f7bd60a675 src/main/java/com/nicholas/tuck/katas/SpellOutCheck.java --- a/src/main/java/com/nicholas/tuck/katas/SpellOutCheck.java Fri Jul 20 12:03:19 2012 -0500 +++ b/src/main/java/com/nicholas/tuck/katas/SpellOutCheck.java Fri Jul 20 12:14:03 2012 -0500 @@ -1,24 +1,19 @@ package com.nicholas.tuck.katas; import java.math.BigDecimal; public class SpellOutCheck { private BigDecimal decimalValue; SpellOutCheck(BigDecimal value) { - this.decimalValue = value; + this.decimalValue = value.remainder(BigDecimal.ONE).setScale(2, BigDecimal.ROUND_HALF_UP); } @Override public String toString() { - String s = decimalValue.toString(); - String[] pieces = s.split("\\."); - int cents = 0; - if (pieces.length > 1) { - cents = Integer.valueOf(pieces[1]); - } + int cents = decimalValue.multiply(new BigDecimal("100")).intValue(); return String.format("Zero and %02d/100 dollars", cents); } } ****************************************** ****************************************** ************ Next Diff ******************* ****************************************** ****************************************** diff -r f7f7bd60a675 -r 11f40d76be29 src/test/java/com/nicholas/tuck/katas/SpellOutCheckTest.java --- a/src/test/java/com/nicholas/tuck/katas/SpellOutCheckTest.java Fri Jul 20 12:14:03 2012 -0500 +++ b/src/test/java/com/nicholas/tuck/katas/SpellOutCheckTest.java Fri Jul 20 12:28:59 2012 -0500 @@ -20,11 +20,23 @@ SpellOutCheck spellOutAgain = new SpellOutCheck(new BigDecimal("0.13")); assertThat(spellOutAgain.toString(), is("Zero and 13/100 dollars")); } @Test - public void zeroDollarsAndPartialCentsShouldPrintCorrectly() { + public void zeroDollarsAndPartialCentsShouldRoundUp() { SpellOutCheck spellOutCheck = new SpellOutCheck(new BigDecimal("0.139")); assertThat(spellOutCheck.toString(), is("Zero and 14/100 dollars")); } + @Test + public void zeroDollarsAndPartialCentsShouldRoundDown() { + SpellOutCheck spellOutCheck = new SpellOutCheck(new BigDecimal("0.133")); + assertThat(spellOutCheck.toString(), is("Zero and 13/100 dollars")); + } + + @Test + public void oneDollarsShouldPrintCorrectly() { + SpellOutCheck spellOutCheck = new SpellOutCheck(new BigDecimal("1")); + assertThat(spellOutCheck.toString(), is("One and 00/100 dollars")); + } + } diff -r f7f7bd60a675 -r 11f40d76be29 src/main/java/com/nicholas/tuck/katas/SpellOutCheck.java --- a/src/main/java/com/nicholas/tuck/katas/SpellOutCheck.java Fri Jul 20 12:14:03 2012 -0500 +++ b/src/main/java/com/nicholas/tuck/katas/SpellOutCheck.java Fri Jul 20 12:28:59 2012 -0500 @@ -1,19 +1,31 @@ package com.nicholas.tuck.katas; import java.math.BigDecimal; public class SpellOutCheck { private BigDecimal decimalValue; - + private BigDecimal wholeDollaz; SpellOutCheck(BigDecimal value) { - this.decimalValue = value.remainder(BigDecimal.ONE).setScale(2, BigDecimal.ROUND_HALF_UP); + BigDecimal[] pieces = value.divideAndRemainder(BigDecimal.ONE); + this.decimalValue = pieces[1].setScale(2, BigDecimal.ROUND_HALF_UP); + wholeDollaz = pieces[0]; } @Override public String toString() { int cents = decimalValue.multiply(new BigDecimal("100")).intValue(); - return String.format("Zero and %02d/100 dollars", cents); + int dollaz = wholeDollaz.intValueExact(); + String hollaz = ""; + switch(dollaz) { + case 0: + hollaz = "Zero"; + break; + case 1: + hollaz = "One"; + break; + } + return String.format("%s and %02d/100 dollars", hollaz, cents); } } ****************************************** ****************************************** ************ Next Diff ******************* ****************************************** ****************************************** diff -r 11f40d76be29 -r aefb1c73abe9 src/test/java/com/nicholas/tuck/katas/SpellOutCheckTest.java --- a/src/test/java/com/nicholas/tuck/katas/SpellOutCheckTest.java Fri Jul 20 12:28:59 2012 -0500 +++ b/src/test/java/com/nicholas/tuck/katas/SpellOutCheckTest.java Fri Jul 20 12:44:16 2012 -0500 @@ -32,11 +32,29 @@ SpellOutCheck spellOutCheck = new SpellOutCheck(new BigDecimal("0.133")); assertThat(spellOutCheck.toString(), is("Zero and 13/100 dollars")); } @Test + public void zeroDollarsAndPartialCentsShouldRoundHalfUp() { + SpellOutCheck spellOutCheck = new SpellOutCheck(new BigDecimal("0.135")); + assertThat(spellOutCheck.toString(), is("Zero and 14/100 dollars")); + } + + @Test public void oneDollarsShouldPrintCorrectly() { SpellOutCheck spellOutCheck = new SpellOutCheck(new BigDecimal("1")); assertThat(spellOutCheck.toString(), is("One and 00/100 dollars")); } + @Test + public void oneDollarsAndSomeCentsShouldPrintCorrectly() { + SpellOutCheck spellOutCheck = new SpellOutCheck(new BigDecimal("1.25")); + assertThat(spellOutCheck.toString(), is("One and 25/100 dollars")); + } + + @Test + public void twoDollarsAndSomeCentsShouldPrintCorrectly() { + SpellOutCheck spellOutCheck = new SpellOutCheck(new BigDecimal("2.25")); + assertThat(spellOutCheck.toString(), is("Two and 25/100 dollars")); + } + } diff -r 11f40d76be29 -r aefb1c73abe9 src/main/java/com/nicholas/tuck/katas/SpellOutCheck.java --- a/src/main/java/com/nicholas/tuck/katas/SpellOutCheck.java Fri Jul 20 12:28:59 2012 -0500 +++ b/src/main/java/com/nicholas/tuck/katas/SpellOutCheck.java Fri Jul 20 12:44:16 2012 -0500 @@ -1,31 +1,34 @@ package com.nicholas.tuck.katas; import java.math.BigDecimal; +import java.util.HashMap; +import java.util.Map; public class SpellOutCheck { private BigDecimal decimalValue; private BigDecimal wholeDollaz; + private static Map<Long, String> dollarNameMap; + + static { + dollarNameMap = new HashMap<Long, String>(); + dollarNameMap.put(0l, "Zero"); + dollarNameMap.put(1l, "One"); + dollarNameMap.put((long)2, "Two"); + } + SpellOutCheck(BigDecimal value) { BigDecimal[] pieces = value.divideAndRemainder(BigDecimal.ONE); this.decimalValue = pieces[1].setScale(2, BigDecimal.ROUND_HALF_UP); wholeDollaz = pieces[0]; } @Override public String toString() { int cents = decimalValue.multiply(new BigDecimal("100")).intValue(); - int dollaz = wholeDollaz.intValueExact(); - String hollaz = ""; - switch(dollaz) { - case 0: - hollaz = "Zero"; - break; - case 1: - hollaz = "One"; - break; - } - return String.format("%s and %02d/100 dollars", hollaz, cents); + + return String.format("%s and %02d/100 dollars", + dollarNameMap.get(wholeDollaz.longValue()), cents); } } ****************************************** ****************************************** ************ Next Diff ******************* ****************************************** ****************************************** diff -r aefb1c73abe9 -r 497b83287332 src/test/java/com/nicholas/tuck/katas/SpellOutCheckTest.java --- a/src/test/java/com/nicholas/tuck/katas/SpellOutCheckTest.java Fri Jul 20 12:44:16 2012 -0500 +++ b/src/test/java/com/nicholas/tuck/katas/SpellOutCheckTest.java Fri Jul 20 12:58:15 2012 -0500 @@ -55,6 +55,11 @@ public void twoDollarsAndSomeCentsShouldPrintCorrectly() { SpellOutCheck spellOutCheck = new SpellOutCheck(new BigDecimal("2.25")); assertThat(spellOutCheck.toString(), is("Two and 25/100 dollars")); } + @Test + public void ninetyNineNineShouldRoundToADollar() { + SpellOutCheck spellOutCheck = new SpellOutCheck(new BigDecimal("0.999")); + assertThat(spellOutCheck.toString(), is("One and 00/100 dollars")); + } } diff -r aefb1c73abe9 -r 497b83287332 src/main/java/com/nicholas/tuck/katas/SpellOutCheck.java --- a/src/main/java/com/nicholas/tuck/katas/SpellOutCheck.java Fri Jul 20 12:44:16 2012 -0500 +++ b/src/main/java/com/nicholas/tuck/katas/SpellOutCheck.java Fri Jul 20 12:58:15 2012 -0500 @@ -1,34 +1,42 @@ package com.nicholas.tuck.katas; import java.math.BigDecimal; +import java.math.MathContext; +import java.math.RoundingMode; import java.util.HashMap; import java.util.Map; public class SpellOutCheck { private BigDecimal decimalValue; - private BigDecimal wholeDollaz; + private BigDecimal wholeDollars; private static Map<Long, String> dollarNameMap; static { dollarNameMap = new HashMap<Long, String>(); dollarNameMap.put(0l, "Zero"); dollarNameMap.put(1l, "One"); dollarNameMap.put((long)2, "Two"); } SpellOutCheck(BigDecimal value) { BigDecimal[] pieces = value.divideAndRemainder(BigDecimal.ONE); - this.decimalValue = pieces[1].setScale(2, BigDecimal.ROUND_HALF_UP); - wholeDollaz = pieces[0]; + wholeDollars = pieces[0]; + + decimalValue = pieces[1].setScale(2, BigDecimal.ROUND_HALF_UP); + if (decimalValue.compareTo(BigDecimal.ONE) == 0) { + wholeDollars = wholeDollars.add(BigDecimal.ONE); + decimalValue = BigDecimal.ZERO; + } + } @Override public String toString() { int cents = decimalValue.multiply(new BigDecimal("100")).intValue(); return String.format("%s and %02d/100 dollars", - dollarNameMap.get(wholeDollaz.longValue()), cents); + dollarNameMap.get(wholeDollars.longValue()), cents); } } ****************************************** ****************************************** ************ Next Diff ******************* ****************************************** ****************************************** diff -r 497b83287332 -r 0a6dc5f51d04 src/test/java/com/nicholas/tuck/katas/SpellOutCheckTest.java --- a/src/test/java/com/nicholas/tuck/katas/SpellOutCheckTest.java Fri Jul 20 12:58:15 2012 -0500 +++ b/src/test/java/com/nicholas/tuck/katas/SpellOutCheckTest.java Fri Jul 20 13:02:05 2012 -0500 @@ -60,6 +60,13 @@ @Test public void ninetyNineNineShouldRoundToADollar() { SpellOutCheck spellOutCheck = new SpellOutCheck(new BigDecimal("0.999")); assertThat(spellOutCheck.toString(), is("One and 00/100 dollars")); } + + @Test + public void threeDollarsShouldPrintCorrectly() { + SpellOutCheck spellOutCheck = new SpellOutCheck(new BigDecimal("3")); + assertThat(spellOutCheck.toString(), is("Three and 00/100 dollars")); + } + } diff -r 497b83287332 -r 0a6dc5f51d04 src/main/java/com/nicholas/tuck/katas/SpellOutCheck.java --- a/src/main/java/com/nicholas/tuck/katas/SpellOutCheck.java Fri Jul 20 12:58:15 2012 -0500 +++ b/src/main/java/com/nicholas/tuck/katas/SpellOutCheck.java Fri Jul 20 13:02:05 2012 -0500 @@ -1,42 +1,43 @@ package com.nicholas.tuck.katas; import java.math.BigDecimal; import java.math.MathContext; import java.math.RoundingMode; import java.util.HashMap; import java.util.Map; public class SpellOutCheck { private BigDecimal decimalValue; private BigDecimal wholeDollars; private static Map<Long, String> dollarNameMap; static { dollarNameMap = new HashMap<Long, String>(); - dollarNameMap.put(0l, "Zero"); - dollarNameMap.put(1l, "One"); + dollarNameMap.put((long)0, "Zero"); + dollarNameMap.put((long)1, "One"); dollarNameMap.put((long)2, "Two"); + dollarNameMap.put((long)3, "Three"); } SpellOutCheck(BigDecimal value) { BigDecimal[] pieces = value.divideAndRemainder(BigDecimal.ONE); wholeDollars = pieces[0]; decimalValue = pieces[1].setScale(2, BigDecimal.ROUND_HALF_UP); if (decimalValue.compareTo(BigDecimal.ONE) == 0) { wholeDollars = wholeDollars.add(BigDecimal.ONE); decimalValue = BigDecimal.ZERO; } } @Override public String toString() { int cents = decimalValue.multiply(new BigDecimal("100")).intValue(); return String.format("%s and %02d/100 dollars", dollarNameMap.get(wholeDollars.longValue()), cents); } } ****************************************** ****************************************** ************ Next Diff ******************* ****************************************** ****************************************** diff -r 0a6dc5f51d04 -r 77e6c87f7f95 src/test/java/com/nicholas/tuck/katas/SpellOutCheckTest.java --- a/src/test/java/com/nicholas/tuck/katas/SpellOutCheckTest.java Fri Jul 20 13:02:05 2012 -0500 +++ b/src/test/java/com/nicholas/tuck/katas/SpellOutCheckTest.java Fri Jul 20 13:15:41 2012 -0500 @@ -66,7 +66,22 @@ @Test public void threeDollarsShouldPrintCorrectly() { SpellOutCheck spellOutCheck = new SpellOutCheck(new BigDecimal("3")); assertThat(spellOutCheck.toString(), is("Three and 00/100 dollars")); } + + @Test + public void fourDollarsShouldPrintCorrectly() { + SpellOutCheck spellOutCheck = new SpellOutCheck(new BigDecimal("4")); + assertThat(spellOutCheck.toString(), is("Four and 00/100 dollars")); + } + @Test + public void shouldHandleFiveThroughTen() { + assertThat(new SpellOutCheck(new BigDecimal("5")).toString(), is("Five and 00/100 dollars")); + assertThat(new SpellOutCheck(new BigDecimal("6")).toString(), is("Six and 00/100 dollars")); + assertThat(new SpellOutCheck(new BigDecimal("7")).toString(), is("Seven and 00/100 dollars")); + assertThat(new SpellOutCheck(new BigDecimal("8")).toString(), is("Eight and 00/100 dollars")); + assertThat(new SpellOutCheck(new BigDecimal("9")).toString(), is("Nine and 00/100 dollars")); + assertThat(new SpellOutCheck(new BigDecimal("10")).toString(), is("Ten and 00/100 dollars")); + } } diff -r 0a6dc5f51d04 -r 77e6c87f7f95 src/main/java/com/nicholas/tuck/katas/SpellOutCheck.java --- a/src/main/java/com/nicholas/tuck/katas/SpellOutCheck.java Fri Jul 20 13:02:05 2012 -0500 +++ b/src/main/java/com/nicholas/tuck/katas/SpellOutCheck.java Fri Jul 20 13:15:41 2012 -0500 @@ -1,43 +1,50 @@ package com.nicholas.tuck.katas; import java.math.BigDecimal; import java.math.MathContext; import java.math.RoundingMode; import java.util.HashMap; import java.util.Map; public class SpellOutCheck { private BigDecimal decimalValue; private BigDecimal wholeDollars; private static Map<Long, String> dollarNameMap; static { dollarNameMap = new HashMap<Long, String>(); dollarNameMap.put((long)0, "Zero"); dollarNameMap.put((long)1, "One"); dollarNameMap.put((long)2, "Two"); dollarNameMap.put((long)3, "Three"); + dollarNameMap.put((long)4, "Four"); + dollarNameMap.put((long)5, "Five"); + dollarNameMap.put((long)6, "Six"); + dollarNameMap.put((long)7, "Seven"); + dollarNameMap.put((long)8, "Eight"); + dollarNameMap.put((long)9, "Nine"); + dollarNameMap.put((long)10, "Ten"); } SpellOutCheck(BigDecimal value) { BigDecimal[] pieces = value.divideAndRemainder(BigDecimal.ONE); wholeDollars = pieces[0]; decimalValue = pieces[1].setScale(2, BigDecimal.ROUND_HALF_UP); if (decimalValue.compareTo(BigDecimal.ONE) == 0) { wholeDollars = wholeDollars.add(BigDecimal.ONE); decimalValue = BigDecimal.ZERO; } } @Override public String toString() { int cents = decimalValue.multiply(new BigDecimal("100")).intValue(); return String.format("%s and %02d/100 dollars", dollarNameMap.get(wholeDollars.longValue()), cents); } } ****************************************** ****************************************** ************ Next Diff ******************* ****************************************** ****************************************** diff -r 77e6c87f7f95 -r 1bb5abeb666f src/main/java/com/nicholas/tuck/katas/SpellOutCheck.java --- a/src/main/java/com/nicholas/tuck/katas/SpellOutCheck.java Fri Jul 20 13:15:41 2012 -0500 +++ b/src/main/java/com/nicholas/tuck/katas/SpellOutCheck.java Fri Jul 20 13:32:20 2012 -0500 @@ -1,50 +1,40 @@ package com.nicholas.tuck.katas; import java.math.BigDecimal; -import java.math.MathContext; -import java.math.RoundingMode; import java.util.HashMap; import java.util.Map; public class SpellOutCheck { - private BigDecimal decimalValue; - private BigDecimal wholeDollars; + private long dollars; + private long cents; private static Map<Long, String> dollarNameMap; - + static { dollarNameMap = new HashMap<Long, String>(); - dollarNameMap.put((long)0, "Zero"); - dollarNameMap.put((long)1, "One"); - dollarNameMap.put((long)2, "Two"); - dollarNameMap.put((long)3, "Three"); - dollarNameMap.put((long)4, "Four"); - dollarNameMap.put((long)5, "Five"); - dollarNameMap.put((long)6, "Six"); - dollarNameMap.put((long)7, "Seven"); - dollarNameMap.put((long)8, "Eight"); - dollarNameMap.put((long)9, "Nine"); - dollarNameMap.put((long)10, "Ten"); + dollarNameMap.put((long) 0, "Zero"); + dollarNameMap.put((long) 1, "One"); + dollarNameMap.put((long) 2, "Two"); + dollarNameMap.put((long) 3, "Three"); + dollarNameMap.put((long) 4, "Four"); + dollarNameMap.put((long) 5, "Five"); + dollarNameMap.put((long) 6, "Six"); + dollarNameMap.put((long) 7, "Seven"); + dollarNameMap.put((long) 8, "Eight"); + dollarNameMap.put((long) 9, "Nine"); + dollarNameMap.put((long) 10, "Ten"); } - + SpellOutCheck(BigDecimal value) { - BigDecimal[] pieces = value.divideAndRemainder(BigDecimal.ONE); - wholeDollars = pieces[0]; - - decimalValue = pieces[1].setScale(2, BigDecimal.ROUND_HALF_UP); - if (decimalValue.compareTo(BigDecimal.ONE) == 0) { - wholeDollars = wholeDollars.add(BigDecimal.ONE); - decimalValue = BigDecimal.ZERO; - } - + long totalCents = Math.round(value.floatValue() * 100); + dollars = totalCents / 100; + cents = totalCents % 100; } @Override public String toString() { - int cents = decimalValue.multiply(new BigDecimal("100")).intValue(); - return String.format("%s and %02d/100 dollars", - dollarNameMap.get(wholeDollars.longValue()), cents); + dollarNameMap.get(dollars), cents); } } ****************************************** ****************************************** ************ Next Diff ******************* ****************************************** ****************************************** diff -r 1bb5abeb666f -r 12ba2469870d src/test/java/com/nicholas/tuck/katas/SpellOutCheckTest.java --- a/src/test/java/com/nicholas/tuck/katas/SpellOutCheckTest.java Fri Jul 20 13:32:20 2012 -0500 +++ b/src/test/java/com/nicholas/tuck/katas/SpellOutCheckTest.java Fri Jul 20 13:48:03 2012 -0500 @@ -82,6 +82,26 @@ assertThat(new SpellOutCheck(new BigDecimal("7")).toString(), is("Seven and 00/100 dollars")); assertThat(new SpellOutCheck(new BigDecimal("8")).toString(), is("Eight and 00/100 dollars")); assertThat(new SpellOutCheck(new BigDecimal("9")).toString(), is("Nine and 00/100 dollars")); assertThat(new SpellOutCheck(new BigDecimal("10")).toString(), is("Ten and 00/100 dollars")); } + + @Test + public void shouldHandleElevenThroughTwenty() { + assertThat(new SpellOutCheck(new BigDecimal("11")).toString(), is("Eleven and 00/100 dollars")); + assertThat(new SpellOutCheck(new BigDecimal("12")).toString(), is("Twelve and 00/100 dollars")); + assertThat(new SpellOutCheck(new BigDecimal("13")).toString(), is("Thirteen and 00/100 dollars")); + assertThat(new SpellOutCheck(new BigDecimal("14")).toString(), is("Fourteen and 00/100 dollars")); + assertThat(new SpellOutCheck(new BigDecimal("15")).toString(), is("Fifteen and 00/100 dollars")); + assertThat(new SpellOutCheck(new BigDecimal("16")).toString(), is("Sixteen and 00/100 dollars")); + assertThat(new SpellOutCheck(new BigDecimal("17")).toString(), is("Seventeen and 00/100 dollars")); + assertThat(new SpellOutCheck(new BigDecimal("18")).toString(), is("Eighteen and 00/100 dollars")); + assertThat(new SpellOutCheck(new BigDecimal("19")).toString(), is("Nineteen and 00/100 dollars")); + assertThat(new SpellOutCheck(new BigDecimal("20")).toString(), is("Twenty and 00/100 dollars")); + } + + @Test + public void shouldHandleTwentyOne() { + assertThat(new SpellOutCheck(new BigDecimal("21")).toString(), is("Twenty-One and 00/100 dollars")); + } + } diff -r 1bb5abeb666f -r 12ba2469870d src/main/java/com/nicholas/tuck/katas/SpellOutCheck.java --- a/src/main/java/com/nicholas/tuck/katas/SpellOutCheck.java Fri Jul 20 13:32:20 2012 -0500 +++ b/src/main/java/com/nicholas/tuck/katas/SpellOutCheck.java Fri Jul 20 13:48:03 2012 -0500 @@ -1,40 +1,63 @@ package com.nicholas.tuck.katas; import java.math.BigDecimal; import java.util.HashMap; import java.util.Map; public class SpellOutCheck { private long dollars; private long cents; private static Map<Long, String> dollarNameMap; static { dollarNameMap = new HashMap<Long, String>(); dollarNameMap.put((long) 0, "Zero"); dollarNameMap.put((long) 1, "One"); dollarNameMap.put((long) 2, "Two"); dollarNameMap.put((long) 3, "Three"); dollarNameMap.put((long) 4, "Four"); dollarNameMap.put((long) 5, "Five"); dollarNameMap.put((long) 6, "Six"); dollarNameMap.put((long) 7, "Seven"); dollarNameMap.put((long) 8, "Eight"); dollarNameMap.put((long) 9, "Nine"); dollarNameMap.put((long) 10, "Ten"); + dollarNameMap.put((long) 11, "Eleven"); + dollarNameMap.put((long) 12, "Twelve"); + dollarNameMap.put((long) 13, "Thirteen"); + dollarNameMap.put((long) 14, "Fourteen"); + dollarNameMap.put((long) 15, "Fifteen"); + dollarNameMap.put((long) 16, "Sixteen"); + dollarNameMap.put((long) 17, "Seventeen"); + dollarNameMap.put((long) 18, "Eighteen"); + dollarNameMap.put((long) 19, "Nineteen"); + dollarNameMap.put((long) 20, "Twenty"); + } SpellOutCheck(BigDecimal value) { long totalCents = Math.round(value.floatValue() * 100); dollars = totalCents / 100; cents = totalCents % 100; } + @Override public String toString() { + String dollarString = buildDollarString(); return String.format("%s and %02d/100 dollars", - dollarNameMap.get(dollars), cents); + dollarString, cents); + } + + private String buildDollarString() { + String dollarString = ""; + if( dollars > 20 ) { + dollarString = dollarNameMap.get((long)20) + "-" + dollarNameMap.get(dollars % 10); + } else { + dollarString = dollarNameMap.get(dollars); + } + return dollarString; } } ****************************************** ****************************************** ************ Next Diff ******************* ****************************************** ****************************************** diff -r 12ba2469870d -r ec44a8d4beb6 src/test/java/com/nicholas/tuck/katas/SpellOutCheckTest.java --- a/src/test/java/com/nicholas/tuck/katas/SpellOutCheckTest.java Fri Jul 20 13:48:03 2012 -0500 +++ b/src/test/java/com/nicholas/tuck/katas/SpellOutCheckTest.java Fri Jul 20 13:53:37 2012 -0500 @@ -101,7 +101,18 @@ @Test public void shouldHandleTwentyOne() { assertThat(new SpellOutCheck(new BigDecimal("21")).toString(), is("Twenty-One and 00/100 dollars")); } - + + @Test + public void shouldHandleTwentyTwo() { + assertThat(new SpellOutCheck(new BigDecimal("22")).toString(), is("Twenty-Two and 00/100 dollars")); + } + + @Test + public void shouldHandleThirtyThree() { + assertThat(new SpellOutCheck(new BigDecimal("33")).toString(), is("Thirty-Three and 00/100 dollars")); + } + + } diff -r 12ba2469870d -r ec44a8d4beb6 src/main/java/com/nicholas/tuck/katas/SpellOutCheck.java --- a/src/main/java/com/nicholas/tuck/katas/SpellOutCheck.java Fri Jul 20 13:48:03 2012 -0500 +++ b/src/main/java/com/nicholas/tuck/katas/SpellOutCheck.java Fri Jul 20 13:53:37 2012 -0500 @@ -1,63 +1,64 @@ package com.nicholas.tuck.katas; import java.math.BigDecimal; import java.util.HashMap; import java.util.Map; public class SpellOutCheck { private long dollars; private long cents; private static Map<Long, String> dollarNameMap; static { dollarNameMap = new HashMap<Long, String>(); dollarNameMap.put((long) 0, "Zero"); dollarNameMap.put((long) 1, "One"); dollarNameMap.put((long) 2, "Two"); dollarNameMap.put((long) 3, "Three"); dollarNameMap.put((long) 4, "Four"); dollarNameMap.put((long) 5, "Five"); dollarNameMap.put((long) 6, "Six"); dollarNameMap.put((long) 7, "Seven"); dollarNameMap.put((long) 8, "Eight"); dollarNameMap.put((long) 9, "Nine"); dollarNameMap.put((long) 10, "Ten"); dollarNameMap.put((long) 11, "Eleven"); dollarNameMap.put((long) 12, "Twelve"); dollarNameMap.put((long) 13, "Thirteen"); dollarNameMap.put((long) 14, "Fourteen"); dollarNameMap.put((long) 15, "Fifteen"); dollarNameMap.put((long) 16, "Sixteen"); dollarNameMap.put((long) 17, "Seventeen"); dollarNameMap.put((long) 18, "Eighteen"); dollarNameMap.put((long) 19, "Nineteen"); dollarNameMap.put((long) 20, "Twenty"); + dollarNameMap.put((long) 30, "Thirty"); } SpellOutCheck(BigDecimal value) { long totalCents = Math.round(value.floatValue() * 100); dollars = totalCents / 100; cents = totalCents % 100; } @Override public String toString() { String dollarString = buildDollarString(); return String.format("%s and %02d/100 dollars", dollarString, cents); } private String buildDollarString() { - String dollarString = ""; - if( dollars > 20 ) { - dollarString = dollarNameMap.get((long)20) + "-" + dollarNameMap.get(dollars % 10); - } else { - dollarString = dollarNameMap.get(dollars); + String dollarString = dollarNameMap.get(dollars); + + if(dollarString == null) { + long onesDigit = dollars % 10; + dollarString = dollarNameMap.get(dollars - onesDigit) + "-" + dollarNameMap.get(onesDigit); } return dollarString; } } ****************************************** ****************************************** ************ Next Diff ******************* ****************************************** ****************************************** diff -r ec44a8d4beb6 -r d563f1ea4ce8 src/test/java/com/nicholas/tuck/katas/SpellOutCheckTest.java --- a/src/test/java/com/nicholas/tuck/katas/SpellOutCheckTest.java Fri Jul 20 13:53:37 2012 -0500 +++ b/src/test/java/com/nicholas/tuck/katas/SpellOutCheckTest.java Fri Jul 20 13:57:08 2012 -0500 @@ -112,7 +112,17 @@ @Test public void shouldHandleThirtyThree() { assertThat(new SpellOutCheck(new BigDecimal("33")).toString(), is("Thirty-Three and 00/100 dollars")); } + @Test + public void shouldHandleFortyThroughNinety() { + assertThat(new SpellOutCheck(new BigDecimal("41")).toString(), is("Forty-One and 00/100 dollars")); + assertThat(new SpellOutCheck(new BigDecimal("51")).toString(), is("Fifty-One and 00/100 dollars")); + assertThat(new SpellOutCheck(new BigDecimal("61")).toString(), is("Sixty-One and 00/100 dollars")); + assertThat(new SpellOutCheck(new BigDecimal("71")).toString(), is("Seventy-One and 00/100 dollars")); + assertThat(new SpellOutCheck(new BigDecimal("81")).toString(), is("Eighty-One and 00/100 dollars")); + assertThat(new SpellOutCheck(new BigDecimal("91")).toString(), is("Ninety-One and 00/100 dollars")); + } + } diff -r ec44a8d4beb6 -r d563f1ea4ce8 src/main/java/com/nicholas/tuck/katas/SpellOutCheck.java --- a/src/main/java/com/nicholas/tuck/katas/SpellOutCheck.java Fri Jul 20 13:53:37 2012 -0500 +++ b/src/main/java/com/nicholas/tuck/katas/SpellOutCheck.java Fri Jul 20 13:57:08 2012 -0500 @@ -1,64 +1,70 @@ package com.nicholas.tuck.katas; import java.math.BigDecimal; import java.util.HashMap; import java.util.Map; public class SpellOutCheck { private long dollars; private long cents; private static Map<Long, String> dollarNameMap; static { dollarNameMap = new HashMap<Long, String>(); dollarNameMap.put((long) 0, "Zero"); dollarNameMap.put((long) 1, "One"); dollarNameMap.put((long) 2, "Two"); dollarNameMap.put((long) 3, "Three"); dollarNameMap.put((long) 4, "Four"); dollarNameMap.put((long) 5, "Five"); dollarNameMap.put((long) 6, "Six"); dollarNameMap.put((long) 7, "Seven"); dollarNameMap.put((long) 8, "Eight"); dollarNameMap.put((long) 9, "Nine"); dollarNameMap.put((long) 10, "Ten"); dollarNameMap.put((long) 11, "Eleven"); dollarNameMap.put((long) 12, "Twelve"); dollarNameMap.put((long) 13, "Thirteen"); dollarNameMap.put((long) 14, "Fourteen"); dollarNameMap.put((long) 15, "Fifteen"); dollarNameMap.put((long) 16, "Sixteen"); dollarNameMap.put((long) 17, "Seventeen"); dollarNameMap.put((long) 18, "Eighteen"); dollarNameMap.put((long) 19, "Nineteen"); dollarNameMap.put((long) 20, "Twenty"); dollarNameMap.put((long) 30, "Thirty"); + dollarNameMap.put((long) 40, "Forty"); + dollarNameMap.put((long) 50, "Fifty"); + dollarNameMap.put((long) 60, "Sixty"); + dollarNameMap.put((long) 70, "Seventy"); + dollarNameMap.put((long) 80, "Eighty"); + dollarNameMap.put((long) 90, "Ninety"); } SpellOutCheck(BigDecimal value) { long totalCents = Math.round(value.floatValue() * 100); dollars = totalCents / 100; cents = totalCents % 100; } @Override public String toString() { String dollarString = buildDollarString(); return String.format("%s and %02d/100 dollars", dollarString, cents); } private String buildDollarString() { String dollarString = dollarNameMap.get(dollars); if(dollarString == null) { long onesDigit = dollars % 10; dollarString = dollarNameMap.get(dollars - onesDigit) + "-" + dollarNameMap.get(onesDigit); } return dollarString; } }