示例#1
0
 def test_open_read2(self):
     file1 = Var('file1')
     x = Var('x')
     eq_(
         eval(
             let([(file1, open_file('test.txt'))], readline(file1),
                 assign(x, readlines(file1)), close_file(file1), x)),
         ['hello'])
示例#2
0
 def test9(self):
     x = LogicVar('x')
     x1 = Var('x')
     y1 = Var('y')
     eq_(
         eval(
             begin(assign(x1, L(L(1, x))), assign(y1, L(L(1, x))),
                   unify(x1, y1))), True)
示例#3
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])
示例#4
0
 def test2(self):
     x = Var('x')
     Lx = LogicVar('x')
     eq_(eval(unify(1, 1)), True)
     eq_(eval(begin(unify(1, 1), unify(2, 2))), True)
     eq_(eval(begin(unify(Lx, 1), unify(Lx, 1))), True)
     eq_(eval(let([(x, 1)], unify(x, 1))), True)
示例#5
0
 def test_fail(self):
     x = Var('x')
     x1 = LogicVar('x')
     eq_(eval(let([(f, rules([[1], fail], [[x], succeed]))], f(x1))), True)
示例#6
0
 def test_findall_template_or(self):
     x, y, z = LogicVar('x'), LogicVar('y'), LogicVar('z')
     f = Var('f')
     eq_(eval(begin(findall(or_(is_(x, 1), is_(x, 2)), x, y), getvalue(y))),
         [1, 2])
示例#7
0
 def test5(self):
     x = Var('x')
     Lx = LogicVar('x')
     assert_raises(NoSolution, eval, begin(unify(Lx, 1), unify(Lx, 2)))
示例#8
0
 def test4(self):
     x = Var('x')
     Lx = LogicVar('x')
     eq_(eval(begin(unify(Lx, 1), unify(Lx, 1))), True)
示例#9
0
 def test_ground(self):
     eq_(eval(ground_p(1)), True)
     assert_raises(NoSolution, eval, ground_p(Var('')))
示例#10
0
 def test_write(self):
     file1 = Var('file1')
     eq_(
         eval(
             let([(file1, open_file('test2.txt', 'w'))],
                 write(file1, 'test'), close_file(file1))), None)
示例#11
0
 def test_open_read(self):
     file1 = Var('file1')
     eq_(
         eval(
             let([(file1, open_file('test.txt'))], assign(x, read(file1)),
                 close_file(file1), x)), 'hello\nhello')
示例#12
0
 def test_assign(self):
     x = Var('x')
     result = compile(assign(x, 2))
     expect = '2'
     eq_(result, expect)