Testing another simple case, V
authorGustavo Martin Morcuende <gu.martinm@gmail.com>
Sun, 27 Nov 2016 16:46:06 +0000 (17:46 +0100)
committerGustavo Martin Morcuende <gu.martinm@gmail.com>
Sun, 27 Nov 2016 16:46:06 +0000 (17:46 +0100)
We skip IV because it is an exception.

TDD/sandromancuso/romannumerals/README [new file with mode: 0644]
TDD/sandromancuso/romannumerals/src/main/java/org/craftedsw/romannumerals/RomanNumeralGenerator.java
TDD/sandromancuso/romannumerals/src/test/java/org/craftedsw/romannumerals/RomanNumeralsGeneratorShould.java

diff --git a/TDD/sandromancuso/romannumerals/README b/TDD/sandromancuso/romannumerals/README
new file mode 100644 (file)
index 0000000..28d3dcc
--- /dev/null
@@ -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.
+
index 5b53491..0dabe1f 100644 (file)
@@ -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";
                }
index 4d18c40..c741117 100644 (file)
@@ -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"));
        }
 
 }