def test_random_walk(self): '''The sentence generated follows the Markov Chain algorithm.''' fish_list = [ "one", "fish", "two", "fish", "red", "fish", "blue", "fish" ] mark = MarkovChain(fish_list) # store a list of words generated by a random walk sentence = mark.random_walk().split() for i in range(len(sentence) - 1): word = sentence[i] word_after = sentence[i + 1] # make sure that word_after is allowed to come after the word states_that_come_next = list(mark.chain[word].keys()) assert word_after in states_that_come_next