def test_stores_puzzle_pipe_solvers_and_complete_flag(self): pipes = (objects.Pipe(objects.Cell(0, 0), objects.Cell(1, 1)), objects.Pipe(objects.Cell(2, 2), objects.Cell(1, 2))) puzzle = objects.Puzzle(3, 3, pipes) ps = solver.PuzzleSolver(puzzle) self.assertEqual(2, len(ps.pipe_solvers)) self.assertEqual(True, isinstance(ps.pipe_solvers[0], solver.PipeSolver)) self.assertEqual(True, isinstance(ps.pipe_solvers[1], solver.PipeSolver)) self.assertFalse(ps.complete)
def test_take_only_available_steps_will_solve_puzzle(self): pipes = ( objects.Pipe( objects.Cell(1, 0), objects.Cell(0, 1), ), objects.Pipe(objects.Cell(1, 1), objects.Cell(2, 0)), ) puzzle = objects.Puzzle(3, 2, pipes) ps = solver.PuzzleSolver(puzzle) ps.take_only_available_steps() self.assertTrue(ps.complete)
def test_sizes_and_pipes_set(self): puzzle = objects.Puzzle( 2, 2, [objects.Pipe(objects.Cell(0, 0), objects.Cell(1, 1))]) self.assertEqual(2, puzzle.size_x) self.assertEqual(2, puzzle.size_y) self.assertEqual(0, puzzle.pipes[0].start.x)
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)
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))
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)
def test_start_and_stop_set(self): start = objects.Cell(1, 1) stop = objects.Cell(2, 2) pipe = objects.Pipe(start, stop) self.assertEqual(1, pipe.start.x) self.assertEqual(1, pipe.start.y) self.assertEqual(2, pipe.stop.x) self.assertEqual(2, pipe.stop.y)
def test_take_only_available_steps(self): pipes = (objects.Pipe(objects.Cell(0, 0), objects.Cell(1, 1)), ) puzzle = objects.Puzzle(3, 3, pipes) puzzle.cells[0][1] = True puzzle.cells[2][0] = True ps = solver.PuzzleSolver(puzzle) ps.take_only_available_steps() self.assertEqual(True, ps.pipe_solvers[0].pipe.complete)
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)
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)
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)
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)