11import unittest
22
3- from word_count import word_count
3+ from word_count import count_words
44
55
66# Tests adapted from `problem-specifications//canonical-data.json` @ v1.3.0
@@ -9,90 +9,90 @@ class WordCountTest(unittest.TestCase):
99
1010 def test_count_one_word (self ):
1111 self .assertEqual (
12- word_count ('word' ),
12+ count_words ('word' ),
1313 {'word' : 1 }
1414 )
1515
16- def test_count_one_of_each (self ):
16+ def test_count_one_of_each_word (self ):
1717 self .assertEqual (
18- word_count ('one of each' ),
18+ count_words ('one of each' ),
1919 {'one' : 1 , 'of' : 1 , 'each' : 1 }
2020 )
2121
22- def test_count_multiple_occurrences_of_a_word (self ):
22+ def test_multiple_occurrences_of_a_word (self ):
2323 self .assertEqual (
24- word_count ('one fish two fish red fish blue fish' ),
24+ count_words ('one fish two fish red fish blue fish' ),
2525 {'one' : 1 , 'fish' : 4 , 'two' : 1 , 'red' : 1 , 'blue' : 1 }
2626 )
2727
28- def test_cramped_list (self ):
28+ def test_handles_cramped_lists (self ):
2929 self .assertEqual (
30- word_count ('one,two,three' ),
30+ count_words ('one,two,three' ),
3131 {'one' : 1 , 'two' : 1 , 'three' : 1 }
3232 )
3333
34- def test_expanded_list (self ):
34+ def test_handles_expanded_lists (self ):
3535 self .assertEqual (
36- word_count ('one,\n two,\n three' ),
36+ count_words ('one,\n two,\n three' ),
3737 {'one' : 1 , 'two' : 1 , 'three' : 1 }
3838 )
3939
40- def test_ignores_punctuation (self ):
40+ def test_ignore_punctuation (self ):
4141 self .assertEqual (
42- word_count ('car : carpet as java : javascript!!&@$%^&' ),
42+ count_words ('car : carpet as java : javascript!!&@$%^&' ),
4343 {'car' : 1 , 'carpet' : 1 , 'as' : 1 , 'java' : 1 , 'javascript' : 1 }
4444 )
4545
4646 def test_include_numbers (self ):
4747 self .assertEqual (
48- word_count ('testing 1 2 testing' ),
48+ count_words ('testing 1 2 testing' ),
4949 {'testing' : 2 , '1' : 1 , '2' : 1 }
5050 )
5151
5252 def test_normalize_case (self ):
5353 self .assertEqual (
54- word_count ('go Go GO Stop stop' ),
54+ count_words ('go Go GO Stop stop' ),
5555 {'go' : 3 , 'stop' : 2 }
5656 )
5757
58- def test_apostrophes (self ):
58+ def test_with_apostrophes (self ):
5959 self .assertEqual (
60- word_count ("First: don't laugh. Then: don't cry." ),
60+ count_words ("First: don't laugh. Then: don't cry." ),
6161 {'first' : 1 , "don't" : 2 , 'laugh' : 1 , 'then' : 1 , 'cry' : 1 }
6262 )
6363
64- def test_quotations (self ):
64+ def test_with_quotations (self ):
6565 self .assertEqual (
66- word_count ("Joe can't tell between 'large' and large." ),
66+ count_words ("Joe can't tell between 'large' and large." ),
6767 {'joe' : 1 , "can't" : 1 , 'tell' : 1 , 'between' : 1 , 'large' : 2 ,
6868 'and' : 1 }
6969 )
7070
7171 def test_multiple_spaces_not_detected_as_a_word (self ):
7272 self .assertEqual (
73- word_count (' multiple whitespaces' ),
73+ count_words (' multiple whitespaces' ),
7474 {'multiple' : 1 , 'whitespaces' : 1 }
7575 )
7676
77- def test_alternating_word_separators (self ):
77+ def test_alternating_word_separators_not_detected_as_a_word (self ):
7878 self .assertEqual (
79- word_count (",\n ,one,\n ,two \n 'three'" ),
79+ count_words (",\n ,one,\n ,two \n 'three'" ),
8080 {'one' : 1 , 'two' : 1 , 'three' : 1 }
8181 )
8282
8383 # Additional tests for this track
8484
8585 def test_tabs (self ):
8686 self .assertEqual (
87- word_count ('rah rah ah ah ah\t roma roma ma\t ga ga oh la la\t '
88- 'want your bad romance' ),
87+ count_words ('rah rah ah ah ah\t roma roma ma\t ga ga oh la la\t '
88+ 'want your bad romance' ),
8989 {'rah' : 2 , 'ah' : 3 , 'roma' : 2 , 'ma' : 1 , 'ga' : 2 , 'oh' : 1 , 'la' : 2 ,
9090 'want' : 1 , 'your' : 1 , 'bad' : 1 , 'romance' : 1 }
9191 )
9292
9393 def test_non_alphanumeric (self ):
9494 self .assertEqual (
95- word_count ('hey,my_spacebar_is_broken.' ),
95+ count_words ('hey,my_spacebar_is_broken.' ),
9696 {'hey' : 1 , 'my' : 1 , 'spacebar' : 1 , 'is' : 1 , 'broken' : 1 }
9797 )
9898
0 commit comments