def test_a_count_of_words(self): self._write("Keep the bar green to keep the code clean.", TEST_FILE) counter = WordCounter.load(TEST_FILE) self.assertEqual(9, counter.number_of_words()) os.remove(TEST_FILE)
def test_ratio_parameterized(self, sentence, word, expected_ratio): counter = WordCounter(sentence) self.assertAlmostEqual(expected_ratio, counter.ratio_of(word), delta=0.01)
def test_containment_of_word(self): counter = WordCounter.load(TEST_FILE)
def test_count_of_words_better(self): counter = WordCounter.load(TEST_FILE)
def test_not_contain_unique_word(self): counter = WordCounter("green bar green hat") self.assertNotIn("foo", counter.unique_words())
def test_not_count_capitalized_word(self): counter = WordCounter("green bar green hat")
def test_count_number_of_words(self): counter = WordCounter("Keep the bar green to keep the code clean.")
def test_count_unique_words_case_insensitive(self): counter = WordCounter("green bar Green hat") self.assertEqual(["bar", "green", "hat"], counter.unique_words())
def test_count_green_twice(self): counter = WordCounter("green bar green hat")
def test_find_unique_words(self): counter = WordCounter("green bar green hat")
def test_return_not_none_for_existing_word_count(self): counter = WordCounter("green bar green hat")
def test_return_none_for_unknown_word_count(self): counter = WordCounter("green bar green hat")
def test_non_containment_of_word(self): counter = WordCounter("green hat")
def word_count_of_missing_file(): WordCounter.load("DoesNotExist.txt")
def test_not_contain_unique_word(self): counter = WordCounter("green bar green hat")
def ratio_of_missing_word(): counter = WordCounter("green bar green") return counter.ratio_of("missingWord")
def test_ratio_of_word(self): counter = WordCounter("green bar green")
def test_count_number_of_words(self): counter = WordCounter("Keep the bar green to keep the code clean.") self.assertEqual(9, counter.number_of_words())
def test_first_unique_word_starts_with_b(self): counter = WordCounter("green bar green")
def test_find_number_of_unique_words(self): counter = WordCounter("green bar green hat") self.assertEqual(3, len(counter.unique_words()))
def ratio_of_given_word(self, sentence, word, expected_ratio): """Helper function for each set of parameters.""" counter = WordCounter(sentence) self.assertAlmostEqual(expected_ratio, counter.ratio_of(word), delta=0.01)