Enhance docs, add more tests in RomanToInteger (#5926)

This commit is contained in:
Hardik Pawar
2024-10-23 11:55:20 +05:30
committed by GitHub
parent aaaf96b05f
commit 7bbdae5fe0
2 changed files with 73 additions and 31 deletions

View File

@ -8,16 +8,31 @@ import org.junit.jupiter.api.Test;
public class RomanToIntegerTest {
@Test
public void testRomanToInteger() {
public void testValidRomanToInteger() {
assertEquals(1994, RomanToInteger.romanToInt("MCMXCIV"));
assertEquals(58, RomanToInteger.romanToInt("LVIII"));
assertEquals(1804, RomanToInteger.romanToInt("MDCCCIV"));
assertEquals(9, RomanToInteger.romanToInt("IX"));
assertEquals(4, RomanToInteger.romanToInt("IV"));
assertEquals(3000, RomanToInteger.romanToInt("MMM"));
}
@Test
void testRomanToIntegerThrows() {
public void testLowercaseInput() {
assertEquals(1994, RomanToInteger.romanToInt("mcmxciv"));
assertEquals(58, RomanToInteger.romanToInt("lviii"));
}
@Test
public void testInvalidRomanNumerals() {
assertThrows(IllegalArgumentException.class, () -> RomanToInteger.romanToInt("Z"));
assertThrows(IllegalArgumentException.class, () -> RomanToInteger.romanToInt("MZI"));
assertThrows(IllegalArgumentException.class, () -> RomanToInteger.romanToInt("MMMO"));
}
@Test
public void testEmptyAndNullInput() {
assertEquals(0, RomanToInteger.romanToInt("")); // Empty string case
assertThrows(NullPointerException.class, () -> RomanToInteger.romanToInt(null)); // Null input case
}
}