Esempio n. 1
0
    def test_single_option(self):

        markov = MarkovChain()
        markov._chain = {'START': [Word('A', 1)]}

        for _ in range(1000):
            letter = markov._get_random_word('START')
            self.assertEqual(letter, 'A')
Esempio n. 2
0
    def test_10_1_odds(self):

        markov = MarkovChain()
        markov._chain = {'START': [Word('A', 10), Word('B', 1)]}

        a_count = 0
        b_count = 0
        for _ in range(10000):
            letter = markov._get_random_word('START')

            if letter == 'A':
                a_count += 1
            elif letter == 'B':
                b_count += 1
            else:
                self.fail("Expected 'A' or 'B' got {0}".format(letter))

        self.assertEqual(a_count + b_count, 10000)
        self.assertGreaterEqual(a_count, 9000)