Fixed NumberUtils
This commit is contained in:
@@ -131,7 +131,7 @@ public class NumberUtils {
|
|||||||
if (numeral.isEmpty()) {
|
if (numeral.isEmpty()) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
for (Map.Entry<Integer, String> entry : NUMERALS.entrySet()) {
|
for (Map.Entry<Integer, String> entry : NUMERALS.descendingMap().entrySet()) {
|
||||||
if (numeral.startsWith(entry.getValue())) {
|
if (numeral.startsWith(entry.getValue())) {
|
||||||
return entry.getKey() + fromNumeral(numeral.substring(entry.getValue().length()));
|
return entry.getKey() + fromNumeral(numeral.substring(entry.getValue().length()));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,20 +5,20 @@ import org.junit.jupiter.api.Test;
|
|||||||
public class NumberUtilsTest {
|
public class NumberUtilsTest {
|
||||||
@Test
|
@Test
|
||||||
public void testFormatDouble() {
|
public void testFormatDouble() {
|
||||||
Assertions.assertEquals(NumberUtils.format(3.0D), "3");
|
Assertions.assertEquals("3", NumberUtils.format(3.0D));
|
||||||
Assertions.assertEquals(NumberUtils.format(3.2D), "3.20");
|
Assertions.assertEquals("3.20", NumberUtils.format(3.2D));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLog2() {
|
public void testLog2() {
|
||||||
Assertions.assertEquals(NumberUtils.log2(2), 1);
|
Assertions.assertEquals(1, NumberUtils.log2(2));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNumerals() {
|
public void testNumerals() {
|
||||||
Assertions.assertEquals(NumberUtils.fromNumeral("IV"), 4);
|
Assertions.assertEquals(4, NumberUtils.fromNumeral("IV"));
|
||||||
Assertions.assertEquals(NumberUtils.fromNumeral("IX"), 9);
|
Assertions.assertEquals(9, NumberUtils.fromNumeral("IX"));
|
||||||
Assertions.assertEquals(NumberUtils.toNumeral(14), "XIV");
|
Assertions.assertEquals("XIV", NumberUtils.toNumeral(14));
|
||||||
Assertions.assertEquals(NumberUtils.toNumeral(21), "XXI");
|
Assertions.assertEquals("XXI", NumberUtils.toNumeral(21));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user