def solve_sudoku_gui(self): self.update_model() position = find_next_empty(self.model) if not position: return True row, col = position for i in range(1, 10): if is_valid(self.model, position, i): self.squares[row][col].set(i) self.update_model() self.squares[row][col].update_drawing(self.window, True) self.draw_matrix_lines() pg.display.update() pg.time.delay(50) if self.solve_sudoku_gui(): return True self.squares[row][col].set(0) self.update_model() self.squares[row][col].update_drawing(self.window, False) self.draw_matrix_lines() pg.display.update() pg.time.delay(50) return False
def specialres(): """ Returns the map page with the best pproposition of restaurants. """ city = request.form['city'] if is_valid(city) == True: res = mappy2(city) if res != None: return res else: return render_template("bestrestaurants.html") else: return render_template("bestrestaurants.html")
def specialhot(): """ Returns the map page with the best proposition of hotel. """ city = request.form['city'] if is_valid(city) == True: res = mappy1(city, 20190708, 20190709) if res != None: return res else: return render_template("besthotels.html") else: return render_template('besthotels.html')
def confirm_position(self): x, y = self.selected_row_col if self.squares[x][y].value == 0: self.squares[x][y].set(self.squares[x][y].temp) self.update_model() else: return True if is_valid(self.board, self.selected_row_col, self.squares[x][y].value) and solve_sudoku(self.model): return True else: self.squares[x][y].set(0) # self.squares[x][y].set_temp(0) self.update_model() return False
def test_is_valid(self): assert is_valid(self.matrix, 0, 1) == True assert is_valid(self.matrix, 2, 2) == False
def test_invalid_passwords(self, password): self.assertFalse(main.is_valid(password))
def test_4(self): res = is_valid("1:210214:[email protected]:7e20bbffa3f1df5e", "210214", "*****@*****.**", 16) self.assertFalse(res, "Correctly rejects insufficient difficulty")
def test_1(self): self.assertIsInstance( is_valid("1:210214:[email protected]:32572a910499e4b8", "210214", "*****@*****.**", 16), bool, "is_valid must return a boolean")
def test_2(self): res = is_valid("1:210214:[email protected]:32572a910499e4b8", "210214", "*****@*****.**", 16) self.assertTrue(res, "Correctly validates a valid hashcash")
def test_3(self): res = is_valid("1:210214:[email protected]:32572a910499e4b8", "210214", "*****@*****.**", 16) self.assertFalse(res, "Correctly rejects a manipulated email")
from main import is_valid valid_passwords = 0 for password in range(123257, 647015): if is_valid(str(password)): valid_passwords += 1 print(f"Number of valid passwords: {valid_passwords}")
def test_is_valid_only_doubles(password, expected_valid): assert is_valid(password, exact_double=True) == expected_valid
def test_is_valid(password, expected_valid): assert is_valid(password) == expected_valid
def _valid_messages(self): return {msg for msg in self.messages if is_valid(msg, self.rules)}
def test_is_valid(): assert is_valid([[1, 1, 0]], (0, 0), (1, 0), (2, 0))