mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-11 22:22:21 +08:00
Enhance docs, add more tests in RomanToInteger
(#5926)
This commit is contained in:
@ -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
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user