@Test @UseDataProvider("decodeResultsData") public void decode(int expected, String romanNumber) { assertEquals(expected, RomanNumberConverter.decode(romanNumber)); }
public static int decode(String roman) { int result = 0; String uRoman = roman.toUpperCase(); for(int i = 0; i < uRoman.length() - 1; i++) { if (decodeSingle(uRoman.charAt(i)) < decodeSingle(uRoman.charAt(i+1))) { result -= decodeSingle(uRoman.charAt(i)); } else { result += decodeSingle(uRoman.charAt(i)); } } result += decodeSingle(uRoman.charAt(uRoman.length()-1)); return result; }
RomanNumberConverter { public static int decode(String roman) { int result = 0; String uRoman = roman.toUpperCase(); for(int i = 0; i < uRoman.length() - 1; i++) { if (decodeSingle(uRoman.charAt(i)) < decodeSingle(uRoman.charAt(i+1))) { result -= decodeSingle(uRoman.charAt(i)); } else { result += decodeSingle(uRoman.charAt(i)); } } result += decodeSingle(uRoman.charAt(uRoman.length()-1)); return result; } }
RomanNumberConverter { public static int decode(String roman) { int result = 0; String uRoman = roman.toUpperCase(); for(int i = 0; i < uRoman.length() - 1; i++) { if (decodeSingle(uRoman.charAt(i)) < decodeSingle(uRoman.charAt(i+1))) { result -= decodeSingle(uRoman.charAt(i)); } else { result += decodeSingle(uRoman.charAt(i)); } } result += decodeSingle(uRoman.charAt(uRoman.length()-1)); return result; }  }
RomanNumberConverter { public static int decode(String roman) { int result = 0; String uRoman = roman.toUpperCase(); for(int i = 0; i < uRoman.length() - 1; i++) { if (decodeSingle(uRoman.charAt(i)) < decodeSingle(uRoman.charAt(i+1))) { result -= decodeSingle(uRoman.charAt(i)); } else { result += decodeSingle(uRoman.charAt(i)); } } result += decodeSingle(uRoman.charAt(uRoman.length()-1)); return result; }  static int decode(String roman); static boolean isRomanNumber(String str); static boolean isNotRomanNumber(String str); }
RomanNumberConverter { public static int decode(String roman) { int result = 0; String uRoman = roman.toUpperCase(); for(int i = 0; i < uRoman.length() - 1; i++) { if (decodeSingle(uRoman.charAt(i)) < decodeSingle(uRoman.charAt(i+1))) { result -= decodeSingle(uRoman.charAt(i)); } else { result += decodeSingle(uRoman.charAt(i)); } } result += decodeSingle(uRoman.charAt(uRoman.length()-1)); return result; }  static int decode(String roman); static boolean isRomanNumber(String str); static boolean isNotRomanNumber(String str);  }