fix: handle Null Dereference in RomanToInteger (#5461)

This commit is contained in:
Piotr Idzik
2024-09-23 10:33:55 +02:00
committed by GitHub
parent b849cbb602
commit 18f6f8c30a
3 changed files with 15 additions and 8 deletions

View File

@ -1,6 +1,7 @@
package com.thealgorithms.conversions;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import org.junit.jupiter.api.Test;
@ -10,5 +11,13 @@ public class RomanToIntegerTest {
public void testRomanToInteger() {
assertEquals(1994, RomanToInteger.romanToInt("MCMXCIV"));
assertEquals(58, RomanToInteger.romanToInt("LVIII"));
assertEquals(1804, RomanToInteger.romanToInt("MDCCCIV"));
}
@Test
void testRomanToIntegerThrows() {
assertThrows(IllegalArgumentException.class, () -> RomanToInteger.romanToInt("Z"));
assertThrows(IllegalArgumentException.class, () -> RomanToInteger.romanToInt("MZI"));
assertThrows(IllegalArgumentException.class, () -> RomanToInteger.romanToInt("MMMO"));
}
}