Created
October 13, 2015 20:10
-
-
Save allolex/3610e013e7392a889af7 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
def add_two(number = 0, *rest) | |
return nil unless number.respond_to? :+ | |
# if number.respond_to? :+ | |
if number.respond_to? :concat | |
puts "srsly?" if rest.size > 0 | |
if number.respond_to? :push | |
number.push 2 | |
else | |
number.concat "2" | |
end | |
else | |
rest << number | |
rest_sum = 0 | |
rest.each do |num| | |
rest_sum += num | |
end | |
2 + rest_sum | |
end | |
# end | |
end | |
def add_five number | |
# … | |
end | |
def test_add_two | |
p add_two(2) == 4 | |
p add_two(1) == 3 | |
p add_two(1.0) == 3.0 | |
p add_two("a") == "a2" | |
p add_two([]) == [2] | |
p add_two([1]) == [1,2] | |
p add_two({}) == nil | |
p add_two(nil) == nil | |
p add_two(true) == nil | |
p add_two == 2 | |
p add_two(1,2) == 5 | |
p add_two("a", "b") | |
end | |
def test_add_five | |
# test with expectation for add_five | |
end | |
def test_all | |
test_add_two | |
test_add_five | |
end | |
test_all |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment