Пример #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_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')
Пример #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'])
Пример #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'])
Пример #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)))
Пример #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'])
Пример #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')
Пример #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'])
Пример #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'])
Пример #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'])
Пример #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')
Пример #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))), '_')
Пример #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)))
Пример #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)
Пример #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)))
Пример #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) 
Пример #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)
Пример #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)))
Пример #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'))
Пример #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) 
Пример #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)))
Пример #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'))
Пример #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)
Пример #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)
Пример #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)
Пример #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) 
Пример #27
0
 def test_identifier2(self):
     x = LogicVar('x')
     eq_(eval(begin(parse_text(identifier(x), '_a1b_23'), getvalue(x))),
         '_a1b_23')
Пример #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])
Пример #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])
Пример #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)
Пример #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)
Пример #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)
Пример #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')
Пример #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)
Пример #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])
Пример #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)
Пример #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')
Пример #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)))
Пример #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))), '_')
Пример #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'])
Пример #41
0
 def test_identifier2(self):
   x = LogicVar('x')
   eq_(eval(begin(parse_text(identifier(x), '_a1b_23'), getvalue(x))), '_a1b_23')
Пример #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)
Пример #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')
Пример #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')
Пример #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)
Пример #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') 
Пример #47
0
 def test_getvalue(self):
     from dao.solvebase import conslist
     eq_(eval(begin(getvalue(L("abc", 1)))), conslist("abc", 1))
Пример #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')
Пример #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'])
Пример #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'])
Пример #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'])
Пример #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])
Пример #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'])
Пример #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)
Пример #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')
Пример #56
0
 def test_getvalue(self):
   from dao.solvebase import conslist
   eq_(eval(begin(getvalue(L("abc", 1)))), conslist("abc", 1))
Пример #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])