Beispiel #1
0
 def test_unicode(self):
     self.assertEqual(
         {decode_if_needed('аДаО'): 1, decode_if_needed('баВаИаДаАаНаИб'): 1},
         count_words('аДаО№Ÿ––баВаИаДаАаНаИб!')
     )
Beispiel #2
0
 def test_newlines(self):
     self.assertEqual(
         {'rah': 2, 'ah': 3, 'roma': 2, 'ma': 1, 'ga': 2, 'oh': 1, 'la': 2,
          'want': 1, 'your': 1, 'bad': 1, 'romance': 1},
         count_words('rah rah ah ah ah\nroma roma ma\n''ga ga oh la la\nwant your bad romance')
     )
Beispiel #3
0
 def test_tabs(self):
     self.assertEqual(
         {'rah': 2, 'ah': 3, 'roma': 2, 'ma': 1, 'ga': 2, 'oh': 1, 'la': 2,
          'want': 1, 'your': 1, 'bad': 1, 'romance': 1},
         count_words('rah rah ah ah ah\troma roma ma\tga ga oh la la\t''want your bad romance')
     )
Beispiel #4
0
 def test_mixed_case(self):
     self.assertEqual(
         [2, 3],
         sorted(list(count_words('go Go GO Stop stop').values()))
     )
Beispiel #5
0
 def test_multiple_spaces(self):
     self.assertEqual(
         {'wait': 1, 'for': 1, 'it': 1},
         count_words('wait for       it')
     )
Beispiel #6
0
 def test_preserves_punctuation(self):
     self.assertEqual(
         {'car': 1, 'carpet': 1, 'as': 1, 'java': 1, 'javascript': 1},
         count_words('car : carpet as java : javascript!!&@$%^&')
     )
Beispiel #7
0
 def test_include_numbers(self):
     self.assertEqual(
         {'testing': 2, '1': 1, '2': 1},
         count_words('testing 1 2 testing'))
Beispiel #8
0
 def test_count_multiple_occurrences(self):
     self.assertEqual(
         {'one': 1, 'fish': 4, 'two': 1, 'red': 1, 'blue': 1},
         count_words('one fish two fish red fish blue fish'))
Beispiel #9
0
 def test_count_one_of_each(self):
     self.assertEqual({'one': 1, 'of': 1, 'each': 1}, count_words('one of each'))
Beispiel #10
0
 def test_count_one_word(self):
     self.assertEqual({'word': 1}, count_words('word'))