Esempio n. 1
0
 def test_random_search(self):
     print('\nTests random search for a single block')
     block = BlockImage(1, 1)
     self.assertEqual(block.get_face(), 1)
     self.assertEqual(block.get_pattern(),
                      BlockPattern.BlackTopRightCornerSquare)
     random_search(block, BlockPattern.WhiteSquare, [])
     self.assertEqual(block.get_pattern(), BlockPattern.WhiteSquare)
Esempio n. 2
0
 def test_beeline_search_complex(self):
     print('\nTests beeline search, complex sequence')
     actions = beeline_search(BlockImage(3),
                              BlockPattern.BlackTopLeftCornerSquare, [])
     block = BlockImage(3)
     self.assertEqual(block.get_pattern(), BlockPattern.WhiteSquare)
     self.assertTrue(len(actions) == 2)
     for action in actions:
         block.execute_action(action)
     self.assertEqual(block.get_pattern(),
                      BlockPattern.BlackTopLeftCornerSquare)
Esempio n. 3
0
 def test_memory_search(self):
     print('\nTests memory search')
     actions = memory_search(BlockImage(),
                             BlockPattern.BlackTopLeftCornerSquare, [])
     block = BlockImage()
     visited = [(block.get_face(), block.get_pattern())]
     for action in actions:
         block.execute_action(action)
         visited.append((block.get_face(), block.get_pattern()))
     self.assertEqual(block.get_pattern(),
                      BlockPattern.BlackTopLeftCornerSquare)
     self.assertEqual(len(visited), len(set(visited)))
Esempio n. 4
0
 def test_random_search(self):
     print('\nTests random search')
     actions = random_search(BlockImage(),
                             BlockPattern.BlackTopLeftCornerSquare, [])
     block = BlockImage()
     for action in actions:
         block.execute_action(action)
     self.assertEqual(block.get_pattern(),
                      BlockPattern.BlackTopLeftCornerSquare)
Esempio n. 5
0
    def test_invalid_sequence(self):
        print('\nTests invalid block sequence')
        block = BlockImage()
        self.assertEqual(block.get_face(), 1)
        self.assertEqual(block.get_pattern(),
                         BlockPattern.BlackTopRightCornerSquare)

        with self.assertRaises(Exception) as context:
            block.execute_action(BlockAction.GoToFaceSix)
        self.assertEqual(str(context.exception), "Can't go from 1 to 6")
Esempio n. 6
0
    def test_simple_sequence_one(self):
        print('\nTests simple block sequence one')
        block = BlockImage()
        self.assertEqual(block.get_face(), 1)
        self.assertEqual(block.get_pattern(),
                         BlockPattern.BlackTopRightCornerSquare)

        block.execute_action(BlockAction.GoToFaceFour)
        self.assertEqual(block.get_face(), 4)
        self.assertEqual(block.get_pattern(), BlockPattern.BlackSquare)

        block.execute_action(BlockAction.GoToFaceFive)
        self.assertEqual(block.get_face(), 5)
        self.assertEqual(block.get_pattern(), BlockPattern.BlackSquare)

        block.execute_action(BlockAction.GoToFaceOne)
        self.assertEqual(block.get_face(), 1)
        self.assertEqual(block.get_pattern(),
                         BlockPattern.BlackTopRightCornerSquare)
Esempio n. 7
0
    def test_simple_sequence_two(self):
        print('\nTests simple sequence two')
        block = BlockImage()
        self.assertEqual(block.get_face(), 1)
        self.assertEqual(block.get_pattern(),
                         BlockPattern.BlackTopRightCornerSquare)

        block.execute_action(BlockAction.RotateRight)
        self.assertEqual(block.get_face(), 1)
        self.assertEqual(block.get_pattern(),
                         BlockPattern.BlackBottomRightCornerSquare)

        block.execute_action(BlockAction.GoToFaceFour)
        self.assertEqual(block.get_face(), 4)
        self.assertEqual(block.get_pattern(), BlockPattern.BlackSquare)

        block.execute_action(BlockAction.GoToFaceSix)
        self.assertEqual(block.get_face(), 6)
        self.assertEqual(block.get_pattern(),
                         BlockPattern.BlackBottomLeftCornerSquare)
