Skip to content

Instantly share code, notes, and snippets.

@jtratner
Created July 12, 2012 03:26
Show Gist options
  • Select an option

  • Save jtratner/3095486 to your computer and use it in GitHub Desktop.

Select an option

Save jtratner/3095486 to your computer and use it in GitHub Desktop.
Fuzzer for CS258 Sudoku Checker
def fuzzer_for_sudoku_checker(sudoku_checker):
""" given `sudoku_checker` a sudoku checker function, attempts to ferret out common issues with checking
for valid input. Raises AssertionError s if the function fails to conform to expectations"""
try:
illegal = (0, [], range(10), [range(10), range(10), 0, range(10), 1, range(10), range(10), range(10), range(10)])
valid_row = range(1, 10)
invalid = ([[1]*9] * 9, [valid_row * 8] + [range(2, 11)])
for s in illegal:
res = sudoku_checker(s)
assert res is None, "Failed to detect that {s} was illegal. Returned {res} instead of `None`".format(s=s, res=res)
for s in invalid:
res = sudoku_checker(s)
assert res is False, "Failed to return False for invalid sudoku {s}. Returned {res} instead of `False`".format(s=s, res=res)
except AssertionError:
raise
except Exception as e:
raise AssertionError("Raised error type {etype} with msg {emsg}.".format(etype=type(e), emsg=str(e)))
@jtratner
Copy link
Copy Markdown
Author

I added it to the repo I made for this (put an argparse wrapper around it so you could run it more easily) jtratner/sudoku-fuzzer-udacity@9017adf . It's a neat case ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment