Created
July 12, 2012 03:26
-
-
Save jtratner/3095486 to your computer and use it in GitHub Desktop.
Fuzzer for CS258 Sudoku Checker
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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))) |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 ;)