From 39686d6aef6a06da3b6f4a687da27e13251441d6 Mon Sep 17 00:00:00 2001 From: Gustavo Martin Morcuende Date: Sun, 27 Nov 2016 17:46:06 +0100 Subject: [PATCH] Testing another simple case, V We skip IV because it is an exception. --- TDD/sandromancuso/romannumerals/README | 7 +++++++ .../java/org/craftedsw/romannumerals/RomanNumeralGenerator.java | 3 +++ .../org/craftedsw/romannumerals/RomanNumeralsGeneratorShould.java | 4 ++++ 3 files changed, 14 insertions(+) create mode 100644 TDD/sandromancuso/romannumerals/README 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")); } } -- 2.1.4