roman: add 9 and 10

This commit is contained in:
vinchent 2024-09-22 21:07:05 +02:00
parent 0a75d86850
commit 6f853c25d0
2 changed files with 9 additions and 0 deletions

View File

@ -6,6 +6,12 @@ func ConvertToRoman(arabic int) string {
var converted strings.Builder
for arabic > 0 {
switch {
case arabic > 9:
converted.WriteString("X")
arabic -= 10
case arabic > 8:
converted.WriteString("IX")
arabic -= 9
case arabic > 4:
converted.WriteString("V")
arabic -= 5

View File

@ -13,6 +13,9 @@ func TestRomanNemerals(t *testing.T) {
{"3 gets converted to III", 3, "III"},
{"4 gets converted to IV", 4, "IV"},
{"5 gets converted to V", 5, "V"},
{"7 gets converted to VII", 7, "VII"},
{"9 gets converted to IX", 9, "IX"},
{"10 gets converted to X", 10, "X"},
}
for _, test := range cases {
t.Run(test.Description, func(t *testing.T) {