def test_findall_or_p(self): x, y = Var('x'), Var('y') eq_( eval( findall( macrorules([[x, y], x], [[x, y], y])(prin(1), prin(2)))), None)
def testLoopUntil(self): eq_( eval( tag_loop_label( let([(i, 3)], LoopUntilForm((set(i, sub(i, 1)), prin(i)), eq(i, 0))))), None)
def test_unwind_protect_loop(self): from util import a, i eq_(eval(let([(i,3)], block(a, assign(i, sub(i, 1)), if_(eq(i, 0), exit_block(a, 1), unwind_protect(continue_block(a), prin(i)))), i)), 0)
def testLoopWhen(self): eq_( eval( tag_loop_label( let([(i, 3)], LoopWhenForm((set(i, sub(i, 1)), prin(i)), gt(i, 0))))), None)
def testLoopTimes(self): eq_( eval( tag_loop_label( let([(i, 3)], LoopTimesForm(3, (set(i, sub(i, 1)), prin(i)))))), None)
def test_unwind_protect_loop(self): from util import a, i eq_( eval( let([(i, 3)], block( a, assign(i, sub(i, 1)), if_(eq(i, 0), exit_block(a, 1), unwind_protect(continue_block(a), prin(i)))), i)), 0)
def test_findall_first_p(self): eq_(eval(findall(first_p(prin(1), prin(2)))), None)
def test_closure1(self): x, f = Const('x'), Const('f') eq_(eval(let([(f, macrorules([[x], prin(x)])), (x, 1)], f(add(x, x)))), None)
def testcall(self): eq_(eval(call(unify(x, 1))), True) eq_(eval(is_(x, quote(prin(1)))&call(x)), None)
def test4(self): x = Var('x') eq_(eval(macrorules([[x], prin(x)])(add(1, 1))), None)
def test_reverse(self): x, y = Var('x'), Var('y') eq_(eval(macrorules([[x, y], y, x])(prin(1), prin(2))), None)
def test_macro5(self): x, y, f = Const('x'), Const('y'), MacroVar('f') eq_(eval(let([(f, macro((x, y), y, x, 1))], f(println(1), prin(2)))), 1)
def testEachForm(self): eq_(eval(tag_loop_label(EachForm(i, range(3), [prin(i)]))), None)
def test_unwind_protect2(self): foo = Var('foo') eq_( eval( block(foo, unwind_protect(exit_block(foo, 1), prin(2), prin(3)))), 1)
def testLoopWhen(self): eq_(eval(tag_loop_label(let([(i,3)], LoopWhenForm((set(i, sub(i, 1)), prin(i)), gt(i,0))))), None)
def testLoopUntil(self): eq_(eval(tag_loop_label(let([(i,3)], LoopUntilForm((set(i, sub(i, 1)), prin(i)), eq(i,0))))), None)
def testLoopTimes(self): eq_(eval(tag_loop_label(let([(i,3)], LoopTimesForm(3, (set(i, sub(i, 1)), prin(i)))))), None)
def test_unwind_protect2(self): foo = Var('foo') eq_(eval(block(foo, unwind_protect(exit_block(foo, 1), prin(2), prin(3)))), 1)
def test_and2(self): eq_(eval(and_(prin(1), prin(2))), None)
def test_cut_or2(self): assert_raises(NoSolution, eval, or_(begin(prin(1), cut_or, fail), prin(2)))
def test_findall_or_once(self): eq_(eval(findall(once(or_(prin(1), prin(2))))), None)
def test_cut_or(self): eq_(eval(or_(begin(prin(1), fail), prin(2))), None)
def testEachForm2(self): eq_(eval(tag_loop_label(EachForm((i, j), zip(range(3), range(3)), [prin(i, j)]))), None)
def test_macro3(self): x, y = Const('x'), Const('y') eq_(eval(macro((x, y), y, x, 1)(println(1), prin(2))), 1)
def test1(self): eq_(eval(macrorules([[], prin(1)])()), None)
def testEachForm2(self): eq_( eval( tag_loop_label( EachForm((i, j), zip(range(3), range(3)), [prin(i, j)]))), None)
def test2(self): x = Var('x') eq_(eval(macrorules([[x], x])(prin(1))), None)
def test5(self): x = Var('x') y = Var('y') eq_(eval(let([(y, 1)], macrorules([[x], prin(x)])(add(y, 1)))), None)
def test_findall_or_p(self): x, y = Var('x'), Var('y') eq_(eval(findall(macrorules([[x, y], x], [[x, y], y])(prin(1), prin(2)))), None)
def test_closure3(self): x, y, f = Const('x'), Const('y'), Const('f') eq_( eval( let([(f, macrorules([[x, y], begin(x, y)])), (x, 1)], f(prin(x), prin(add(x, x))))), None)
def test_closure1(self): x, f = Const('x'), Const('f') eq_(eval(let([(f, macrorules([[x], prin(x)])), (x, 1)], f(add(x,x)))), None)
def test_closure3(self): x, y, f = Const('x'), Const('y'), Const('f') eq_(eval(let([(f, macrorules([[x, y], begin(x, y)])), (x, 1)], f(prin(x), prin(add(x,x))))), None)
def testcall(self): eq_(eval(call(unify(x, 1))), True) eq_(eval(is_(x, quote(prin(1))) & call(x)), None)