def test_one_repeating_word(self): word = unique_words[0] wordcount.count_words(self.wordcounts_dict, [word] * 5) self.verify_keys_are_exactly({word}) self.verify_all_counts({word}, 5)
def adds_more_unique_words(): wordcounts = {} for word in unique_words: wordcounts[word] = 1 test_passed = True wordcount.count_words(wordcounts, more_unique_words) num_words = len(unique_words) + len(more_unique_words) if not len(wordcounts) == num_words: print 'Fail: Expected %d keys, got %d' % (num_words, len(wordcounts.keys())) test_passed = False for word in unique_words + more_unique_words: if not word in wordcounts: print 'Fail: Missing', word test_passed = False else: if wordcounts.get(word) != 1: print 'Fail: for %s, expected 1, got %d' % (word, wordcounts.get(word)) test_passed = False if test_passed: print 'PASS', 'adds_more_unique_words' else: print '*** FAIL ***', 'adds_more_unique_words' return
def test_adds_more_unique_words(self): self.set_up_dict_with(unique_words, 1) wordcount.count_words(self.wordcounts_dict, more_unique_words) self.verify_keys_are_exactly(unique_words + more_unique_words) self.verify_all_counts(unique_words + more_unique_words, 1)
def test_counts_repeated_words(self): self.set_up_dict_with(unique_words + more_unique_words, 1) wordcount.count_words(self.wordcounts_dict, unique_words + more_unique_words + unique_words) self.verify_keys_are_exactly(unique_words + more_unique_words) self.verify_all_counts(unique_words, 3) self.verify_all_counts(more_unique_words, 2)
def counts_unique_words(): wordcounts = {} test_passed = True wordcount.count_words(wordcounts, unique_words) if not len(wordcounts.keys()) == len(unique_words): print 'Fail: Expected %d keys, got %d' % (len(unique_words), len(wordcounts.keys())) test_passed = False for word in unique_words: if not word in wordcounts: print 'Fail: Missing', word test_passed = False else: if wordcounts.get(word) != 1: print 'Fail: for %s, expected 1, got %d' % (word, wordcounts.get(word)) test_passed = False if test_passed: print 'PASS', 'counts_unique_words' else: print '*** FAIL ***', 'counts_unique_words'
def test_counts_unique_words(self): wordcount.count_words(self.wordcounts_dict, unique_words) self.verify_keys_are_exactly(unique_words) self.verify_all_counts(unique_words, 1)