Exemplo n.º 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])
Exemplo n.º 2
0
 def test_digit_string1(self):
     x = LogicVar('x')
     eq_(eval(parse_text(digits1, '123')), '123')
     eq_(eval(parse_text(is_(x, digits1), '123a')), '123')
     eq_(
         eval(begin(parse_text(eval_unify(x, digits1), '123 '),
                    getvalue(x))), '123')
Exemplo n.º 3
0
 def test_any5(self):
     _ = DummyVar('_')
     y = LogicVar('y')
     eq_(
         eval(
             begin(set_text('aaa'), any(char(_), _, y), char(_), eoi,
                   getvalue(y))), ['a', 'a'])
Exemplo n.º 4
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'])
Exemplo n.º 5
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)))
Exemplo n.º 6
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'])
Exemplo n.º 7
0
 def test_digit_string0(self):
   x = LogicVar('x')
   eq_(eval(parse_text(digits0, '')), '')
   eq_(eval(parse_text(digits0, 'a')), '')
   eq_(eval(parse_text(digits0, '123')), '123')
   eq_(eval(parse_text(is_(x, digits0), '123a')), '123')
   eq_(eval(begin(parse_text(eval_unify(x, digits0), '123 '), getvalue(x))), '123')
Exemplo n.º 8
0
 def test_some5(self):
     _ = DummyVar('_')
     y = LogicVar('y')
     eq_(
         eval(
             begin(set_text('abc'), some(char(_), _, y), char(_), eoi,
                   getvalue(y))), ['a', 'b'])
Exemplo n.º 9
0
 def test_times4(self):
     _ = DummyVar('_')
     x = LogicVar('x')
     eq_(
         eval(
             begin(set_text('aaa'), times(char(_), 3, _, x), eoi,
                   getvalue(x))), ['a', 'a', 'a'])
Exemplo n.º 10
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'])
Exemplo n.º 11
0
 def test_chars(self):
     x, cs, chars = LogicVar('x'), Var('cs'), MacroVar('chars')
     x1 = Var('x')
     eq_(
         eval(
             let([(chars, lamda(
                 (x1, cs), begin(char(x1), contain(cs, x1))))],
                 parse_text(chars(x, 'a'), 'a'), getvalue(x))), 'a')
Exemplo n.º 12
0
 def test_underline_letter_digit(self):
     x = LogicVar('x')
     eq_(eval(parse_text(underline_letter_digit, '1')), '1')
     eq_(eval(parse_text(is_(x, underline_letter_digit), 'a')), 'a')
     eq_(
         eval(
             begin(parse_text(eval_unify(x, underline_letter_digit), '_'),
                   getvalue(x))), '_')
Exemplo n.º 13
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)))
Exemplo n.º 14
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)
Exemplo n.º 15
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)))
Exemplo n.º 16
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) 
Exemplo n.º 17
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)
Exemplo n.º 18
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)))
Exemplo n.º 19
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'))
Exemplo n.º 20
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) 
Exemplo n.º 21
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)))
Exemplo n.º 22
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'))
Exemplo n.º 23
0
 def testCut5(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), c(x))], [[x], d(x)])),
                     (b, rules([[1], 'b1'], [[4], 'b4'])),
                     (c, rules([[4], 'c4'])), (d, rules([[3], 'd3']))],
                    start(Lx), getvalue(Lx))), 4)
Exemplo n.º 24
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)
Exemplo n.º 25
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)
Exemplo n.º 26
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) 
Exemplo n.º 27
0
 def test_identifier2(self):
     x = LogicVar('x')
     eq_(eval(begin(parse_text(identifier(x), '_a1b_23'), getvalue(x))),
         '_a1b_23')
Exemplo n.º 28
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])
Exemplo n.º 29
0
 def test_between3(self):
   x = LogicVar('x')
   y = LogicVar('y')
   eq_(eval(begin(findall(between(1, 3, x), x, y), getvalue(y))), [1, 2, 3])
Exemplo n.º 30
0
 def test_getvalue(self):
     x = LogicVar('x')
     x1 = DaoLogicVar('x')
     eq_(eval(getvalue(x)), x1)
     eq_(eval(begin(unify(x, 1), getvalue(x))), 1)
Exemplo n.º 31
0
 def test_unify_parse_text(self):
   x = LogicVar('x')
   eq_(eval(begin(set_text('abcde'), unify_parse_text(x), getvalue(x))), 'abcde')
   eq_(eval(begin(set_text('abcde'), unify_parse_text('abcde'))), True)
Exemplo n.º 32
0
 def test_unify_parse_text(self):
     x = LogicVar('x')
     eq_(eval(begin(set_text('abcde'), unify_parse_text(x), getvalue(x))),
         'abcde')
     eq_(eval(begin(set_text('abcde'), unify_parse_text('abcde'))), True)
Exemplo n.º 33
0
 def test_digit(self):
   x = LogicVar('x')
   eq_(eval(parse_text(digit, '1')), '1')
   eq_(eval(parse_text(is_(x, digit), '1')), '1')
   eq_(eval(begin(parse_text(eval_unify(x, digit), '1'), getvalue(x))), '1')
