def test_board_set_tile_sets_only_tile(): board = Board(empty_tiles(4)) board = set_tile(board, 1, 2, 3) assert board.tiles == [ [0, 0, 0, 0], [0, 0, 0, 0], [0, 3, 0, 0], [0, 0, 0, 0], ]
def test_get_tile_should_error_on_negative_col(): board = Board(empty_tiles(4)) with raises(AttributeError): get_tile(board, -1, 1)
def test_get_tile(): board = Board(empty_tiles(4)) board = set_tile(board, 1, 2, 3) assert get_tile(board, 1, 2) == 3
def test_board_size(): board = Board(empty_tiles(4)) assert board.size == 4
def test_set_tile_should_not_error_on_max_value(): board = Board(empty_tiles(4)) set_tile(board, 0, 0, 4)
def test_set_tile_should_error_on_value_too_high(): board = Board(empty_tiles(4)) with raises(AttributeError): set_tile(board, 0, 0, 5)
def test_empty_tiles_should_fill_all_zero(): assert empty_tiles(3) == [ [0, 0, 0], [0, 0, 0], [0, 0, 0], ]
def test_set_tile_should_error_on_negative_value(): board = Board(empty_tiles(4)) with raises(AttributeError): set_tile(board, 0, 0, -1)
def test_solve_backtrack_empty_board(): board = Board(empty_tiles(9)) _solution, solved = solve_backtrack(board) assert solved
def test_board_should_start_empty(): board = Board(empty_tiles(9)) assert board.tiles == [[0] * 9] * 9
def test_board_error_on_size_not_square_number(): with raises(AttributeError): Board(empty_tiles(12))
def test_board_no_error_when_size_is_square_number(): Board(empty_tiles(81))
def test_get_tile_should_error_on_col_too_high(): board = Board(empty_tiles(4)) with raises(AttributeError): get_tile(board, 4, 1)
def test_post_to_solve_empty_board_should_have_solved_in_response(client: TestClient): response = client.post('/solve', json={'board': empty_tiles(9)}) data = response.json() assert 'solved' in data assert data['solved'] == True