Skip to content

Instantly share code, notes, and snippets.

@danott
Last active January 4, 2016 07:09
Show Gist options
  • Save danott/8587012 to your computer and use it in GitHub Desktop.
Save danott/8587012 to your computer and use it in GitHub Desktop.
Make these tests pass and the computer will do serial commas for you!
require "minitest/autorun"
class TestSerialComma < MiniTest::Unit::TestCase
def possessives
%w[hers his yours mine ours]
end
def test_possessives_1
assert_equal "hers", serial_comma(places.slice(0, 1))
end
def test_possessives_2
skip
assert_equal "hers and his", serial_comma(possessives.slice(0, 2))
end
def test_possessives_3
skip
assert_equal "hers, his, and yours", serial_comma(possessives.slice(0, 3))
end
def test_possessives_4
skip
assert_equal "hers, his, yours, and mine", serial_comma(possessives.slice(0, 4))
end
def test_possessives_5
skip
assert_equal "hers, his, yours, mine, and ours", serial_comma(possessives)
end
def places
%w[Seattle Lexington Athens Newcastle]
end
def test_places_1
skip
assert_equal "Seattle", serial_comma(places.slice(0, 1))
end
def test_places_2
skip
assert_equal "Seattle and Lexington", serial_comma(places.slice(0, 2))
end
def test_places_3
skip
assert_equal "Seattle, Lexington, and Athens", serial_comma(places.slice(0, 3))
end
def test_places_4
skip
assert_equal "Seattle, Lexington, Athens, and Newcastle", serial_comma(places)
end
end
@squaresurf
Copy link

Fun times. I forked your gist and wrote a method to pass it. If you get a chance let me know what you would do differently.

PS. I updated your test slightly in my first revision. Let me know if I did that incorrectly.

@danott
Copy link
Author

danott commented Jan 24, 2014

@squaresurf. Yep, I totally had a copy/paste error on that test. I have fixed it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment