RomanNumbering { protected static String convert(int index) { StringBuilder buf = new StringBuilder(); if (index < 0) { buf.append('-'); index = -index; } if (index >= 4000) { buf.append('|'); buf.append(convert(index / 1000)); buf.append('|'); index = index - (index / 1000) * 1000; } int pos = 0; while (true) { RomanDigit dig = ROMAN_DIGITS[pos]; while (index >= dig.value) { buf.append(dig.digit); index -= dig.value; } if (index <= 0) { break; } int j = pos; while (!ROMAN_DIGITS[++j].pre) ; if (index + ROMAN_DIGITS[j].value >= dig.value) { buf.append(ROMAN_DIGITS[j].digit).append(dig.digit); index -= dig.value - ROMAN_DIGITS[j].value; } pos++; } return buf.toString(); }  static String toRomanLowerCase(int number); static String toRomanUpperCase(int number); static String toRoman(int number, boolean upperCase);  }
@Test public void negativeConvertTest() { Assert.assertEquals("-vi", RomanNumbering.convert(-6)); }
@Test public void zeroConvertTest() { Assert.assertEquals("", RomanNumbering.convert(0)); }
@Test public void convertTest() { Assert.assertEquals("mdclxvi", RomanNumbering.convert(1666)); Assert.assertEquals("mcmlxxxiii", RomanNumbering.convert(1983)); Assert.assertEquals("mmm", RomanNumbering.convert(3000)); Assert.assertEquals("|vi|", RomanNumbering.convert(6000)); Assert.assertEquals("|vi|dccxxxiii", RomanNumbering.convert(6733)); }