This file contains hidden or 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
| private static final NavigableMap<Integer, String> ROMAN_NUMERALS = new TreeMap<>() { | |
| { | |
| put(1, "I"); | |
| put(4, "IV"); | |
| put(5, "V"); | |
| put(9, "IX"); | |
| put(10, "X"); | |
| put(50, "L"); | |
| put(100, "C"); | |
| put(500, "D"); |
This file contains hidden or 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
| @Test | |
| public void convert_shouldReturnIV() { | |
| final String romanNumeral = RomanNumerals.convert(4); | |
| assertThat(romanNumeral, is("IV")); | |
| } |
This file contains hidden or 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
| @Test | |
| public void convert_shouldReturnIII() { | |
| final String romanNumeral = RomanNumerals.convert(3); | |
| assertThat(romanNumeral, is("III")); | |
| } |
This file contains hidden or 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
| public class RomanNumerals { | |
| private static final NavigableMap<Integer, String> ROMAN_NUMERALS = new TreeMap<>() { | |
| { | |
| put(1, "I"); | |
| put(5, "V"); | |
| put(10, "X"); | |
| put(50, "L"); | |
| put(100, "C"); | |
| put(500, "D"); |
This file contains hidden or 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
| public class RomanNumerals { | |
| private static final NavigableMap<Integer, String> ROMAN_NUMERALS = new TreeMap<>() { | |
| { | |
| put(1, "I"); | |
| put(5, "V"); | |
| put(10, "X"); | |
| put(50, "L"); | |
| put(100, "C"); | |
| put(500, "D"); |
This file contains hidden or 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
| public class RomanNumerals { | |
| private static final NavigableMap<Integer, String> ROMAN_NUMERALS = new TreeMap<>() { | |
| { | |
| put(1, "I"); | |
| put(5, "V"); | |
| put(10, "X"); | |
| put(50, "L"); | |
| put(100, "C"); | |
| put(500, "D"); |
This file contains hidden or 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
| @Test | |
| public void convert_shouldReturnII() { | |
| final String romanNumeral = RomanNumerals.convert(2); | |
| assertThat(romanNumeral, is("II")); | |
| } |
This file contains hidden or 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
| import java.util.Map; | |
| public class RomanNumerals { | |
| private static final Map<Integer, String> ROMAN_NUMERALS = Map.of( | |
| 1, "I", | |
| 5, "V", | |
| 10, "X", | |
| 50, "L", | |
| 100, "C", |
This file contains hidden or 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
| public class RomanNumerals { | |
| public static String convert(int number) { | |
| if (number == 5) { | |
| return "V"; | |
| } else if (number ==10) { | |
| return "X"; | |
| } else if (number == 50) { | |
| return "L"; | |
| } else if (number == 100) { |
This file contains hidden or 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
| public class RomanNumeralsTest { | |
| @Test | |
| public void convert_shouldReturnI() { | |
| final String romanNumeral = RomanNumerals.convert(1); | |
| assertThat(romanNumeral, is("I")); | |
| } |