[pypy-svn] r33319 - pypy/dist/pypy/objspace/test

auc at codespeak.net auc at codespeak.net
Mon Oct 16 11:13:23 CEST 2006


Author: auc
Date: Mon Oct 16 11:13:21 2006
New Revision: 33319

Modified:
   pypy/dist/pypy/objspace/test/test_logicobjspace.py
Log:
recompute everything nqueens test


Modified: pypy/dist/pypy/objspace/test/test_logicobjspace.py
==============================================================================
--- pypy/dist/pypy/objspace/test/test_logicobjspace.py	(original)
+++ pypy/dist/pypy/objspace/test/test_logicobjspace.py	Mon Oct 16 11:13:21 2006
@@ -793,9 +793,10 @@
         
         
     def test_default_solver(self):
+        skip("segfaulting")
         if is_interpreted():
             skip("will loop infinitely (bug in space.clone())")
-        from problem import conference_scheduling
+        from constraint.examples import conference_scheduling
         from constraint import solver
 
         s = newspace(conference_scheduling)
@@ -807,6 +808,7 @@
 
 
     def test_recomputing_solver(self):
+        skip("segfaulting")
         if is_interpreted():
             skip("interpreted clone support still missing")
         from problem import conference_scheduling
@@ -866,14 +868,54 @@
                 unify(Sol, False)
 
         def lazily(lst):
-            def _():
-                for e in lst:
-                    yield e
-            return _
+            for e in lst:
+                yield e
 
         for commit_to in (lazily([1, 1, 1, 1, 1, 1]),
                           lazily([1, 1, 1, 2, 1, 2])):
             s = newspace(suit)
             Solution = newvar()
-            stacklet(solve, s, commit_to(), Solution)
+            solve(s, commit_to, Solution)
             assert Solution in (False, ('beige', 'mauve', 'coral'))
+
+    def test_queens1(self):
+        if not is_interpreted():
+            skip("segfaulting")
+        from constraint.examples import queens1, queens2
+
+        def solve(spc, commitment, Sol):
+            while 1:
+                status = spc.ask()
+                if status > 1:
+                    spc.commit(commitment.next())
+                elif status in (0, 1):
+                    break
+            if status:
+                unify(Sol, spc.merge())
+            else:
+                unify(Sol, False)
+
+        def lazily(lst):
+            for e in lst:
+                yield e
+
+        def all_paths(length):
+            number = 2 ** length
+            for i in range(number):
+                res = []
+                k = i
+                for j in range(length):
+                    res.append((k & 1) + 1)
+                    k = k >> 1
+                yield res
+
+        for queen in (queens1, queens2):
+            sols = set()
+            for commitment in all_paths(3):
+                s = newspace(queen, 4)
+                Solution = newvar()
+                commit = lazily(commitment)
+                solve(s, commit, Solution)
+                if Solution:
+                    sols.add(tuple(Solution))
+            assert len(sols) == 2



More information about the Pypy-commit mailing list