From 5f93a0b843e0b9dacc8ac6918c83ae45cc8f4126 Mon Sep 17 00:00:00 2001 From: vinchent Date: Sun, 22 Sep 2024 20:53:13 +0200 Subject: [PATCH] roman: get start with the roman numerals --- roman/roman.go | 11 +++++++++++ roman/roman_test.go | 25 +++++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 roman/roman.go create mode 100644 roman/roman_test.go diff --git a/roman/roman.go b/roman/roman.go new file mode 100644 index 0000000..2301213 --- /dev/null +++ b/roman/roman.go @@ -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 +} diff --git a/roman/roman_test.go b/roman/roman_test.go new file mode 100644 index 0000000..0b445d6 --- /dev/null +++ b/roman/roman_test.go @@ -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) + } + }) + } +}