Exemplo n.º 34
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)
Exemplo n.º 35
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])
Exemplo n.º 36
0
 def test_getvalue_default(self):
   x = LogicVar('x')
   eq_(eval(getvalue_default(x)), None)
   eq_(eval(getvalue_default(x, 1)), 1)
   eq_(eval(begin(unify(x, 2), getvalue(x))), 2)
Exemplo n.º 37
0
 def test_digit(self):
     x = LogicVar('x')
     eq_(eval(parse_text(digit, '1')), '1')
     eq_(eval(parse_text(is_(x, digit), '1')), '1')
     eq_(eval(begin(parse_text(eval_unify(x, digit), '1'), getvalue(x))),
         '1')
Exemplo n.º 38
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)))
Exemplo n.º 39
0
 def test_underline_letter_digit(self):
   x = LogicVar('x')
   eq_(eval(parse_text(underline_letter_digit, '1')), '1')
   eq_(eval(parse_text(is_(x, underline_letter_digit), 'a')), 'a')
   eq_(eval(begin(parse_text(eval_unify(x, underline_letter_digit), '_'), getvalue(x))), '_')
Exemplo n.º 40
0
 def test_times4(self):
   _ = DummyVar('_')
   x = LogicVar('x')
   eq_(eval(begin(set_text('aaa'), times(char(_), 3, _, x), eoi, getvalue(x))), ['a', 'a', 'a'])
Exemplo n.º 41
0
 def test_identifier2(self):
   x = LogicVar('x')
   eq_(eval(begin(parse_text(identifier(x), '_a1b_23'), getvalue(x))), '_a1b_23')
Exemplo n.º 42
0
 def test_getvalue_default(self):
     x = LogicVar('x')
     eq_(eval(getvalue_default(x)), None)
     eq_(eval(getvalue_default(x, 1)), 1)
     eq_(eval(begin(unify(x, 2), getvalue(x))), 2)
Exemplo n.º 43
0
 def test_number(self):
     x = LogicVar('x')
     eq_(eval(begin(parse_text(integer(x), '2'), getvalue(x))), '2')
     eq_(eval(begin(parse_text(integer(x), '234'), getvalue(x))), '234')
     eq_(eval(begin(parse_text(integer(x), '0232'), getvalue(x))), '0232')
Exemplo n.º 44
0
 def test_word(self):
   x = LogicVar('x')
   eq_(eval(begin(parse_text(word(x), 'ab'), getvalue(x))), 'ab')
   eq_(eval(begin(parse_text(word('ab'), 'ab'))), 'ab')
Exemplo n.º 45
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)
Exemplo n.º 46
0
 def test_number(self):
   x = LogicVar('x')
   eq_(eval(begin(parse_text(integer(x), '2'), getvalue(x))), '2')
   eq_(eval(begin(parse_text(integer(x), '234'), getvalue(x))), '234')
   eq_(eval(begin(parse_text(integer(x), '0232'), getvalue(x))), '0232') 
Exemplo n.º 47
0
 def test_getvalue(self):
     from dao.solvebase import conslist
     eq_(eval(begin(getvalue(L("abc", 1)))), conslist("abc", 1))
Exemplo n.º 48
0
 def test_chars(self):
   x, cs, chars = LogicVar('x'), Var('cs'), MacroVar('chars')
   x1 = Var('x')
   eq_(eval(let([(chars, lamda((x1, cs), begin(char(x1), contain(cs, x1))))],
                           parse_text(chars(x, 'a'), 'a'), getvalue(x))), 'a')
Exemplo n.º 49
0
 def test_some5(self):
   _ = DummyVar('_')
   y = LogicVar('y')
   eq_(eval(begin(set_text('abc'), some(char(_), _, y), char(_), eoi, getvalue(y))), ['a', 'b'])
Exemplo n.º 50
0
 def test_lazy_any4(self):
   _ = DummyVar('_')
   y = LogicVar('y')
   eq_(eval(begin(set_text('aaa'), lazy_any(char(_), _, y), eoi, getvalue(y))), ['a', 'a', 'a'])
Exemplo n.º 51
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'])
Exemplo n.º 52
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])
Exemplo n.º 53
0
 def test_greedy_seplist4(self):
   _ = DummyVar('_')
   y = LogicVar('y')
   eq_(eval(begin(set_text('a,a,a'), greedy_seplist(char(_), char(','), _, y), eoi, getvalue(y))), ['a', 'a', 'a'])
Exemplo n.º 54
0
 def test_getvalue(self):
   x = LogicVar('x')
   x1 = DaoLogicVar('x')
   eq_(eval(getvalue(x)), x1)
   eq_(eval(begin(unify(x, 1), getvalue(x))), 1)
Exemplo n.º 55
0
 def test_word(self):
     x = LogicVar('x')
     eq_(eval(begin(parse_text(word(x), 'ab'), getvalue(x))), 'ab')
     eq_(eval(begin(parse_text(word('ab'), 'ab'))), 'ab')
Exemplo n.º 56
0
 def test_getvalue(self):
   from dao.solvebase import conslist
   eq_(eval(begin(getvalue(L("abc", 1)))), conslist("abc", 1))
Exemplo n.º 57
0
 def test_between3(self):
     x = LogicVar('x')
     y = LogicVar('y')
     eq_(eval(begin(findall(between(1, 3, x), x, y), getvalue(y))),
         [1, 2, 3])