diff --git a/acronym.rb b/acronym.rb new file mode 100644 index 0000000..6a2c762 --- /dev/null +++ b/acronym.rb @@ -0,0 +1,5 @@ +module Acronym + def self.abbreviate(value) + value.scan(/\b\w/).map(&:upcase).join + end +end diff --git a/acronym_test.rb b/acronym_test.rb new file mode 100644 index 0000000..afdea31 --- /dev/null +++ b/acronym_test.rb @@ -0,0 +1,40 @@ +require 'minitest/autorun' +require_relative 'acronym' + +# Common test data version: 1.7.0 cacf1f1 +class AcronymTest < Minitest::Test + def test_basic + # skip + assert_equal "PNG", Acronym.abbreviate('Portable Network Graphics') + end + + def test_lowercase_words + skip + assert_equal "ROR", Acronym.abbreviate('Ruby on Rails') + end + + def test_punctuation + skip + assert_equal "FIFO", Acronym.abbreviate('First In, First Out') + end + + def test_all_caps_word + skip + assert_equal "GIMP", Acronym.abbreviate('GNU Image Manipulation Program') + end + + def test_punctuation_without_whitespace + skip + assert_equal "CMOS", Acronym.abbreviate('Complementary metal-oxide semiconductor') + end + + def test_very_long_abbreviation + skip + assert_equal "ROTFLSHTMDCOALM", Acronym.abbreviate('Rolling On The Floor Laughing So Hard That My Dogs Came Over And Licked Me') + end + + def test_consecutive_delimiters + skip + assert_equal "SIMUFTA", Acronym.abbreviate('Something - I made up from thin air') + end +end