Guest User

Untitled

a guest
Jun 3rd, 2020
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.43 KB | None | 0 0
  1. import unittest
  2.  
  3. def abbreviate(text):
  4.     return "".join(w[0] for w in text.replace("_","").replace("-"," ").split()).upper()
  5.  
  6. # Tests adapted from `problem-specifications//canonical-data.json` @ v1.7.0
  7.  
  8.  
  9. class AcronymTest(unittest.TestCase):
  10.     def test_basic(self):
  11.         self.assertEqual(abbreviate("Portable Network Graphics"), "PNG")
  12.  
  13.     def test_lowercase_words(self):
  14.         self.assertEqual(abbreviate("Ruby on Rails"), "ROR")
  15.  
  16.     def test_punctuation(self):
  17.         self.assertEqual(abbreviate("First In, First Out"), "FIFO")
  18.  
  19.     def test_all_caps_word(self):
  20.         self.assertEqual(abbreviate("GNU Image Manipulation Program"), "GIMP")
  21.  
  22.     def test_punctuation_without_whitespace(self):
  23.         self.assertEqual(abbreviate("Complementary metal-oxide semiconductor"), "CMOS")
  24.  
  25.     def test_very_long_abbreviation(self):
  26.         self.assertEqual(
  27.             abbreviate(
  28.                 "Rolling On The Floor Laughing So Hard That My Dogs Came Over And Licked Me"
  29.             ),
  30.             "ROTFLSHTMDCOALM",
  31.         )
  32.  
  33.     def test_consecutive_delimiters(self):
  34.         self.assertEqual(abbreviate("Something - I made up from thin air"), "SIMUFTA")
  35.  
  36.     def test_apostrophes(self):
  37.         self.assertEqual(abbreviate("Halley's Comet"), "HC")
  38.  
  39.     def test_underscore_emphasis(self):
  40.         self.assertEqual(abbreviate("The Road _Not_ Taken"), "TRNT")
  41.  
  42.  
  43. if __name__ == "__main__":
  44.     unittest.main()
Advertisement
Add Comment
Please, Sign In to add comment