Example #1
0
 def test_cut2(self):
     a, b, c, x = Var('a'), Var('b'), Var('c'), Var('x')
     Lx = LogicVar('x')
     assert_raises(
         NoSolution, eval,
         letrec([(a, rules([[x], begin(b(x), cut, c(x))])),
                 (b, rules([[1], True], [[2], True], [[3], True])),
                 (c, rules([[2], True]))], a(Lx), getvalue(Lx)))
Example #2
0
 def testCut1(self):
     a, b, c, x = Var('a'), Var('b'), Var('c'), Var('x')
     Lx = LogicVar('x')
     eq_(
         eval(
             letrec([(a, rules([[x], begin(b(x), cut, c(x))])),
                     (b, rules([[1], True], [[2], True], [[3], True])),
                     (c, rules([[1], True]))], a(Lx), getvalue(Lx))), 1)
Example #3
0
 def testCut4(self):
     a, b, c, d, x = Var('a'), Var('b'), Var('c'), Var('d'), Var('x'),
     Lx = LogicVar('x')
     assert_raises(
         NoSolution, eval,
         letrec([(a, rules([[x], begin(b(x), cut, c(x))], [[x], d(x)])),
                 (b, rules([[1], 'b1'], [[4], 'b4'])),
                 (c, rules([[4], 'c4'])), (d, rules([[3], 'd3']))], a(Lx),
                getvalue(Lx)))
Example #4
0
 def test_cut2_no_Cut3_begin(self):
     a, b, c, d, x = Var('a'), Var('b'), Var('c'), Var('d'), Var('x')
     Lx = LogicVar('x')
     eq_(
         eval(
             letrec([(a, rules([[x], begin(b(x), c(x))], [[x], d(x)])),
                     (b, rules([[1], 'b1'], [[4], 'b4'])),
                     (c, rules([[4], 'c4'])), (d, rules([[3], 'd3']))],
                    a(Lx), getvalue(Lx))), 4)
Example #5
0
 def test_cut2(self):
   a, b, c, x = Var('a'), Var('b'), Var('c'), Var('x')
   Lx = LogicVar('x')
   assert_raises(NoSolution, eval, letrec([(a, rules([[x], begin(b(x), cut, c(x))])),
                    (b, rules([[1], True],
                                   [[2], True],
                                   [[3], True])),
                    (c, rules([[2], True]))],
            a(Lx), getvalue(Lx)))
Example #6
0
 def testCut1(self):
   a, b, c, x = Var('a'), Var('b'), Var('c'), Var('x')
   Lx = LogicVar('x')
   eq_(eval(letrec([(a, rules([[x], begin(b(x), cut, c(x))])), 
                    (b, rules([[1], True],
                                [[2], True],
                                [[3], True])),
                    (c, rules([[1], True]))],
            a(Lx), getvalue(Lx))), 1) 
Example #7
0
 def testCut4(self):
   a, b, c, d, x = Var('a'), Var('b'), Var('c'), Var('d'), Var('x'), 
   Lx = LogicVar('x')
   assert_raises(NoSolution, eval, letrec([(a, rules([[x], begin(b(x), cut, c(x))],
                         [[x], d(x)])),
                    (b, rules([[1], 'b1'],
                                [[4], 'b4'])),
                    (c, rules([[4], 'c4'])),
                    (d, rules([[3], 'd3']))],
            a(Lx), getvalue(Lx)))
Example #8
0
 def test_cut2_no_Cut3_begin(self):
   a, b, c, d, x = Var('a'), Var('b'), Var('c'), Var('d'), Var('x')
   Lx = LogicVar('x')
   eq_(eval(letrec([(a, rules([[x], begin(b(x),c(x))],
                                [[x], d(x)])),
                    (b, rules([[1], 'b1'],
                                [[4], 'b4'])),
                    (c, rules([[4], 'c4'])),
                    (d, rules([[3], 'd3']))],
            a(Lx), getvalue(Lx))), 4) 
Example #9
0
 def testCut5(self):
     start, a, b, c, d, x = Var('start'), Var('a'), Var('b'), Var('c'), Var(
         'd'), Var('x'),
     Lx = LogicVar('x')
     eq_(
         eval(
             letrec([(start, rules([[x], a(x)], [[x], d(x)])),
                     (a, rules([[x], begin(b(x), c(x))], [[x], d(x)])),
                     (b, rules([[1], 'b1'], [[4], 'b4'])),
                     (c, rules([[4], 'c4'])), (d, rules([[3], 'd3']))],
                    start(Lx), getvalue(Lx))), 4)
Example #10
0
 def test_cut2_no_Cut2_and_(self):
     # test_cut2_no_Cut_and_p work correct.
     # but this test and test_cut2_no_Cut3_begin work wrong because the bug below:
     # bug in Var.getvalue/Var.setvalue:
     # dont't restore the longer chain of bindings after shorten it.
     a, b, c, d, x = Var('a'), Var('b'), Var('c'), Var('d'), Var('x')
     Lx = LogicVar('x')
     eq_(
         eval(
             letrec([(a, rules([[x], begin(b(x), c(x))], [[x], d(x)])),
                     (b, rules([[1], True], [[4], True])),
                     (c, rules([[4], True])), (d, rules([[3], True]))],
                    a(Lx), getvalue(Lx))), 4)
Example #11
0
 def testCut6(self):
   start, a, b, c, d, x = Var('start'), Var('a'), Var('b'), Var('c'), Var('d'), Var('x'), 
   Lx = LogicVar('x')
   eq_(eval(letrec([
     (start, rules([[x], a(x)],
                   [[x], d(x)])),      
     (a, rules([[x], begin(b(x), cut, c(x))],
               [[x], d(x)])),
     (b, rules([[1], 'b1'],
               [[4], 'b4'])),
     (c, rules([[4], 'c4'])),
     (d, rules([[3], 'd3']))],
     start(Lx), getvalue(Lx))), 3)
Example #12
0
 def test_cut2_no_Cut2_and_(self):
   # test_cut2_no_Cut_and_p work correct.
   # but this test and test_cut2_no_Cut3_begin work wrong because the bug below:
   # bug in Var.getvalue/Var.setvalue: 
   # dont't restore the longer chain of bindings after shorten it.
   a, b, c, d, x = Var('a'), Var('b'), Var('c'), Var('d'), Var('x')
   Lx = LogicVar('x')
   eq_(eval(letrec([(a, rules([[x], begin(b(x),c(x))],
                                [[x], d(x)])),
                    (b, rules([[1], True],
                                [[4], True])),
                    (c, rules([[4], True])),
                    (d, rules([[3], True]))],
            a(Lx), getvalue(Lx))), 4)