From: Gustavo Martin Morcuende Date: Sun, 27 Nov 2016 16:46:06 +0000 (+0100) Subject: Testing another simple case, V X-Git-Url: https://git.gumartinm.name/?a=commitdiff_plain;h=39686d6aef6a06da3b6f4a687da27e13251441d6;p=JavaForFun Testing another simple case, V We skip IV because it is an exception. --- diff --git a/TDD/sandromancuso/romannumerals/README b/TDD/sandromancuso/romannumerals/README new file mode 100644 index 0000000..28d3dcc --- /dev/null +++ b/TDD/sandromancuso/romannumerals/README @@ -0,0 +1,7 @@ +Sandro Mancuso: test-driving algorithms +https://www.youtube.com/watch?v=iZjgj1S0FCY + +Attention, we do not use complicated structures like switch/case because they are more difficult to refactor, +once you add more cases to switch there is no way back, we can not refactor that. +Statement if with elses are also complicated, because of that we use if with returns. + 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 5b53491..0dabe1f 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 @@ -4,6 +4,9 @@ public class RomanNumeralGenerator { public static String romanFor(int decimal) { String roman = ""; + if (decimal == 5) { + return "V"; + } for (int i = 0; i < decimal; i++) { roman += "I"; } 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 4d18c40..c741117 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 @@ -18,6 +18,10 @@ public class RomanNumeralsGeneratorShould { assertThat(romanFor(1), is("I")); assertThat(romanFor(2), is("II")); assertThat(romanFor(3), is("III")); + // We jump to five because IV is an exception, it is + // going to be more complicated and we do not already have + // the pattern to extract the algorithm for the IV number. + assertThat(romanFor(5), is("V")); } }