From: Gustavo Martin Morcuende Date: Sun, 27 Nov 2016 17:16:02 +0000 (+0100) Subject: Writing test for XXX requires a while loop X-Git-Url: https://git.gumartinm.name/?a=commitdiff_plain;h=8dc2c72c66fb5f76fdcd0d59f60bb41cbefac9c7;p=JavaForFun Writing test for XXX requires a while loop Duplication: there is two loops appending letters, we want to remove one because both of them are doing the same. --- diff --git a/TDD/sandromancuso/romannumerals/src/main/java/org/craftedsw/romannumerals/RomanNumeralGenerator.java b/TDD/sandromancuso/romannumerals/src/main/java/org/craftedsw/romannumerals/RomanNumeralGenerator.java index 18f422e..e24a8da 100644 --- a/TDD/sandromancuso/romannumerals/src/main/java/org/craftedsw/romannumerals/RomanNumeralGenerator.java +++ b/TDD/sandromancuso/romannumerals/src/main/java/org/craftedsw/romannumerals/RomanNumeralGenerator.java @@ -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; } diff --git a/TDD/sandromancuso/romannumerals/src/test/java/org/craftedsw/romannumerals/RomanNumeralsGeneratorShould.java b/TDD/sandromancuso/romannumerals/src/test/java/org/craftedsw/romannumerals/RomanNumeralsGeneratorShould.java index 4c3eafc..031280b 100644 --- a/TDD/sandromancuso/romannumerals/src/test/java/org/craftedsw/romannumerals/RomanNumeralsGeneratorShould.java +++ b/TDD/sandromancuso/romannumerals/src/test/java/org/craftedsw/romannumerals/RomanNumeralsGeneratorShould.java @@ -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")); } }