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'])
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)
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])
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)
def test_fail(self): x = Var('x') x1 = LogicVar('x') eq_(eval(let([(f, rules([[1], fail], [[x], succeed]))], f(x1))), True)
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])
def test5(self): x = Var('x') Lx = LogicVar('x') assert_raises(NoSolution, eval, begin(unify(Lx, 1), unify(Lx, 2)))
def test4(self): x = Var('x') Lx = LogicVar('x') eq_(eval(begin(unify(Lx, 1), unify(Lx, 1))), True)
def test_ground(self): eq_(eval(ground_p(1)), True) assert_raises(NoSolution, eval, ground_p(Var('')))
def test_write(self): file1 = Var('file1') eq_( eval( let([(file1, open_file('test2.txt', 'w'))], write(file1, 'test'), close_file(file1))), None)
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')
def test_assign(self): x = Var('x') result = compile(assign(x, 2)) expect = '2' eq_(result, expect)