예제 #1
0
    def test_one_step_available(self):
        pipe = objects.Pipe(objects.Cell(0, 0), objects.Cell(2, 2))
        puzzle = objects.Puzzle(3, 3, [pipe])
        puzzle.cells[0][1] = True
        ps = solver.PipeSolver(puzzle, pipe)
        ps.take_only_available_steps()

        self.assertEqual(1, len(ps.pipe.steps))
예제 #2
0
    def test_uses_start_cell(self):
        pipe = objects.Pipe(objects.Cell(0, 0), objects.Cell(1, 1))
        puzzle = objects.Puzzle(3, 3, [pipe])
        ps = solver.PipeSolver(puzzle, pipe)
        cell = ps.get_current_cell()

        self.assertEqual(0, cell.x)
        self.assertEqual(0, cell.y)
예제 #3
0
    def test_two_steps_available(self):
        # should return the same pipe since there isn't just one optional step
        pipe = objects.Pipe(objects.Cell(0, 0), objects.Cell(2, 2))
        puzzle = objects.Puzzle(3, 3, [pipe])
        ps = solver.PipeSolver(puzzle, pipe)
        ps.take_only_available_steps()

        self.assertEqual(pipe, ps.pipe)
예제 #4
0
    def test_complete_the_pipe(self):
        pipe = objects.Pipe(objects.Cell(0, 0), objects.Cell(1, 1))
        puzzle = objects.Puzzle(3, 3, [pipe])
        puzzle.cells[0][1] = True
        puzzle.cells[2][0] = True
        ps = solver.PipeSolver(puzzle, pipe)
        ps.take_only_available_steps()

        self.assertEqual(1, len(ps.pipe.steps))
        self.assertEqual(True, ps.pipe.complete)
예제 #5
0
    def test_one_possible_move_in_the_corner(self):
        pipe = objects.Pipe(objects.Cell(0, 0), objects.Cell(1, 1))
        puzzle = objects.Puzzle(3, 3, [pipe])
        puzzle.cells[0][1] = True
        ps = solver.PipeSolver(puzzle, pipe)
        moves = ps.get_possible_next_moves()

        self.assertEqual(1, len(moves))
        self.assertEqual(1, moves[0].x)
        self.assertEqual(0, moves[0].y)
예제 #6
0
    def test_three_possible_moves_on_a_side(self):
        pipe = objects.Pipe(objects.Cell(0, 1), objects.Cell(2, 2))
        puzzle = objects.Puzzle(3, 3, [pipe])
        ps = solver.PipeSolver(puzzle, pipe)
        moves = ps.get_possible_next_moves()

        self.assertEqual(3, len(moves))
        self.assertEqual(1, moves[0].x)
        self.assertEqual(1, moves[0].y)
        self.assertEqual(0, moves[1].x)
        self.assertEqual(2, moves[1].y)
        self.assertEqual(0, moves[2].x)
        self.assertEqual(0, moves[2].y)
예제 #7
0
    def test_four_possible_moves_including_stop(self):
        pipe = objects.Pipe(objects.Cell(1, 1), objects.Cell(1, 0))
        puzzle = objects.Puzzle(4, 4, [pipe])
        ps = solver.PipeSolver(puzzle, pipe)
        moves = ps.get_possible_next_moves()

        self.assertEqual(4, len(moves))
        self.assertEqual(2, moves[0].x)
        self.assertEqual(1, moves[0].y)
        self.assertEqual(1, moves[1].x)
        self.assertEqual(2, moves[1].y)
        self.assertEqual(0, moves[2].x)
        self.assertEqual(1, moves[2].y)
        self.assertEqual(1, moves[3].x)
        self.assertEqual(0, moves[3].y)