Added a test for puzzles with diagonal constraints.
authorEevee <eevee@nyarumaa.(none)>
Wed, 7 Jan 2009 14:54:16 +0000 (09:54 -0500)
committerEevee <eevee@nyarumaa.(none)>
Wed, 7 Jan 2009 14:54:16 +0000 (09:54 -0500)
Created a TestCase subclass to use for tests, too.

pseudoku/__init__.py
pseudoku/tests/__init__.py
pseudoku/tests/constraints/__init__.py [new file with mode: 0644]
pseudoku/tests/constraints/diagonal.py [new file with mode: 0644]
pseudoku/tests/integrity/simple.py

index c7a803b..33fe0b5 100644 (file)
@@ -3,24 +3,4 @@ from grid.constraints import Diagonal
 import render.text
 
 def main():
 import render.text
 
 def main():
-    grid = Grid.from_string("""
-        3...2...7
-        ...3.1...
-        ..6...4..
-        89.....54
-        4...5...8
-        61.....32
-        ..8...2..
-        ...5.9...
-        1...6...9
-    """)
-
-    grid.add_constraint(Diagonal(grid, direction='down', offset=0))
-    grid.add_constraint(Diagonal(grid, direction='up', offset=0))
-
-    r = render.text.AsciiArtGridRenderer()
-    print r.render_grid(grid)
-
-    grid.solve()
-
-    print r.render_grid(grid)
+    print "I don't do anything any more!"
index e69de29..3821889 100644 (file)
@@ -0,0 +1,21 @@
+from unittest import TestCase
+
+from pseudoku.grid import Grid
+
+class SudokuTestCase(TestCase):
+    """TestCase subclass that provides some convenience methods for testing
+    sudoku puzzles.
+    """
+    
+    def assertSolvable(self, grid, msg=None):
+        """Asserts that the given puzzle, when run through Grid.solve(),
+        produces a filled grid.
+
+        grid may be either a Grid object or a string.
+        """
+
+        if type(grid) == str:
+            grid = Grid.from_string(grid)
+
+        grid.solve()
+        self.assertTrue(grid.filled, msg)
diff --git a/pseudoku/tests/constraints/__init__.py b/pseudoku/tests/constraints/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/pseudoku/tests/constraints/diagonal.py b/pseudoku/tests/constraints/diagonal.py
new file mode 100644 (file)
index 0000000..c118339
--- /dev/null
@@ -0,0 +1,18 @@
+from pseudoku.grid import Grid
+from pseudoku.grid.constraints import Diagonal
+
+from pseudoku.tests import SudokuTestCase
+
+class DiagonalGridTestCase(SudokuTestCase):
+    """Tests that grids with extra non-standard constraints are solved."""
+
+
+    def test_main_diagonals(self):
+        grid = Grid.from_string("""
+            3...2...7 ...3.1...  ..6...4..
+            89.....54 4...5...8 61.....32
+            ..8...2..  ...5.9...  1...6...9
+        """)
+        grid.add_constraint(Diagonal(grid, direction='down', offset=0))
+        grid.add_constraint(Diagonal(grid, direction='up', offset=0))
+        self.assertSolvable(grid, "Main diagonals (Color Sudoku, page 8)")
index 9558ba3..48cde80 100644 (file)
@@ -1,23 +1,14 @@
-from unittest import TestCase
-
 from pseudoku.grid import Grid
 
 from pseudoku.grid import Grid
 
-class SimpleGridTestCase(TestCase):
+from pseudoku.tests import SudokuTestCase
+
+class SimpleGridTestCase(SudokuTestCase):
     """Tests the solving integrity of some puzzles that can be solved using
     only elimination and uniqueness.
     """
 
     """Tests the solving integrity of some puzzles that can be solved using
     only elimination and uniqueness.
     """
 
-    def _test_single_puzzle(self, puzzle, msg=None):
-        """Solves a single puzzle and verifies that the result is, at least,
-        not incorrect.
-        """
-        
-        grid = Grid.from_string(puzzle)
-        grid.solve()
-        self.assertTrue(grid.filled, msg)
-
     def test_simple(self):
     def test_simple(self):
-        self._test_single_puzzle("""
+        self.assertSolvable("""
             ...69.... 9.5..876. ..4..1.2.
             6...5...3 38.....49 7...3...2
             .7.9..3.. .231..4.8 ....83...
             ...69.... 9.5..876. ..4..1.2.
             6...5...3 38.....49 7...3...2
             .7.9..3.. .231..4.8 ....83...