From 8dc2c72c66fb5f76fdcd0d59f60bb41cbefac9c7 Mon Sep 17 00:00:00 2001 From: Gustavo Martin Morcuende Date: Sun, 27 Nov 2016 18:16:02 +0100 Subject: [PATCH] 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. --- .../main/java/org/craftedsw/romannumerals/RomanNumeralGenerator.java | 2 +- .../java/org/craftedsw/romannumerals/RomanNumeralsGeneratorShould.java | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) 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")); } } -- 2.1.4