diff --git a/exercises/practice/roman-numerals/.meta/spec_generator.lua b/exercises/practice/roman-numerals/.meta/spec_generator.lua new file mode 100644 index 0000000..5723187 --- /dev/null +++ b/exercises/practice/roman-numerals/.meta/spec_generator.lua @@ -0,0 +1,9 @@ +return { + module_name = 'roman_numerals', + + generate_test = function(case) + local template = [[ + assert.are.equal('%s', roman_numerals.to_roman(%s))]] + return template:format(case.expected, case.input.number) + end +} diff --git a/exercises/practice/roman-numerals/.meta/tests.toml b/exercises/practice/roman-numerals/.meta/tests.toml index 57c6c4b..709011b 100644 --- a/exercises/practice/roman-numerals/.meta/tests.toml +++ b/exercises/practice/roman-numerals/.meta/tests.toml @@ -84,5 +84,8 @@ description = "3000 is MMM" [3bc4b41c-c2e6-49d9-9142-420691504336] description = "3001 is MMMI" +[2f89cad7-73f6-4d1b-857b-0ef531f68b7e] +description = "3888 is MMMDCCCLXXXVIII" + [4e18e96b-5fbb-43df-a91b-9cb511fe0856] description = "3999 is MMMCMXCIX" diff --git a/exercises/practice/roman-numerals/roman-numerals_spec.lua b/exercises/practice/roman-numerals/roman-numerals_spec.lua index 4944eaa..16004fb 100644 --- a/exercises/practice/roman-numerals/roman-numerals_spec.lua +++ b/exercises/practice/roman-numerals/roman-numerals_spec.lua @@ -1,103 +1,111 @@ -local to_roman = require('roman-numerals').to_roman +local roman_numerals = require('roman-numerals') describe('roman-numerals', function() - it('converts 1', function() - assert.are.equal('I', to_roman(1)) + it('1 is i', function() + assert.are.equal('I', roman_numerals.to_roman(1)) end) - it('converts 2', function() - assert.are.equal('II', to_roman(2)) + it('2 is ii', function() + assert.are.equal('II', roman_numerals.to_roman(2)) end) - it('converts 3', function() - assert.are.equal('III', to_roman(3)) + it('3 is iii', function() + assert.are.equal('III', roman_numerals.to_roman(3)) end) - it('converts 4', function() - assert.are.equal('IV', to_roman(4)) + it('4 is iv', function() + assert.are.equal('IV', roman_numerals.to_roman(4)) end) - it('converts 5', function() - assert.are.equal('V', to_roman(5)) + it('5 is v', function() + assert.are.equal('V', roman_numerals.to_roman(5)) end) - it('converts 6', function() - assert.are.equal('VI', to_roman(6)) + it('6 is vi', function() + assert.are.equal('VI', roman_numerals.to_roman(6)) end) - it('converts 9', function() - assert.are.equal('IX', to_roman(9)) + it('9 is ix', function() + assert.are.equal('IX', roman_numerals.to_roman(9)) end) - it('converts 16', function() - assert.are.equal('XVI', to_roman(16)) + it('16 is xvi', function() + assert.are.equal('XVI', roman_numerals.to_roman(16)) end) - it('converts 27', function() - assert.are.equal('XXVII', to_roman(27)) + it('27 is xxvii', function() + assert.are.equal('XXVII', roman_numerals.to_roman(27)) end) - it('converts 48', function() - assert.are.equal('XLVIII', to_roman(48)) + it('48 is xlviii', function() + assert.are.equal('XLVIII', roman_numerals.to_roman(48)) end) - it('converts 59', function() - assert.are.equal('LIX', to_roman(59)) + it('49 is xlix', function() + assert.are.equal('XLIX', roman_numerals.to_roman(49)) end) - it('converts 66', function() - assert.are.equal('LXVI', to_roman(66)) + it('59 is lix', function() + assert.are.equal('LIX', roman_numerals.to_roman(59)) end) - it('converts 93', function() - assert.are.equal('XCIII', to_roman(93)) + it('66 is lxvi', function() + assert.are.equal('LXVI', roman_numerals.to_roman(66)) end) - it('converts 141', function() - assert.are.equal('CXLI', to_roman(141)) + it('93 is xciii', function() + assert.are.equal('XCIII', roman_numerals.to_roman(93)) end) - it('converts 163', function() - assert.are.equal('CLXIII', to_roman(163)) + it('141 is cxli', function() + assert.are.equal('CXLI', roman_numerals.to_roman(141)) end) - it('converts 166', function() - assert.are.equal('CLXVI', to_roman(166)) + it('163 is clxiii', function() + assert.are.equal('CLXIII', roman_numerals.to_roman(163)) end) - it('converts 402', function() - assert.are.equal('CDII', to_roman(402)) + it('166 is clxvi', function() + assert.are.equal('CLXVI', roman_numerals.to_roman(166)) end) - it('converts 575', function() - assert.are.equal('DLXXV', to_roman(575)) + it('402 is cdii', function() + assert.are.equal('CDII', roman_numerals.to_roman(402)) end) - it('converts 666', function() - assert.are.equal('DCLXVI', to_roman(666)) + it('575 is dlxxv', function() + assert.are.equal('DLXXV', roman_numerals.to_roman(575)) end) - it('converts 911', function() - assert.are.equal('CMXI', to_roman(911)) + it('666 is dclxvi', function() + assert.are.equal('DCLXVI', roman_numerals.to_roman(666)) end) - it('converts 1024', function() - assert.are.equal('MXXIV', to_roman(1024)) + it('911 is cmxi', function() + assert.are.equal('CMXI', roman_numerals.to_roman(911)) end) - it('converts 1666', function() - assert.are.equal('MDCLXVI', to_roman(1666)) + it('1024 is mxxiv', function() + assert.are.equal('MXXIV', roman_numerals.to_roman(1024)) end) - it('converts 3000', function() - assert.are.equal('MMM', to_roman(3000)) + it('1666 is mdclxvi', function() + assert.are.equal('MDCLXVI', roman_numerals.to_roman(1666)) end) - it('converts 3001', function() - assert.are.equal('MMMI', to_roman(3001)) + it('3000 is mmm', function() + assert.are.equal('MMM', roman_numerals.to_roman(3000)) end) - it('converts 3999', function() - assert.are.equal('MMMCMXCIX', to_roman(3999)) + it('3001 is mmmi', function() + assert.are.equal('MMMI', roman_numerals.to_roman(3001)) + end) + + it('3888 is mmmdccclxxxviii', function() + assert.are.equal('MMMDCCCLXXXVIII', roman_numerals.to_roman(3888)) + end) + + it('3999 is mmmcmxcix', function() + assert.are.equal('MMMCMXCIX', roman_numerals.to_roman(3999)) end) end)