Created
January 21, 2015 04:30
-
-
Save zspencer/93d2eef867b204df167e 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
require 'rspec' | |
require 'securerandom' | |
describe("Roman numeral conversion") do | |
def expect_numeral_to_become_number(numeral,number) | |
expect(convert_numeral(numeral)).to(eql(number)) | |
end | |
it "should return 1 for I" do | |
expect_numeral_to_become_number("I",1) | |
end | |
it "should return 2 for II" do | |
expect_numeral_to_become_number("II",2) | |
end | |
it "should return 3 for III" do | |
expect_numeral_to_become_number("III",3) | |
end | |
it "should return 4 for IV" do | |
expect_numeral_to_become_number("IV",4) | |
end | |
it "should return 5 for V" do | |
expect_numeral_to_become_number("V",5) | |
end | |
it "should return 6 for VI" do | |
expect_numeral_to_become_number("VI",6) | |
end | |
end | |
NUMERAL_TO_ARABIC = { | |
"I" => 1, | |
"IV" => 4, | |
"V" => 5, | |
"VI" => 6 | |
} | |
# Given a string containing a roman numeral, | |
# returns the arabic number | |
# | |
# @param numeral [String] numeral to turn to arabic | |
# @return [Numeric] | |
def convert_numeral(numeral) | |
return NUMERAL_TO_ARABIC[numeral]if NUMERAL_TO_ARABIC[numeral] | |
array = numeral.split("") | |
array.count | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment