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)))
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)
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")
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)
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)
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)