Skip to content

word-count: added test version and updated tests to match canonical #1044

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Oct 27, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 49 additions & 22 deletions exercises/word-count/word_count_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,66 +7,93 @@ class WordCountTests(unittest.TestCase):

def test_count_one_word(self):
self.assertEqual(
{'word': 1},
word_count('word')
word_count('word'),
{'word': 1}
)

def test_count_one_of_each(self):
self.assertEqual(
{'one': 1, 'of': 1, 'each': 1},
word_count('one of each')
word_count('one of each'),
{'one': 1, 'of': 1, 'each': 1}
)

def test_count_multiple_occurences(self):
self.assertEqual(
{'one': 1, 'fish': 4, 'two': 1, 'red': 1, 'blue': 1},
word_count('one fish two fish red fish blue fish')
word_count('one fish two fish red fish blue fish'),
{'one': 1, 'fish': 4, 'two': 1, 'red': 1, 'blue': 1}
)

def test_cramped_list(self):
self.assertEqual(
word_count('one,two,three'),
{'one': 1, 'two': 1, 'three': 1}
)

def test_expanded_list(self):
self.assertEqual(
word_count('one,\ntwo,\nthree'),
{'one': 1, 'two': 1, 'three': 1}
)

def test_ignores_punctuation(self):
self.assertEqual(
{'car': 1, 'carpet': 1, 'as': 1, 'java': 1, 'javascript': 1},
word_count('car : carpet as java : javascript!!&@$%^&')
word_count('car : carpet as java : javascript!!&@$%^&'),
{'car': 1, 'carpet': 1, 'as': 1, 'java': 1, 'javascript': 1}
)

def test_include_numbers(self):
self.assertEqual(
{'testing': 2, '1': 1, '2': 1},
word_count('testing 1 2 testing')
word_count('testing 1 2 testing'),
{'testing': 2, '1': 1, '2': 1}
)

def test_mixed_case(self):
self.assertEqual(
[2, 3],
sorted(list(word_count('go Go GO Stop stop').values()))
word_count('go Go GO Stop stop'),
{'go': 3, 'stop': 2}
)

def test_apostrophes(self):
self.assertEqual(
word_count("First: don't laugh. Then: don't cry."),
{'first': 1, "don't": 2, 'laugh': 1, 'then': 1, 'cry': 1}
)

def test_quotations(self):
self.assertEqual(
word_count("Joe can't tell between 'large' and large."),
{'joe': 1, "can't": 1, 'tell': 1, 'between': 1, 'large': 2,
'and': 1}
)

# Additional tests for this track

def test_multiple_spaces(self):
self.assertEqual(
{'wait': 1, 'for': 1, 'it': 1},
word_count('wait for it')
word_count('wait for it'),
{'wait': 1, 'for': 1, 'it': 1}
)

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},
word_count('rah rah ah ah ah\nroma roma ma\n'
'ga ga oh la la\nwant your bad romance')
'ga ga oh la la\nwant your bad romance'),
{'rah': 2, 'ah': 3, 'roma': 2, 'ma': 1, 'ga': 2, 'oh': 1, 'la': 2,
'want': 1, 'your': 1, 'bad': 1, 'romance': 1}
)

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},
word_count('rah rah ah ah ah\troma roma ma\tga ga oh la la\t'
'want your bad romance')
'want your bad romance'),
{'rah': 2, 'ah': 3, 'roma': 2, 'ma': 1, 'ga': 2, 'oh': 1, 'la': 2,
'want': 1, 'your': 1, 'bad': 1, 'romance': 1}
)

def test_non_alphanumeric(self):
self.assertEqual(
{'hey': 1, 'my': 1, 'spacebar': 1, 'is': 1, 'broken': 1},
word_count('hey,my_spacebar_is_broken.')
word_count('hey,my_spacebar_is_broken.'),
{'hey': 1, 'my': 1, 'spacebar': 1, 'is': 1, 'broken': 1}
)


Expand Down