Skip to content

Commit 28162b9

Browse files
committed
✨ (roman-numerals): add third test and refactor
1 parent 26f6786 commit 28162b9

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

property-base-test/roman_number.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
package roman_numerals
22

3+
import "strings"
4+
35
func ConvertToRoman(arabic int) string {
4-
if arabic == 2 {
5-
return "II"
6+
var result strings.Builder
7+
for i := arabic; i > 0; i-- {
8+
result.WriteString("I")
69
}
7-
return "I"
10+
return result.String()
811
}

property-base-test/roman_number_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ func TestRomanNumerals(t *testing.T) {
1010
}{
1111
{"1 gets converted to I", 1, "I"},
1212
{"2 gets converted to II", 2, "II"},
13+
{"3 gets converted to III", 3, "III"},
1314
}
1415

1516
for _, test := range cases {

0 commit comments

Comments
 (0)