Skip to content

Instantly share code, notes, and snippets.

@georgeu2000
Created February 21, 2013 19:02
Show Gist options
  • Save georgeu2000/5007171 to your computer and use it in GitHub Desktop.
Save georgeu2000/5007171 to your computer and use it in GitHub Desktop.
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
@andreimoment
Copy link

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment