|
1 | 1 | package roman_numerals |
2 | 2 |
|
3 | | -import "testing" |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + "testing" |
| 6 | +) |
4 | 7 |
|
5 | 8 | func TestRomanNumerals(t *testing.T) { |
6 | 9 | cases := []struct { |
7 | | - Description string |
8 | | - Arabic int |
9 | | - Want string |
| 10 | + Arabic int |
| 11 | + Roman string |
10 | 12 | }{ |
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"}, |
22 | 42 | } |
23 | 43 |
|
24 | 44 | 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) { |
26 | 46 | 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) |
29 | 49 | } |
30 | 50 | }) |
31 | 51 | } |
|
0 commit comments