def test_number2(): """ 10 should throw an error """ try: load_from_text_file("../DATA/invalidNumber2.txt") except: return assert (False) # should not be reached
def main(): args = parse_arg() sudoku = load_from_text_file(args.filepath) solver = SolverBacktracking(sudoku) solution = solver.solve(sudoku) print('\n'.join( [' '.join([str(cell) for cell in row]) for row in solution]), end="\n\n")
def test_empty(clues_file, Solver): sudoku = load_from_text_file(clues_file) print() print(sudoku) solver = Solver(sudoku) solution = solver.solve() print(solution) assert is_valid_solution(solution) assert respect_clues(sudoku, solution) assert sudoku is not solution
def load_puzzle_from_text_slot(self): filename = QFileDialog.getOpenFileName(self, 'Open File') if filename[0]: array = load_from_text_file(filename[0]) for x in range(9): for y in range(9): v = array[x, y] if (v > 0): self.line_edits[x][y].setText(str(v)) self.line_edits[x][y].setReadOnly(True) self.line_edits[x][y].setFont( QFont("Aria;", 18, QFont.Bold)) else: self.line_edits[x][y].setText("") self.line_edits[x][y].setReadOnly(False) self.line_edits[x][y].setFont(QFont("Aria;", 16))
def test_load(GridStruc): clues = load_from_text_file("../DATA/easy.txt") grid = GridStruc(clues) assert grid.valid(0, 0, 1) == False assert grid.valid(0, 0, 9) == False assert grid.valid(1, 1, 1) == False assert grid.valid(1, 1, 3) == True assert grid[2, 0] == 8 assert grid.valid(2, 0, 8) == False assert grid.valid(2, 0, 7) == True assert grid[0, 2] == 0 assert grid.valid(0, 2, 9) == False assert grid.valid(0, 2, 1) == False assert grid.valid(0, 2, 3) == True
def test_empty(): """ Load an empty sudoku """ result = load_from_text_file("../DATA/empty.txt") assert (result == np.zeros((DIM, DIM), dtype=int)).all()
def _test_size(filepath): try: load_from_text_file(filepath) except: return assert (False) # should not be reached
def test_diag(): """ Load a diagonal matrix """ result = load_from_text_file("../DATA/diag.txt") assert (result == np.diag([e for e in range(1, DIM + 1)])).all()
def test_diag_ones(): """ Load identity matrix """ result = load_from_text_file("../DATA/diag-ones.txt", check_validity=False) assert (result == np.diag(np.ones(DIM, dtype=int))).all()
def test_ones(): result = load_from_text_file("../DATA/ones.txt", check_validity=False) """ Load ones only """ assert (result == np.ones((DIM, DIM), dtype=int)).all()