Beispiel #1
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) 
Beispiel #2
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)))
Beispiel #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)))
Beispiel #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) 
Beispiel #5
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)
Beispiel #6
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) 
Beispiel #7
0
 def testKleene1(self): #occurs_check
   x, s, kleene = Var('x'), Var('s'), Var('kleene')
   x1 = Var('x')
   result = LogicVar('result')
   ruleList = [(kleene, rules( 
                 ((cons('a', x),), begin(char('a'), kleene(x))),
                 ((nil,), nullword)))]
   eq_(eval(letrec(ruleList, 
                   parse_text(kleene(result), 'aa'), getvalue(result))), L('a', 'a'))
Beispiel #8
0
 def test1(self):
   x = Var('x')
   lx = LogicVar('x')
   eq_(eval(rules([[x],x])(2)), 2) 
   eq_(eval(rules([[1], 1],[[x],x])(2)), 2) 
Beispiel #9
0
 def testdouble1(self):
     x = Var('x')
     eq_(eval(rules([[x], add(x, x)])(2)), 4)
Beispiel #10
0
 def test1_2(self):
     eq_(eval(rules([[1], 1], [[2], 2])(2)), 2)
Beispiel #11
0
 def test1_0(self):
     eq_(eval(rules([[1], 1])(1)), 1)
Beispiel #12
0
 def testdouble5(self):
   f = Var('f')
   x = Var('x')
   assert_raises(TypeError, eval, let([(f, rules([[x], add(x, x)]))], f(1, 2))) # passed
Beispiel #13
0
 def testdouble4(self):
   f = Var('f')
   x = Var('x')
   eq_(eval(let([(f, rules([[x], add(x, x)]))], f(f(1)))), 4) 
Beispiel #14
0
 def testdouble2(self):
   x = Var('x')
   eq_(eval(rules([[x], x])(add(2, 2))), 4)
Beispiel #15
0
 def testdouble1(self):
   x = Var('x')
   eq_(eval(rules([[x], add(x, x)])(2)), 4)
Beispiel #16
0
 def test2(self):
   lx = LogicVar('x')
   eq_(eval(rules([[1], 1],[[2],2])(lx)), 1)
Beispiel #17
0
 def test1_2(self):
   eq_(eval(rules([[1], 1],[[2],2])(2)), 2) 
Beispiel #18
0
 def test_let_rec_embed_var1(self):
   e, f = LogicVar('e'), Var('f')
   eq_(eval(letrec([(f, rules([[1], 1]))], f(e))), 1)
Beispiel #19
0
 def test_let_embed_var2(self):
   e, f = LogicVar('e'), Var('f')
   eq_(eval(let([(f, rules([[1], 1]))], f(e), getvalue(e))), 1)
Beispiel #20
0
 def test1(self):
     x = Var('x')
     lx = LogicVar('x')
     eq_(eval(rules([[x], x])(2)), 2)
     eq_(eval(rules([[1], 1], [[x], x])(2)), 2)
Beispiel #21
0
 def test_letrec_rules(self):
   f = Var('f')
   x = Var('x')
   eq_(eval(letrec([(f, rules([[1], 1],[[x],f(sub(x,1))]))], f(1))), 1) # passed
   eq_(eval(letrec([(f, rules([[1], 1],[[x],f(sub(x,1))]))], f(2))), 1)
Beispiel #22
0
 def test2(self):
     lx = LogicVar('x')
     eq_(eval(rules([[1], 1], [[2], 2])(lx)), 1)
Beispiel #23
0
 def test_fail(self):
   x = Var('x')
   x1 = LogicVar('x')
   eq_(eval(let([(f,rules([[1], fail], [[x], succeed]))], f(x1))), True)
Beispiel #24
0
 def testdouble2(self):
     x = Var('x')
     eq_(eval(rules([[x], x])(add(2, 2))), 4)
Beispiel #25
0
 def test_succeed(self):
     x = LogicVar('x')
     eq_(eval(let([(f, rules([[1], succeed]))], f(x))), True)
Beispiel #26
0
 def test_findall_template_func(self):
   x, y, z = LogicVar('x'), LogicVar('y'), LogicVar('z')
   f = Var('f')
   eq_(eval(let([(f, rules(((), 2), ((), 3)))], 
              findall(is_(x, f()), x, y), getvalue(y))), [2, 3])
Beispiel #27
0
 def test1_0(self):
   eq_(eval(rules([[1], 1])(1)), 1) 
Beispiel #28
0
 def test_succeed(self):
   x = LogicVar('x')
   eq_(eval(let([(f,rules([[1], succeed]))], f(x))), True)
Beispiel #29
0
 def test_fail(self):
     x = Var('x')
     x1 = LogicVar('x')
     eq_(eval(let([(f, rules([[1], fail], [[x], succeed]))], f(x1))), True)