Created
June 29, 2019 01:08
-
-
Save omenking/b44286717e2c1bd945201bb5fa20c0b2 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" | |
# remove the first and last letter of a string | |
# if there is less than 2 characters return zero. | |
def quartered value | |
raise ArgumentError, 'Argument is not a string' unless value.is_a? String | |
return value unless value.size > 2 | |
value[0] = '' | |
value.chop | |
end | |
class QaurteredTest < Test::Unit::TestCase | |
def test_quartered | |
assert_equal 'orl', quartered('world'), "quartered('world') should return a string called 'orl'" | |
end | |
def test_quartered_ignore | |
assert_equal 'hi', quartered('hi'), "quartered('hi') should return 'hi'" | |
end | |
def test_quartered_invalid | |
assert_raise_message('Argument is not a string', "quartered(2) should raise exception") do | |
quartered(2) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment