Skip to content

Commit

Permalink
String calculator #7
Browse files Browse the repository at this point in the history
  • Loading branch information
alloy committed Jul 22, 2011
1 parent 5d6e708 commit c25f0e3
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions string_calculator.rb
Expand Up @@ -3,7 +3,8 @@

def add(string)
return 0 if string.empty?
string[0,1].to_i + string[2,1].to_i
first_number, last_number = string.split(',')
first_number.to_i + last_number.to_i
end

describe "The string calculator method `Add'" do
Expand All @@ -15,7 +16,11 @@ def add(string)
add("1").should == 1
end

it "returns the sum of two digits delimited by a comma" do
it "returns the sum of two numbers delimited by a comma" do
add("1,2").should == 3
end

it "takes numbers consisting of two or more digits" do
add("21,21").should == 42
end
end

0 comments on commit c25f0e3

Please sign in to comment.