roman: add convert to arabic

This commit is contained in:
vinchent 2024-09-22 21:28:24 +02:00
parent 6da23dc641
commit 715ea6477a
2 changed files with 52 additions and 34 deletions

View File

@ -35,3 +35,7 @@ func ConvertToRoman(arabic int) string {
return converted.String() return converted.String()
} }
func ConvertToArabic(roman string) int {
return 1
}

View File

@ -5,11 +5,10 @@ import (
"testing" "testing"
) )
func TestRomanNemerals(t *testing.T) { var cases = []struct {
cases := []struct {
Arabic int Arabic int
Roman string Roman string
}{ }{
{Arabic: 1, Roman: "I"}, {Arabic: 1, Roman: "I"},
{Arabic: 2, Roman: "II"}, {Arabic: 2, Roman: "II"},
{Arabic: 3, Roman: "III"}, {Arabic: 3, Roman: "III"},
@ -39,7 +38,9 @@ func TestRomanNemerals(t *testing.T) {
{Arabic: 2014, Roman: "MMXIV"}, {Arabic: 2014, Roman: "MMXIV"},
{Arabic: 1006, Roman: "MVI"}, {Arabic: 1006, Roman: "MVI"},
{Arabic: 798, Roman: "DCCXCVIII"}, {Arabic: 798, Roman: "DCCXCVIII"},
} }
func TestRomanNemerals(t *testing.T) {
for _, test := range cases { for _, test := range cases {
t.Run(fmt.Sprintf("%d gets converted to %q", test.Arabic, test.Roman), func(t *testing.T) { t.Run(fmt.Sprintf("%d gets converted to %q", test.Arabic, test.Roman), func(t *testing.T) {
got := ConvertToRoman(test.Arabic) got := ConvertToRoman(test.Arabic)
@ -51,3 +52,16 @@ func TestRomanNemerals(t *testing.T) {
}) })
} }
} }
func TestConvertingToArabic(t *testing.T) {
for _, test := range cases[:1] {
t.Run(fmt.Sprintf("%q gets converted to %d", test.Roman, test.Arabic), func(t *testing.T) {
got := ConvertToArabic(test.Roman)
want := test.Arabic
if got != want {
t.Errorf("got %d, want %d", got, want)
}
})
}
}