示例#1
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])
示例#2
0
 def test_unify2(self):
     x = LogicVar('x')
     result = compile_optimize(unify(x, 2))
     x1 = il.LogicVar('x')
     x2 = il.ConstLocalVar('x')
     expect = il.begin(
         il.Assign(x2, il.Deref(LogicVar(x1))),
         il.If(
             il.IsLogicVar(x2),
             il.begin(il.SetBinding(x2, il.Integer(2)), il.TRUE),
             il.If(il.Eq(x2, il.Integer(2)), il.TRUE,
                   il.failcont(il.TRUE))))
     eq_(result, expect)
示例#3
0
 def test_greedy_seplist5(self):
     _ = DummyVar('_')
     y = LogicVar('y')
     assert_raises(
         NoSolution, eval,
         begin(set_text('a,a,a'), greedy_seplist(char(_), char(','), _, y),
               char(_), eoi, getvalue(y)))
示例#4
0
 def test_seplist5(self):
     _ = DummyVar('_')
     y = LogicVar('y')
     eq_(
         eval(
             begin(set_text('a,b,cd'), seplist(char(_), char(','), _, y),
                   char(_), eoi, getvalue(y))), ['a', 'b', 'c'])
示例#5
0
 def test_greedy_some5(self):
     _ = DummyVar('_')
     y = LogicVar('y')
     assert_raises(
         NoSolution, eval,
         begin(set_text('aaa'), greedy_some(char(_), _, y), char(_), eoi,
               y))
示例#6
0
 def test_greedy_some4(self):
     _ = DummyVar('_')
     y = LogicVar('y')
     eq_(
         eval(
             begin(set_text('aaa'), greedy_some(char(_), _, y), eoi,
                   getvalue(y))), ['a', 'a', 'a'])
示例#7
0
 def test_some5(self):
     _ = DummyVar('_')
     y = LogicVar('y')
     eq_(
         eval(
             begin(set_text('abc'), some(char(_), _, y), char(_), eoi,
                   getvalue(y))), ['a', 'b'])
示例#8
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)
示例#9
0
 def test_lazy_seplist5(self):
     _ = DummyVar('_')
     y = LogicVar('y')
     eq_(
         eval(
             begin(set_text('a,a,aa'), lazy_seplist(char(_), char(','), _,
                                                    y), char(_), eoi,
                   getvalue(y))), ['a', 'a', 'a'])
示例#10
0
 def test10(self):
     x = LogicVar('x')
     x1 = Const('x')
     y1 = Const('y')
     eq_(
         eval(
             begin(assign(x1, L(L(1, x))), assign(y1, L(L(1, x))),
                   unify(x1, y1))), True)
示例#11
0
 def test_type(self):
     x = LogicVar('x')
     eq_(eval(isinteger(x)), False)
     eq_(eval(isinteger(1)), True)
     eq_(eval(isfloat(1)), False)
     eq_(eval(isfloat(1.0)), True)
     eq_(eval(isnumber(1.0)), True)
     eq_(eval(isnumber(1)), True)
     eq_(eval(istuple(())), True)
     eq_(eval(islist([])), True)
     eq_(eval(isdict({})), True)