Writing test for XXX requires a while loop
authorGustavo Martin Morcuende <gu.martinm@gmail.com>
Sun, 27 Nov 2016 17:16:02 +0000 (18:16 +0100)
committerGustavo Martin Morcuende <gu.martinm@gmail.com>
Sun, 27 Nov 2016 17:17:31 +0000 (18:17 +0100)
Duplication: there is two loops appending letters, we want to remove one because
both of them are doing the same.

TDD/sandromancuso/romannumerals/src/main/java/org/craftedsw/romannumerals/RomanNumeralGenerator.java
TDD/sandromancuso/romannumerals/src/test/java/org/craftedsw/romannumerals/RomanNumeralsGeneratorShould.java

index 18f422e..e24a8da 100644 (file)
@@ -5,7 +5,7 @@ public class RomanNumeralGenerator {
        public static String romanFor(int decimal) {
                String roman = "";
                for (RomanToDecimal romanToDecimal : RomanToDecimal.values()) {
-                       if (decimal >= romanToDecimal.decimal) {
+                       while (decimal >= romanToDecimal.decimal) {
                                roman += romanToDecimal.roman;
                                decimal -= romanToDecimal.decimal;
                        }
index 4c3eafc..031280b 100644 (file)
@@ -25,6 +25,7 @@ public class RomanNumeralsGeneratorShould {
                assertThat(romanFor(7), is("VII"));
                assertThat(romanFor(10), is("X"));
                assertThat(romanFor(18), is("XVIII"));
+               assertThat(romanFor(30), is("XXX"));
        }
 
 }