Last active
August 28, 2017 19:28
-
-
Save todd-cook/9e6e7c82e43773c008922595410e03f7 to your computer and use it in GitHub Desktop.
Test RomanNumerals
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Feel free to take a few minutes to read About Roman Numerals if you're not familiar: | |
* https://en.wikipedia.org/wiki/Roman_numerals | |
*/ | |
public class RomanNumeralConverter { | |
public static int toArabic(String roman) { | |
//TODO : Your implementation here | |
return 1; | |
} | |
public static void test_RomanToArabic() { | |
int number_correct = 0; | |
Object[] test_data = new Object[]{"I", 1, "II", 2, "III", 3, "IV", 4, "V", 5, "VI", 6, "VII", 7, "VIII", 8, | |
"IX", 9, "X", 10, "XI", 11, "XII", 12, "XIII", 13, "XIV", 14, "XV", 15, "XVI", 16, "XVII", 17, | |
"XVIII", 18, "XIX", 19, "XX", 20, "L", 50, "C", 100, "D", 500, "M", 1000, | |
"XL", 40, "XC", 90, "CD", 400, "CM", 900, "MCMLIV", 1954, "MCMXC", 1990, | |
"MMXIV", 2014 , "XIIII", 14 ,"XLIV", 44, "CDXCIX", 499, "MCMLIII", 1953, "MMMCCCIII", 3303}; | |
for (int ii = 0; ii < test_data.length; ii += 2) { | |
if (check((String) test_data[ii], (Integer) test_data[ii + 1])) number_correct++; | |
} | |
System.out.println(String.format("Number correct: %d", number_correct)); | |
} | |
public static void main(String[] args) { | |
RomanNumeralConverter.test_RomanToArabic(); | |
} | |
public static boolean check(String roman, int expected) { | |
int tmp = toArabic(roman); | |
if (tmp == expected) { | |
System.out.println(String.format("Success: %s is %d", roman, expected)); | |
return true; | |
} else { | |
System.out.println(String.format("Problem: %s was supposed to be %d, but got %d instead.", roman, expected, tmp)); | |
return false; | |
} | |
} | |
public static String toRoman (int arabic){ | |
return "TODO for Extra Credit"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment