def test_ddebug_sudoku_random(self): for i in range(10): constraints = create_random_constraints() if test_sudoku(constraints) == 'FAIL': print("run #", i) print(i, "#constraints:", len(constraints)) minimal = delta_debug(constraints, test_sudoku) print(draw_sudoku(constraints)) print(draw_sudoku(minimal)) print(minimal)
def test_ddebug_sudoku_complex(self): constraints = [(1, 1, 1), (2, 1, 2), (3, 1, 3), (4, 2, 1), (5, 2, 2), (6, 2, 3), (7, 3, 7), (8, 3, 8), (9, 3, 9)] minimal = delta_debug(constraints, test_sudoku)
def test_ddebug_sudoku_duplicate_pos(self): constraints = [(1, 1, 9), (1, 1, 8), (8, 8, 7), (2, 2, 5)] minimal = delta_debug(constraints, test_sudoku) self.assertEqual(minimal, [(1, 1, 9), (1, 1, 8)])
def test_ddebug_sudoku(self): constraints = [(1, 1, 9), (1, 2, 3), (8, 8, 7), (2, 2, 9)] minimal = delta_debug(constraints, test_sudoku) self.assertEqual(minimal, [(1, 1, 9), (2, 2, 9)])
def test_ddebug_string(self): s = "this is a long string with a big rat inside" result = delta_debug(s, no_rats) self.assertEqual(result, 'rat')
Sample solution to the Delta Debugging exercise """ from ddebug import delta_debug class AnimalError(Exception): pass def print_animals(names): """Prints animals but only if they get along well""" if 'cat' in names and 'dog' in names: raise (AnimalError()) if 'wolf' in names and 'pig' in names: raise (AnimalError()) if 'anteater' in names and 'ant' in names: raise (AnimalError()) print(';'.join(names)) def test_animals(names): try: print_animals(names) return 'PASS' except AnimalError: return 'FAIL' if __name__ == '__main__': data = ['pig', 'chicken', 'dog', 'anteater', 'wolf', 'piranha'] result = delta_debug(data, test_animals) print("minimal failing set: ", result)
from ddebug import delta_debug from sudoku import draw_sudoku, solve_sudoku def test_sudoku(constraints): try: status, solution = solve_sudoku(constraints) return "PASS" if status == 'Optimal' else "FAIL" except: return "FAIL" if __name__ == '__main__': constraints = [(1,1,9), (1,2,3), (8,8,7), (2,2,9)] #constraints = [(1,1,9), (1,2,3), (8,8,7), (4,2,9), (2,2,9)] #constraints = [(1,1,1), (2,1,2), (3,1,3), (4,2,1), (5,2,2), (6,2,3), (7,3,7), (8,3,8), (9,3,9)] minimal = delta_debug(constraints, test_sudoku) print(draw_sudoku(constraints)) print('minimal failing subset:') print(draw_sudoku(minimal))