Skip to content

Instantly share code, notes, and snippets.

@phillipoertel
Last active August 29, 2015 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phillipoertel/11223054 to your computer and use it in GitHub Desktop.
Save phillipoertel/11223054 to your computer and use it in GitHub Desktop.
require 'test/unit'
class StringCalculator
def add(string)
string.split(',').map(&:to_i).inject(:+) || 0
end
end
class TestStringCalculator < Test::Unit::TestCase
def add(string)
StringCalculator.new.add(string)
end
def test_empty_string_returns_0
assert_equal(0, add(""))
end
def test_one_number_returns_the_number
assert_equal(5, add("5"))
end
def test_two_numbers_returns_sum
assert_equal(8, add("5,3"))
end
def test_four_numbers_returns_sum
assert_equal(100, add("5,3,12,80"))
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment