Skip to content

Commit d231f57

Browse files
committed
✨ (roman-numerals): ConvertToRoman add rest test and refactor
1 parent 7aa5d8e commit d231f57

File tree

2 files changed

+44
-18
lines changed

2 files changed

+44
-18
lines changed

property-base-test/roman_number.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ type RomanNumerals struct {
88
}
99

1010
var allRomanNumerals = []RomanNumerals{
11+
{1000, "M"},
12+
{900, "CM"},
13+
{500, "D"},
14+
{400, "CD"},
15+
{100, "C"},
16+
{90, "XC"},
1117
{50, "L"},
1218
{40, "XL"},
1319
{10, "X"},

property-base-test/roman_number_test.go

Lines changed: 38 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,51 @@
11
package roman_numerals
22

3-
import "testing"
3+
import (
4+
"fmt"
5+
"testing"
6+
)
47

58
func TestRomanNumerals(t *testing.T) {
69
cases := []struct {
7-
Description string
8-
Arabic int
9-
Want string
10+
Arabic int
11+
Roman string
1012
}{
11-
{"1 gets converted to I", 1, "I"},
12-
{"2 gets converted to II", 2, "II"},
13-
{"3 gets converted to III", 3, "III"},
14-
{"4 gets converted to IV", 4, "IV"},
15-
{"5 gets converted to V", 5, "V"},
16-
{"9 gets converted to IX", 9, "IX"},
17-
{"10 gets converted to X", 10, "X"},
18-
{"40 gets converted to XL", 40, "XL"},
19-
{"47 gets converted to XLVII", 47, "XLVII"},
20-
{"49 gets converted to XLIX", 49, "XLIX"},
21-
{"50 gets converted to L", 50, "L"},
13+
{Arabic: 1, Roman: "I"},
14+
{Arabic: 2, Roman: "II"},
15+
{Arabic: 3, Roman: "III"},
16+
{Arabic: 4, Roman: "IV"},
17+
{Arabic: 5, Roman: "V"},
18+
{Arabic: 6, Roman: "VI"},
19+
{Arabic: 7, Roman: "VII"},
20+
{Arabic: 8, Roman: "VIII"},
21+
{Arabic: 9, Roman: "IX"},
22+
{Arabic: 10, Roman: "X"},
23+
{Arabic: 14, Roman: "XIV"},
24+
{Arabic: 18, Roman: "XVIII"},
25+
{Arabic: 20, Roman: "XX"},
26+
{Arabic: 39, Roman: "XXXIX"},
27+
{Arabic: 40, Roman: "XL"},
28+
{Arabic: 47, Roman: "XLVII"},
29+
{Arabic: 49, Roman: "XLIX"},
30+
{Arabic: 50, Roman: "L"},
31+
{Arabic: 100, Roman: "C"},
32+
{Arabic: 90, Roman: "XC"},
33+
{Arabic: 400, Roman: "CD"},
34+
{Arabic: 500, Roman: "D"},
35+
{Arabic: 900, Roman: "CM"},
36+
{Arabic: 1000, Roman: "M"},
37+
{Arabic: 1984, Roman: "MCMLXXXIV"},
38+
{Arabic: 3999, Roman: "MMMCMXCIX"},
39+
{Arabic: 2014, Roman: "MMXIV"},
40+
{Arabic: 1006, Roman: "MVI"},
41+
{Arabic: 798, Roman: "DCCXCVIII"},
2242
}
2343

2444
for _, test := range cases {
25-
t.Run(test.Description, func(t *testing.T) {
45+
t.Run(fmt.Sprintf("%d get converted to %q", test.Arabic, test.Roman), func(t *testing.T) {
2646
got := ConvertToRoman(test.Arabic)
27-
if got != test.Want {
28-
t.Errorf("got %q, want %q", got, test.Want)
47+
if got != test.Roman {
48+
t.Errorf("got %q, want %q", got, test.Roman)
2949
}
3050
})
3151
}

0 commit comments

Comments
 (0)