roman: add convert to arabic
This commit is contained in:
parent
6da23dc641
commit
715ea6477a
@ -35,3 +35,7 @@ func ConvertToRoman(arabic int) string {
|
|||||||
|
|
||||||
return converted.String()
|
return converted.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ConvertToArabic(roman string) int {
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
@ -5,41 +5,42 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var cases = []struct {
|
||||||
|
Arabic int
|
||||||
|
Roman string
|
||||||
|
}{
|
||||||
|
{Arabic: 1, Roman: "I"},
|
||||||
|
{Arabic: 2, Roman: "II"},
|
||||||
|
{Arabic: 3, Roman: "III"},
|
||||||
|
{Arabic: 4, Roman: "IV"},
|
||||||
|
{Arabic: 5, Roman: "V"},
|
||||||
|
{Arabic: 6, Roman: "VI"},
|
||||||
|
{Arabic: 7, Roman: "VII"},
|
||||||
|
{Arabic: 8, Roman: "VIII"},
|
||||||
|
{Arabic: 9, Roman: "IX"},
|
||||||
|
{Arabic: 10, Roman: "X"},
|
||||||
|
{Arabic: 14, Roman: "XIV"},
|
||||||
|
{Arabic: 18, Roman: "XVIII"},
|
||||||
|
{Arabic: 20, Roman: "XX"},
|
||||||
|
{Arabic: 39, Roman: "XXXIX"},
|
||||||
|
{Arabic: 40, Roman: "XL"},
|
||||||
|
{Arabic: 47, Roman: "XLVII"},
|
||||||
|
{Arabic: 49, Roman: "XLIX"},
|
||||||
|
{Arabic: 50, Roman: "L"},
|
||||||
|
{Arabic: 100, Roman: "C"},
|
||||||
|
{Arabic: 90, Roman: "XC"},
|
||||||
|
{Arabic: 400, Roman: "CD"},
|
||||||
|
{Arabic: 500, Roman: "D"},
|
||||||
|
{Arabic: 900, Roman: "CM"},
|
||||||
|
{Arabic: 1000, Roman: "M"},
|
||||||
|
{Arabic: 1984, Roman: "MCMLXXXIV"},
|
||||||
|
{Arabic: 3999, Roman: "MMMCMXCIX"},
|
||||||
|
{Arabic: 2014, Roman: "MMXIV"},
|
||||||
|
{Arabic: 1006, Roman: "MVI"},
|
||||||
|
{Arabic: 798, Roman: "DCCXCVIII"},
|
||||||
|
}
|
||||||
|
|
||||||
func TestRomanNemerals(t *testing.T) {
|
func TestRomanNemerals(t *testing.T) {
|
||||||
cases := []struct {
|
|
||||||
Arabic int
|
|
||||||
Roman string
|
|
||||||
}{
|
|
||||||
{Arabic: 1, Roman: "I"},
|
|
||||||
{Arabic: 2, Roman: "II"},
|
|
||||||
{Arabic: 3, Roman: "III"},
|
|
||||||
{Arabic: 4, Roman: "IV"},
|
|
||||||
{Arabic: 5, Roman: "V"},
|
|
||||||
{Arabic: 6, Roman: "VI"},
|
|
||||||
{Arabic: 7, Roman: "VII"},
|
|
||||||
{Arabic: 8, Roman: "VIII"},
|
|
||||||
{Arabic: 9, Roman: "IX"},
|
|
||||||
{Arabic: 10, Roman: "X"},
|
|
||||||
{Arabic: 14, Roman: "XIV"},
|
|
||||||
{Arabic: 18, Roman: "XVIII"},
|
|
||||||
{Arabic: 20, Roman: "XX"},
|
|
||||||
{Arabic: 39, Roman: "XXXIX"},
|
|
||||||
{Arabic: 40, Roman: "XL"},
|
|
||||||
{Arabic: 47, Roman: "XLVII"},
|
|
||||||
{Arabic: 49, Roman: "XLIX"},
|
|
||||||
{Arabic: 50, Roman: "L"},
|
|
||||||
{Arabic: 100, Roman: "C"},
|
|
||||||
{Arabic: 90, Roman: "XC"},
|
|
||||||
{Arabic: 400, Roman: "CD"},
|
|
||||||
{Arabic: 500, Roman: "D"},
|
|
||||||
{Arabic: 900, Roman: "CM"},
|
|
||||||
{Arabic: 1000, Roman: "M"},
|
|
||||||
{Arabic: 1984, Roman: "MCMLXXXIV"},
|
|
||||||
{Arabic: 3999, Roman: "MMMCMXCIX"},
|
|
||||||
{Arabic: 2014, Roman: "MMXIV"},
|
|
||||||
{Arabic: 1006, Roman: "MVI"},
|
|
||||||
{Arabic: 798, Roman: "DCCXCVIII"},
|
|
||||||
}
|
|
||||||
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)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user