Пример #1
0
 def test_simple_map(self):
     text_file = Maze.open_map('Tests/simple_test.txt')
     lb = Maze(None, text_file)
     path = solve_maze(lb, 0)
     bombs_used = path.pop(0)
     self.assertEqual(bombs_used, 1)
     self.assertEqual(len(path), 9)
Пример #2
0
 def test_portals(self):
     text_file = Maze.open_map(wall_maze)
     lb = Maze(None, text_file)
     lb.portals = [[(4, 1), (34, 1)]]
     lb.bombs = 0
     path = solve_maze(lb, 0)
     path.pop(0)
     self.assertEqual(len(path), 7)
Пример #3
0
    def create_maze_widget(self):
        if self.params_dialog.file:
            maze = Maze(None, self.params_dialog.file)
        else:
            maze = Maze(self.params_dialog.settings)
        self.mazeWidget = MazeWidget(maze, self)
        self.layout.addWidget(self.mazeWidget, 1, 0)

        self.update_window()
Пример #4
0
 def test_one_way_walls(self):
     text_file = Maze.open_map(wall_maze)
     lb = Maze(None, text_file)
     #  instead of wall we have one-way wall
     lb[5][1] = lb.EMPTY
     lb.one_way_walls.append((5, 1, Directions.right))
     path = solve_maze(lb, 0)
     bombs_used = path.pop(0)
     self.assertEqual(bombs_used, 1)  # we have wall, but don't use bombs
     self.assertEqual(len(path), 38)
Пример #5
0
 def test_alpha(self):
     text_file = Maze.open_map('Tests/test_alpha.txt')
     lb = Maze(None, text_file)
     path = solve_maze(lb, 0)  # ALPHA = 0
     bombs_used = path.pop(0)
     self.assertEqual(bombs_used, lb.bombs)
     self.assertEqual(len(path), 38)  # Used all bombs, shorter path
     path = solve_maze(lb, 100)  # ALPHA = 100
     bombs_used = path.pop(0)
     self.assertEqual(bombs_used, 0)  # 0 bombs used, longest path
     self.assertEqual(len(path), 44)
Пример #6
0
 def open_map(self):
     directory = os.path.abspath(
         os.path.join(os.path.dirname(__file__), '../..', 'Resources'))
     openfile = QtWidgets.QFileDialog.getOpenFileName(
         self, "Open File", directory, "Text files(*.txt)")[0]
     if openfile:
         self.file = Maze.open_map(openfile)
         self.accepted.emit()
         self.hide()
Пример #7
0
 def test_incorrect_maze_params(self):
     text_file = Maze.open_map(straight_maze)
     lb = Maze(None, text_file)
     lb.start = None
     lb.finishes = [None]
     lb.bombs = -1
     self.assertRaises(ValueError, lambda: solve_maze(lb, 0))
Пример #8
0
    def test_2_finishes(self):
        text_file = Maze.open_map(wall_maze)
        lb = Maze(None, text_file)
        lb.finishes = [(1, 1), (38, 1)]

        lb.start = (20, 1)
        path = solve_maze(lb, 0)
        path.pop(0)
        self.assertEqual(path[-1], (38, 1))  # second finish is closer

        lb.start = (15, 1)
        path = solve_maze(lb, 0)
        path.pop(0)
        self.assertEqual(path[-1], (1, 1))  # first finish is closer
Пример #9
0
 def test_maze_params(self):
     lb = Maze((25, 25, 25))
     self.assertEqual(lb.width, 27)  # 25+2 because I create frame
     self.assertEqual(lb.height, 27)
     self.assertEqual(lb.scale, 25)
Пример #10
0
 def test_file_save(self):
     text_file = Maze.open_map(straight_maze)
     lb = Maze(None, text_file)
     lb.save_map('Tests/saved_straight_maze.txt')
     new_text_file = Maze.open_map('Tests/saved_straight_maze.txt')
     self.assertEqual(text_file, new_text_file)
Пример #11
0
 def test_maze_wall(self):
     text_file = Maze.open_map(wall_maze)
     lb = Maze(None, text_file)
     path = solve_maze(lb, 0)
     path.pop(0)
     self.assertEqual(len(path), 38)
Пример #12
0
 def test_maze_wall_no_bombs(self):
     text_file = Maze.open_map(no_bombs_maze)
     lb = Maze(None, text_file)
     path = solve_maze(lb, 0)
     self.assertEqual(None, path)
Пример #13
0
 def test_maze_straight_line(self):
     text_file = Maze.open_map(straight_maze)
     lb = Maze(None, text_file)
     path = solve_maze(lb, 0)
     path.pop(0)
     self.assertEqual(len(path), 38)