Advertisement
ugochukwu15

Untitled

Jul 27th, 2017
189
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. class Test(unittest.TestCase):
  4.     def test_returns_tuple(self):
  5.         isogram = is_isogram('abolishment')
  6.         self.assertIsInstance(isogram, tuple, msg='Does not return a tuple')
  7.  
  8.     def test_checks_for_isograms(self):
  9.         word = 'abolishment'
  10.         self.assertEqual(
  11.             is_isogram(word),
  12.             (word, True),
  13.             msg="Isogram word, '{}' not detected correctly".format(word)
  14.         )
  15.  
  16.     def test_returns_false_for_nonisograms(self):
  17.         word = 'alphabet'
  18.         self.assertEqual(
  19.             is_isogram(word),
  20.             (word, False),
  21.             msg="Non isogram word, '{}' falsely detected".format(word)
  22.         )
  23.  
  24.     def test_it_only_accepts_strings(self):
  25.         with self.assertRaises(TypeError) as context:
  26.             is_isogram(2)
  27.             self.assertEqual(
  28.                 'Argument should be a string',
  29.                 context.exception.message,
  30.                 'String inputs allowed only'
  31.             )
  32.  
  33.     def test_empty_string_input(self):
  34.         word = " "
  35.         self.assertEqual(
  36.             is_isogram(word),
  37.             (word, False),
  38.             msg='Empty string not a avalid isogram'
  39.         )
  40.  
  41.  
  42. def is_isogram(text):
  43.     if not text:
  44.         return (text,False)
  45.     for letter in text:
  46.       if text.count(letter)==1:
  47.           pass
  48.       else:
  49.           break
  50.     else:
  51.         return (text,True)
  52.     return (text,False)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement