示例#1
0
class Numbers_1121_Memory2_TestCase(unittest.TestCase):
    '''
    1: 50% -> 1
       50% -> 2
    2: 100% -> 1
    '''

    seqs = [
        [1, 1, 1],
        [1, 1, 2],

        [1, 2, 2],
        [1, 2, 1],
        [1, 2, 1],
        [1, 2, 1],

        [2, 1, 1],
    ]

    def setUp(self):
        random.seed(42)
        self.chain = Chain(memory=2)
        for seq in self.seqs:
            self.chain.train(seq)

    def test_dict(self):
        self.assertEqual(self.chain,
            {(1, 1): [1, 2],
             (1, 2): [2, 1, 1, 1],
             (2, 1): [1]})

    def test_walk_no_start(self):
        self.assertEqual(list(islice(self.chain.walk(), 10)),
                         [2, 1, 1, 1, 2, 1, 1, 1, 1, 1])

    def test_walk_start_11(self):
        self.assertEqual(list(self.chain.walk(start=(1, 1))),
                         [1, 1, 2, 1, 1, 1, 1, 1, 2, 2])

    def test_walk_start_21(self):
        self.assertEqual(list(self.chain.walk(start=(2, 1))),
                         [1, 1, 2, 1, 1, 1, 1, 1, 2, 2])

    def test_walk_start_12(self):
        self.assertEqual(list(self.chain.walk(start=(1, 2))), [2])

    def test_walk_start_22(self):
        self.assertEqual(list(self.chain.walk(start=(2, 2))), [])
示例#2
0
 def test_walk_start_2(self):
     chain = Chain(self.seq)
     self.assertEqual(list(islice(chain.walk(start=2), 10)),
                      [1, 1, 2, 1, 1, 1, 1, 1, 2, 1])
示例#3
0
 def test_walk_no_start(self):
     chain = Chain(self.seq)
     self.assertEqual(list(islice(chain.walk(), 10)), [1, 1, 2])