Permalink
Browse files

Include Norvig's tests

  • Loading branch information...
1 parent a7ce8ff commit f55ce534c1595b04ba8d97bbb5c719cbd3fa77c7 Andreas Pauley committed Feb 27, 2011
Showing with 15 additions and 0 deletions.
  1. +15 −0 sudoku.py
View
@@ -160,7 +160,22 @@ def solve_file(filename, sep='\n'):
outfile = os.path.splitext(filename)[0] + '.out'
to_file(outfile, solutions)
+def test():
+ "A set of tests that must pass."
+ assert len(squares) == 81
+ assert len(unitlist) == 27
+ assert all(len(units[s]) == 3 for s in squares)
+ assert all(len(peers[s]) == 20 for s in squares)
+ assert units['C2'] == [['A2', 'B2', 'C2', 'D2', 'E2', 'F2', 'G2', 'H2', 'I2'],
+ ['C1', 'C2', 'C3', 'C4', 'C5', 'C6', 'C7', 'C8', 'C9'],
+ ['A1', 'A2', 'A3', 'B1', 'B2', 'B3', 'C1', 'C2', 'C3']]
+ assert peers['C2'] == set(['A2', 'B2', 'D2', 'E2', 'F2', 'G2', 'H2', 'I2',
+ 'C1', 'C3', 'C4', 'C5', 'C6', 'C7', 'C8', 'C9',
+ 'A1', 'A3', 'B1', 'B3'])
+ print 'All tests pass.'
+
if __name__ == '__main__':
+ test()
solve_file("easy50.txt", '========')
solve_file("top95.txt")
solve_file("hardest.txt")

0 comments on commit f55ce53

Please sign in to comment.