Esempio n. 8
0
    def test_beeline_search_rotations(self):
        print('\nTests beeline search, rotations')
        actions = beeline_search(BlockImage(),
                                 BlockPattern.BlackTopLeftCornerSquare, [])
        block = BlockImage()
        self.assertEqual(block.get_pattern(),
                         BlockPattern.BlackTopRightCornerSquare)
        self.assertEqual(len(actions), 1)
        block.execute_action(actions[0])
        self.assertEqual(block.get_pattern(),
                         BlockPattern.BlackTopLeftCornerSquare)

        actions = beeline_search(BlockImage(),
                                 BlockPattern.BlackBottomLeftCornerSquare, [])
        block = BlockImage()
        self.assertEqual(block.get_pattern(),
                         BlockPattern.BlackTopRightCornerSquare)
        # Since beeline search is somewhat stochastic, these test rely on heuristics
        self.assertEqual(len(actions), 2)
        for action in actions:
            block.execute_action(action)
        self.assertEqual(block.get_pattern(),
                         BlockPattern.BlackBottomLeftCornerSquare)
Esempio n. 9
0
 def test_peek(self):
     print('\nTests peek')
     block = BlockImage(6)
     self.assertEqual(block.get_pattern(),
                      BlockPattern.BlackBottomRightCornerSquare)
     self.assertEqual(block.peek_action(BlockAction.RotateRight),
                      (6, BlockPattern.BlackBottomLeftCornerSquare))
     self.assertEqual(block.peek_action(BlockAction.RotateLeft),
                      (6, BlockPattern.BlackTopRightCornerSquare))
     self.assertEqual(block.peek_action(BlockAction.GoToFaceThree),
                      (3, BlockPattern.WhiteSquare))
     with self.assertRaises(Exception) as context:
         block.peek_action(BlockAction.GoToFaceOne)
     self.assertEqual(
         str(context.exception),
         "Invalid action BlockAction.GoToFaceOne for " +
         "Block,1,Face,6,Pattern,BlackBottomRightCornerSquare")
Esempio n. 10
0
    def test_complex_sequence(self):
        print('\nTests block complex sequence')
        block = BlockImage()
        self.assertEqual(block.get_face(), 1)
        self.assertEqual(block.get_pattern(),
                         BlockPattern.BlackTopRightCornerSquare)

        block.execute_action(BlockAction.GoToFaceFour)
        self.assertEqual(block.get_face(), 4)
        self.assertEqual(block.get_pattern(), BlockPattern.BlackSquare)

        block.execute_action(BlockAction.GoToFaceThree)
        self.assertEqual(block.get_face(), 3)
        self.assertEqual(block.get_pattern(), BlockPattern.WhiteSquare)

        block.execute_action(BlockAction.RotateRight)
        self.assertEqual(block.get_face(), 3)
        self.assertEqual(block.get_pattern(), BlockPattern.WhiteSquare)

        block.execute_action(BlockAction.GoToFaceOne)
        self.assertEqual(block.get_face(), 1)
        self.assertEqual(block.get_pattern(),
                         BlockPattern.BlackBottomRightCornerSquare)

        block.execute_action(BlockAction.GoToFaceFive)
        self.assertEqual(block.get_face(), 5)
        self.assertEqual(block.get_pattern(), BlockPattern.BlackSquare)

        block.execute_action(BlockAction.GoToFaceSix)
        self.assertEqual(block.get_face(), 6)
        self.assertEqual(block.get_pattern(),
                         BlockPattern.BlackBottomLeftCornerSquare)

        block.execute_action(BlockAction.RotateRight)
        self.assertEqual(block.get_face(), 6)
        self.assertEqual(block.get_pattern(),
                         BlockPattern.BlackTopLeftCornerSquare)

        block.execute_action(BlockAction.GoToFaceThree)
        self.assertEqual(block.get_face(), 3)
        self.assertEqual(block.get_pattern(), BlockPattern.WhiteSquare)

        block.execute_action(BlockAction.GoToFaceOne)
        self.assertEqual(block.get_face(), 1)
        self.assertEqual(block.get_pattern(),
                         BlockPattern.BlackBottomLeftCornerSquare)

        block.execute_action(BlockAction.RotateLeft)
        self.assertEqual(block.get_face(), 1)
        self.assertEqual(block.get_pattern(),
                         BlockPattern.BlackBottomRightCornerSquare)