roman: get start with the roman numerals
This commit is contained in:
parent
7a32f26bd5
commit
5f93a0b843
11
roman/roman.go
Normal file
11
roman/roman.go
Normal 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
25
roman/roman_test.go
Normal 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)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user