Skip to content

Instantly share code, notes, and snippets.

@SolomonHD
Created February 10, 2015 14:22
Show Gist options
  • Save SolomonHD/386344b214959c9f74da to your computer and use it in GitHub Desktop.
Save SolomonHD/386344b214959c9f74da to your computer and use it in GitHub Desktop.
Name Quiz
require 'minitest/autorun'
require 'minitest/pride'
def first_name(input)
string = []
string << input.split(" ")
output = string[0]
return output
end
def last_name(input)
string = []
string << input.split(" ")
return string[-1]
end
class StringQuiz < MiniTest::Test
def test_first_name
assert_equal "Mason", first_name("Mason Matthews")
end
def test_last_name
assert_equal "Matthews", last_name("Mason Matthews")
end
def test_one_word_name
assert_equal "", first_name("deadmou5")
assert_equal "deadmou5", last_name("deadmou5")
end
def test_three_word_name
assert_equal "John Quincy", first_name("John Quincy Adams")
assert_equal "Adams", last_name("John Quincy Adams")
end
def test_no_word_name
assert_equal "", first_name("")
assert_equal "", last_name("")
end
def test_nil_name
assert_equal "", first_name(nil)
assert_equal "", last_name(nil)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment