***roman: add convert to arabic, the real one
This commit is contained in:
parent
715ea6477a
commit
52825e49b3
@ -37,5 +37,13 @@ func ConvertToRoman(arabic int) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func ConvertToArabic(roman string) int {
|
func ConvertToArabic(roman string) int {
|
||||||
return 1
|
var converted int
|
||||||
|
for _, numeral := range allRomanNumerals {
|
||||||
|
for strings.HasPrefix(roman, numeral.Symbol) {
|
||||||
|
converted += numeral.Value
|
||||||
|
// roman = roman[len(numeral.Symbol):]
|
||||||
|
roman = strings.TrimPrefix(roman, numeral.Symbol)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return converted
|
||||||
}
|
}
|
||||||
|
@ -54,7 +54,7 @@ func TestRomanNemerals(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestConvertingToArabic(t *testing.T) {
|
func TestConvertingToArabic(t *testing.T) {
|
||||||
for _, test := range cases[:1] {
|
for _, test := range cases {
|
||||||
t.Run(fmt.Sprintf("%q gets converted to %d", test.Roman, test.Arabic), func(t *testing.T) {
|
t.Run(fmt.Sprintf("%q gets converted to %d", test.Roman, test.Arabic), func(t *testing.T) {
|
||||||
got := ConvertToArabic(test.Roman)
|
got := ConvertToArabic(test.Roman)
|
||||||
want := test.Arabic
|
want := test.Arabic
|
||||||
|
Loading…
Reference in New Issue
Block a user