roman: add more roman letters and test

This commit is contained in:
vinchent 2024-09-22 21:24:24 +02:00
parent 7d751cab3d
commit 6da23dc641
2 changed files with 46 additions and 18 deletions

View File

@ -8,6 +8,15 @@ type RomanNumeral struct {
}
var allRomanNumerals = []RomanNumeral{
{1000, "M"},
{900, "CM"},
{500, "D"},
{400, "CD"},
{900, "CM"},
{100, "C"},
{90, "XC"},
{50, "L"},
{40, "XL"},
{10, "X"},
{9, "IX"},
{5, "V"},

View File

@ -1,30 +1,49 @@
package roman
import "testing"
import (
"fmt"
"testing"
)
func TestRomanNemerals(t *testing.T) {
cases := []struct {
Description string
Arabic int
Want string
Arabic int
Roman string
}{
{"1 gets converted to I", 1, "I"},
{"2 gets converted to II", 2, "II"},
{"3 gets converted to III", 3, "III"},
{"4 gets converted to IV", 4, "IV"},
{"5 gets converted to V", 5, "V"},
{"7 gets converted to VII", 7, "VII"},
{"9 gets converted to IX", 9, "IX"},
{"10 gets converted to X", 10, "X"},
{"14 gets converted to XIV", 14, "XIV"},
{"18 gets converted to XVIII", 18, "XVIII"},
{"20 gets converted to XX", 20, "XX"},
{"39 gets converted to XXXIX", 39, "XXXIX"},
{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 {
t.Run(test.Description, 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)
want := test.Want
want := test.Roman
if got != want {
t.Errorf("got %q, want %q", got, want)