예제 #1
0
class SingleMissingValueSudokuTests(TestCase):
    def setUp(self):
        self.solver = SudokuSolver(SOLUTION_WITHOUT_ONE_VALUE)

    def test_row_incomplete(self):
        self.assertFalse(self.solver.is_row_filled_in(0))

    def test_square_incomplete(self):
        self.assertFalse(self.solver.is_square_filled_in(0))

    def test_solution_for_row(self):
        self.assertTrue((self.solver.solution_for_row(0) == numpy.matrix(SOLUTION[0:17])).all())

    def test_solution_for_column(self):
        expected = numpy.matrix(SOLUTION)
        self.assertTrue((self.solver.solution_for_column(0) == expected[:, 0]).all())

    def test_column_incomplete(self):
        self.assertFalse(self.solver.is_column_filled_in(0))

    def test_solution_for_square(self):
        solution = numpy.matrix(SOLUTION)
        self.assertTrue((self.solver.solution_for_square(0) == solution[(0, 1, 2), :][:, (0, 1, 2)]).all())
예제 #2
0
파일: main.py 프로젝트: bram1et/sdku
        quit()
    else:
        input_info = InputInformation(sys.argv)

    try:
        input_file = open(input_info.input_file, "r")
        output_file = open(input_info.output_file, "w")
    except:
        print("Error opening file. Quitting...")
        quit()

    file_reader = FileReader(input_file)
    file_writer = FileWriter(output_file)
    N, P, Q, = file_reader.get_params()
    board = file_reader.get_board()
    sudoku_board = SudokuSolver(N, P, Q, board, input_info.tokens)
    info.search_start = time.time()
    sudoku_board.start_time = info.search_start
    sudoku_board.time_out_limit = float(input_info.timeout_limit)

    if False:
        sudoku_board.heap_test()
    else:
        if input_info.tokens["LCV"]:
            solved_board = sudoku_board.solve_board_value_heap(False)
        else:
            solved_board = sudoku_board.solve_board_heap(False)
        info.search_done = time.time()
        if solved_board is not None:
            if solved_board.solved:
                info.status = info.status_types["s"]
예제 #3
0
        quit()
    else:
        input_info = InputInformation(sys.argv)

    try:
        input_file = open(input_info.input_file, 'r')
        output_file = open(input_info.output_file, 'w')
    except:
        print('Error opening file')
        quit()

    file_reader = FileReader(input_file)
    file_writer = FileWriter(output_file)
    N, P, Q,  = file_reader.get_params()
    board = file_reader.get_board()
    sudoku_board =  SudokuSolver(N, P, Q, board)
    info.search_start = time.time()
    sudoku_board.start_time = info.search_start
    sudoku_board.time_out_limit = float(input_info.timeout_limit)
    solved_board = sudoku_board.solve_board()
    info.search_done = time.time()
    if solved_board is not None:
        if solved_board.solved:
            info.status = info.status_types["s"]
            info.solution = solved_board.board_to_output()
        else:
            info.status = info.status_types["t"]
            info.count_nodes = solved_board.nodes_created
            info.count_deadends = solved_board.times_backtracked
            info.solution = info.generate_empty_board(N)
    else:
예제 #4
0
 def setUp(self):
     self.solver = SudokuSolver(SOLUTION_WITHOUT_ONE_VALUE)
예제 #5
0
 def setUp(self):
     self.solver = SudokuSolver(SOLUTION)
예제 #6
0
class CompleteSudokuTests(TestCase):
    def setUp(self):
        self.solver = SudokuSolver(SOLUTION)

    def test_solved_solution(self):
        self.assertTrue(numpy.array_equal(self.solver.solution(), numpy.matrix(SOLUTION)))

    def test_row_complete(self):
        self.assertTrue(self.solver.is_row_filled_in(0))

    def test_column_complete(self):
        self.assertTrue(self.solver.is_column_filled_in(0))

    def test_square_fetch(self):
        self.assertTrue(numpy.array_equal(self.solver.fetch_square(0), numpy.matrix(SQUARE0)))

    def test_square_array_slice(self):
        """testing for slice of main sudoku square that gets returned. maps to the square"""
        _slice = self.solver.coordinates_for_square(0)
        self.assertEqual(_slice['row'], (0, 1, 2))
        self.assertEqual(_slice['col'], (0, 1, 2))

        _slice = self.solver.coordinates_for_square(1)
        self.assertEqual(_slice['row'], (0, 1, 2))
        self.assertEqual(_slice['col'], (3, 4, 5))

        _slice = self.solver.coordinates_for_square(2)
        self.assertEqual(_slice['row'], (0, 1, 2))
        self.assertEqual(_slice['col'], (6, 7, 8))

        _slice = self.solver.coordinates_for_square(3)
        self.assertEqual(_slice['row'], (3, 4, 5))
        self.assertEqual(_slice['col'], (0, 1, 2))

        _slice = self.solver.coordinates_for_square(4)
        self.assertEqual(_slice['row'], (3, 4, 5))
        self.assertEqual(_slice['col'], (3, 4, 5))

        _slice = self.solver.coordinates_for_square(5)
        self.assertEqual(_slice['row'], (3, 4, 5))
        self.assertEqual(_slice['col'], (6, 7, 8))

        _slice = self.solver.coordinates_for_square(6)
        self.assertEqual(_slice['row'], (6, 7, 8))
        self.assertEqual(_slice['col'], (0, 1, 2))

        _slice = self.solver.coordinates_for_square(7)
        self.assertEqual(_slice['row'], (6, 7, 8))
        self.assertEqual(_slice['col'], (3, 4, 5))

        _slice = self.solver.coordinates_for_square(8)
        self.assertEqual(_slice['row'], (6, 7, 8))
        self.assertEqual(_slice['col'], (6, 7, 8))

    def test_square_complete(self):
        self.assertTrue(self.solver.is_square_filled_in(0))

    def test_solution_for_row(self):
        self.assertTrue((self.solver.solution_for_row(0) == numpy.matrix(SOLUTION[0:17])).all())

    def test_solution_for_column(self):
        solution = numpy.matrix(SOLUTION)
        self.assertTrue((self.solver.solution_for_column(0) == solution[:, 0]).all())

    def test_solution_for_square(self):
        solution = numpy.matrix(SOLUTION)
        self.assertTrue((self.solver.solution_for_square(0) == solution[(0, 1, 2), :][:, (0, 1, 2)]).all())
예제 #7
0
 def setUp(self):
     self.solver = SudokuSolver(SOLUTION_WITHOUT_TWO_VALUES_IN_ROW)