Created
October 14, 2015 23:35
-
-
Save dillonkearns/78f867376ced4505c076 to your computer and use it in GitHub Desktop.
Roman Numeral Kata Result
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Numeral | |
CONVERSIONS = { | |
100 => 'C', | |
90 => 'X', | |
10 => 'X', | |
5 => 'V', | |
4 => 'IV', | |
1 => 'I', | |
} | |
def self.to_roman(n) | |
result = '' | |
CONVERSIONS.each do |value, numeral| | |
while n >= value | |
result += numeral | |
n -= value | |
end | |
end | |
result | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require_relative '../lib/numeral' | |
require_relative './spec_helper' | |
describe Numeral do | |
it 'converts 1 to I' do | |
assert_equal 'I', Numeral.to_roman(1) | |
end | |
it 'converts 2 to II' do | |
assert_equal 'II', Numeral.to_roman(2) | |
end | |
it 'converts 5 to V' do | |
assert_equal 'V', Numeral.to_roman(5) | |
end | |
it 'converts 10 to X' do | |
assert_equal 'X', Numeral.to_roman(10) | |
end | |
it 'converts 20 to XX' do | |
assert_equal 'XX', Numeral.to_roman(20) | |
end | |
it 'converts 25 to XXV' do | |
assert_equal 'XXV', Numeral.to_roman(25) | |
end | |
it 'converts 4 to IV' do | |
assert_equal 'IV', Numeral.to_roman(4) | |
end | |
it 'converts 100 to C' do | |
assert_equal 'C', Numeral.to_roman(100) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'minitest/autorun' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment