Created
October 10, 2012 15:29
-
-
Save royosherove/3866357 to your computer and use it in GitHub Desktop.
start of string calculator kata in ruby
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" | |
class StringCalculator | |
def add(numbers) | |
return 0 if numbers == "" | |
return numbers.to_i unless numbers.include? "," | |
return numbers[0].to_i + numbers[2].to_i | |
end | |
def initialize | |
puts "initialized!" | |
end | |
end | |
describe StringCalculator do | |
describe ".add" do | |
context "empty input" do | |
it "should return the default zero" do | |
subject.add("").should == 0 | |
end | |
end | |
context "single number" do | |
it "should return that number" do | |
subject.add("1").should == 1 | |
end | |
specify { subject.add("2").should == 2 } | |
specify { subject.add("-2").should == -2 } | |
end | |
context "multiple numbers" do | |
it "should sum them up" do | |
subject.add("1,2").should == 3 | |
end | |
specify { subject.add("1,3").should == 4} | |
specify { subject.add("1,2,3").should == 6} | |
end | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment