Created
February 21, 2013 19:02
-
-
Save georgeu2000/5007171 to your computer and use it in GitHub Desktop.
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 RomanNumeral | |
def self.add_roman(roman_number) | |
result = 0 | |
roman_number.each_char do |c| | |
result += roman_lookup(c) | |
end | |
result | |
end | |
def self.to_arabic(roman_number) | |
add_roman roman_number | |
end | |
def self.roman_lookup(character) | |
case character | |
when "I" | |
1 | |
when "V" | |
5 | |
end | |
end | |
end | |
describe RomanNumeral do | |
it 'returns 1' do | |
RomanNumeral.to_arabic( 'I' ).should == 1 | |
end | |
it 'returns 5' do | |
RomanNumeral.to_arabic( 'V' ).should == 5 | |
end | |
describe 'adds' do | |
it 'many numbers' do | |
RomanNumeral.to_arabic( 'VII' ).should == 7 | |
end | |
end | |
it 'subtracts' do | |
RomanNumeral.to_arabic( 'IV' ).should == 4 | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks!