Fixed NumberUtils

This commit is contained in:
Auxilor
2021-08-06 22:31:51 +01:00
parent 56234e6c83
commit b9b4ce1937
2 changed files with 8 additions and 8 deletions

View File

@@ -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()));
} }

View File

@@ -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));
} }
} }