roman: get start with the roman numerals

This commit is contained in:
vinchent 2024-09-22 20:53:13 +02:00
parent 7a32f26bd5
commit 5f93a0b843
2 changed files with 36 additions and 0 deletions

11
roman/roman.go Normal file
View File

@ -0,0 +1,11 @@
package roman
func ConvertToRoman(arabic int) string {
var converted string
if arabic <= 3 {
for i := 0; i < arabic; i++ {
converted += "I"
}
}
return converted
}

25
roman/roman_test.go Normal file
View File

@ -0,0 +1,25 @@
package roman
import "testing"
func TestRomanNemerals(t *testing.T) {
cases := []struct {
Description string
Arabic int
Want string
}{
{"1 gets converted to I", 1, "I"},
{"2 gets converted to II", 2, "II"},
{"3 gets converted to III", 3, "III"},
}
for _, test := range cases {
t.Run(test.Description, func(t *testing.T) {
got := ConvertToRoman(test.Arabic)
want := test.Want
if got != want {
t.Errorf("got %q, want %q", got, want)
}
})
}
}