コード例 #1
0
 def testMoveError(self):
     page1 = MazePage(name='1', size=(3, 2), start=(2, 0), goal=(1, 1))
     page2 = MazePage(name='2', size=(3, 2), start=(2, 1), goal=(2, 1))
     page2[2][1].addExit(1, 0)
     
     moves, _ = page1.solve(page2)
     
     self.assertEqual(None, moves)
コード例 #2
0
 def testSolve(self):
     page1 = MazePage(name='1', size=(3, 2), start=(1, 0), goal=(1, 1))
     page2 = MazePage(name='2', size=(3, 2), start=(2, 1), goal=(2, 1))
     page2[2][1].addExit(0, 1)
     
     moves, sidetrack_depth = page1.solve(page2)
     
     self.assertEqual([(page1, 0, 1)], moves)
     self.assertEqual(0, sidetrack_depth)
コード例 #3
0
 def testPartnerSolution(self):
     page1 = MazePage(name='1', size=(3, 2), start=(1, 0), goal=(2, 0))
     page2 = MazePage(name='2', size=(3, 2), start=(2, 1), goal=(2, 0))
     page2[2][1].addExit(1, 0)
     page1[2][0].addExit(0, -1)
     
     moves, _ = page1.solve(page2)
     
     self.assertEqual([(page1, 1, 0), (page2, 0, -1)], moves)
コード例 #4
0
 def testBacktrackSolution(self):
     page1 = MazePage(name='1', size=(3, 2), start=(1, 0), goal=(2, 0))
     page2 = MazePage(name='2', size=(3, 2), start=(2, 1), goal=(2, 1))
     page2[2][1].addExit(0, 1)
     page2[2][1].addExit(1, 0)
     
     moves, _ = page1.solve(page2)
     
     self.assertEqual([(page1, 1, 0)], moves)
コード例 #5
0
 def testSolveTwice(self):
     page1 = MazePage(name='1', size=(3, 2), start=(1, 0), goal=(1, 1))
     page2 = MazePage(name='2', size=(3, 2), start=(2, 1), goal=(2, 1))
     page2[2][1].addExit(0, 1)
     
     page1.solve(page2) # ignore first result
     moves, _ = page1.solve(page2) # repeat the call
     
     self.assertEqual([(page1, 0, 1)], moves)
コード例 #6
0
 def testMove(self):
     page = MazePage(size=(3, 2), start=(1,0))
     page[1][0].addExit(0, 1)
     
     pos1 = page.pos
     page.move(0, 1)
     pos2 = page.pos
       
     self.assertEqual((1,0), pos1)
     self.assertEqual((1,1), pos2)
コード例 #7
0
 def testMutate(self):
     random = DummyRandom(randints={(0, 2): [1],  # x
                                    (0, 3): [2]}, # y
                          choiceIndexes=[3])
     page = MazePage(size=(3, 4), start=(1, 0), goal=(2, 0))
     
     page.mutate(random)
     
     exits = page[1][2].exits
     self.assertEqual(set([(0, -1)]), exits)
コード例 #8
0
 def testCycle(self):
     page1 = MazePage(name='1', size=(2, 2), start=(0, 0), goal=(1, 1))
     page2 = MazePage(name='2', size=(2, 2), start=(0, 0), goal=(1, 1))
     page2[0][0].addExit(1, 0)
     page2[1][0].addExit(-1, 0)
     page1[1][0].addExit(1, 0)
     page1[0][0].addExit(-1, 0)
     
     moves, _ = page1.solve(page2)
     
     self.assertEqual(None, moves)
コード例 #9
0
 def testMultipleSolutionsError(self):
     page1 = MazePage(name='1', size=(2, 2), start=(0, 0), goal=(1, 1))
     page2 = MazePage(name='2', size=(2, 1), start=(0, 0), goal=(1, 0))
     page2[0][0].addExit(0, 1)
     page2[0][0].addExit(1, 0)
     page1[1][0].addExit(1, 0)
     page1[0][1].addExit(1, 0)
     page2[1][0].addExit(0, 1)
     page2[1][0].addExit(1, 0)
     
     with self.assertRaises(MultipleSolutionsError):
         page1.solve(page2)
コード例 #10
0
    def testFormat(self):
        page = MazePage(name='1', size=(3, 2), start=(0, 0), goal=(1, 1))
        page[0][0].addExit(1, 0)
        page[1][0].addExit(-1, 0)
        expectedDisplay = """\
1:
 x Gx  x 
S>  <  x 
"""
        
        display = page.display()
        
        self.assertMultiLineEqual(expectedDisplay, display)