def test_get_text_length(self): markov = MarkovChain(order=4) markov.parse("a b c d e f g") output = markov.get_text(length=200) self.assertLessEqual(len(output), 200)
def test_start_words_used(self): # Check that we actually use the start words markov = MarkovChain(order=1) markov.parse("a b c b c b c b c b") output = markov.get_text(1000) if not output.startswith("a"): self.fail("Output did not start with a!")
def test_run_on_bug(self): # There was a bug causing the ends of sentences # to get mauled markov = MarkovChain(order=2) markov.parse("a b a b a b a b a b") output = markov.get_text(1000) self.assertNotIn("ab", output)
def test_get_text_null_input(self): # If we have nothing in _chain then we # want to return an empty string markov = MarkovChain(order=4) self.assertEqual(markov._chain, {}) self.assertEqual(markov._parsed, False) output = markov.get_text() self.assertEqual(output, "")