-
Notifications
You must be signed in to change notification settings - Fork 19.9k
/
Copy pathRomanToIntegerTest.java
38 lines (31 loc) · 1.41 KB
/
RomanToIntegerTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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;
public class RomanToIntegerTest {
@Test
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
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
}
}