Last active
August 29, 2015 14:00
-
-
Save phillipoertel/11223054 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 '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