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 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')
def test_any5(self): _ = DummyVar('_') y = LogicVar('y') eq_( eval( begin(set_text('aaa'), any(char(_), _, y), char(_), eoi, getvalue(y))), ['a', 'a'])
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'])
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)))
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'])
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')
def test_some5(self): _ = DummyVar('_') y = LogicVar('y') eq_( eval( begin(set_text('abc'), some(char(_), _, y), char(_), eoi, getvalue(y))), ['a', 'b'])
def test_times4(self): _ = DummyVar('_') x = LogicVar('x') eq_( eval( begin(set_text('aaa'), times(char(_), 3, _, x), eoi, getvalue(x))), ['a', 'a', 'a'])
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'])
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')
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))), '_')
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)))
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)
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)))
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)
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)
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)))
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'))
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)
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)))
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'))
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)
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)
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)
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)
def test_identifier2(self): x = LogicVar('x') eq_(eval(begin(parse_text(identifier(x), '_a1b_23'), getvalue(x))), '_a1b_23')
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 test_between3(self): x = LogicVar('x') y = LogicVar('y') eq_(eval(begin(findall(between(1, 3, x), x, y), getvalue(y))), [1, 2, 3])
def test_getvalue(self): x = LogicVar('x') x1 = DaoLogicVar('x') eq_(eval(getvalue(x)), x1) eq_(eval(begin(unify(x, 1), getvalue(x))), 1)
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)
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')
def test_let_embed_var2(self): e, f = LogicVar('e'), Var('f') eq_(eval(let([(f, rules([[1], 1]))], f(e), getvalue(e))), 1)
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 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)
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)))
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))), '_')
def test_times4(self): _ = DummyVar('_') x = LogicVar('x') eq_(eval(begin(set_text('aaa'), times(char(_), 3, _, x), eoi, getvalue(x))), ['a', 'a', 'a'])
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')
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')
def test_getvalue(self): from dao.solvebase import conslist eq_(eval(begin(getvalue(L("abc", 1)))), conslist("abc", 1))
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')
def test_some5(self): _ = DummyVar('_') y = LogicVar('y') eq_(eval(begin(set_text('abc'), some(char(_), _, y), char(_), eoi, getvalue(y))), ['a', 'b'])
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'])
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'])
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'])