Esempio n. 1
0
    def test_genAST_pred_part_fun(self):
        # Build AST:
        string_to_file("#PREDICATE F=S+->T", file_name)
        ast_string = file_to_AST_str(file_name)
        root = str_ast_to_python_ast(ast_string)

        l = []
        l.append(frozenset([]))
        l.append(frozenset([("a","x")]))
        l.append(frozenset([("a","y")]))
        l.append(frozenset([("b","x")]))
        l.append(frozenset([("b","y")]))
        l.append(frozenset([("a","x"),("b","x")]))
        l.append(frozenset([("a","y"),("b","y")]))
        l.append(frozenset([("a","x"),("b","y")]))
        l.append(frozenset([("a","y"),("b","x")]))
        env = Environment()
        env.add_ids_to_frame(["S","T","F"])
        env.set_value("S", frozenset(["a","b"]))
        env.set_value("T", frozenset(["x","y"]))
        env.set_value("F", frozenset(l))
        assert interpret(root.children[0],env)

        l = []
        l.append(frozenset([("1","hallo_welt")]))
        l.append(frozenset([("2","hallo_welt")]))
        l.append(frozenset([("1","hallo_welt"),("2","hallo_welt")]))
        l.append(frozenset([]))
        env.set_value("S", frozenset(["1","2"]))
        env.set_value("T", frozenset(["hallo_welt",]))
        env.set_value("F", frozenset(l))
        assert interpret(root.children[0],env)
Esempio n. 2
0
    def test_simple_pred_impl3(self):
        # Build AST: z=42 => 1+1=2
        intExp4 = AIntegerExpression(42)
        idExp = AIdentifierExpression("z")
        eqPred2 = AEqualPredicate()
        eqPred2.children.append(idExp)
        eqPred2.children.append(intExp4)

        intExp = AIntegerExpression(1)
        intExp2 = AIntegerExpression(1)
        intExp3 = AIntegerExpression(2)
        addExp = AAddExpression()
        addExp.children.append(intExp)
        addExp.children.append(intExp2)
        eqPred = AEqualPredicate()
        eqPred.children.append(addExp)
        eqPred.children.append(intExp3)

        implPred = AImplicationPredicate()
        implPred.children.append(eqPred2)
        implPred.children.append(eqPred)

        #Test
        env = Environment() # True=>True is True
        env.add_ids_to_frame(["z"])
        env.set_value("z", 42)
        assert interpret(implPred, env)

        # False=>True is True
        env.set_value("z", 41)
        assert interpret(implPred, env)
Esempio n. 3
0
    def test_simple_set_pred_inters(self):
        # Build AST: S <: S /\ T
        idExp = AIdentifierExpression("S")
        idExp2 = AIdentifierExpression("S")
        idExp3 = AIdentifierExpression("T")
        insExp = AIntersectionExpression()
        insExp.children.append(idExp2)
        insExp.children.append(idExp3)
        inclPred = ASubsetPredicate()
        inclPred.children.append(idExp)
        inclPred.children.append(insExp)

        # Test
        env = Environment()
        env.add_ids_to_frame(["S","T"])
        env.set_value("S", frozenset(["aa","bb"]))
        env.set_value("T", frozenset(["bb","cc","dd"]))
        assert not interpret(inclPred, env)

        env.set_value("S", frozenset(["aa","bb"]))
        env.set_value("T", frozenset(["aa","bb","cc","dd"]))
        assert interpret(inclPred, env)

        env.set_value("S", frozenset(["aa","bb"]))
        env.set_value("T", frozenset(["cc","dd"]))
        assert not interpret(inclPred, env)
Esempio n. 4
0
 def test_all_ids_known5(self):
     string_to_file("#PREDICATE ID={x|x>0 & x<10}", file_name)
     ast_string = file_to_AST_str(file_name)
     root = str_ast_to_python_ast(ast_string)
     
     env = Environment()
     env.add_ids_to_frame(["ID"])
     env.set_value("ID", frozenset([1,2,3])) # would be false
     assert all_ids_known(root, env)==True
Esempio n. 5
0
 def test_all_ids_known2(self):
     string_to_file("#PREDICATE x=y & x=42", file_name)
     ast_string = file_to_AST_str(file_name)
     root = str_ast_to_python_ast(ast_string)
     
     env = Environment()
     env.add_ids_to_frame(["x","y"])
     env.set_value("x",42)
     env.set_value("y",42)
     assert all_ids_known(root, env)==True
Esempio n. 6
0
 def test_all_ids_known6(self):
     string_to_file("#PREDICATE {(1,2)}:S<->T", file_name)
     ast_string = file_to_AST_str(file_name)
     root = str_ast_to_python_ast(ast_string)
     
     env = Environment()
     env.add_ids_to_frame(["S","T"])
     env.set_value("S", frozenset([1,2,3,4,5]))
     env.set_value("T", frozenset([1,2,3,4,5]))  
     assert all_ids_known(root, env)==True               
Esempio n. 7
0
    def test_genAST_string(self):
        # Build AST
        string_to_file("#PREDICATE s=\"Hallo Welt\"", file_name)
        ast_string = file_to_AST_str(file_name)
        root = str_ast_to_python_ast(ast_string)

        # Test
        env = Environment()
        env.add_ids_to_frame(["s"])
        env.set_value("s", "Hallo Welt")
        assert interpret(root.children[0],env)
Esempio n. 8
0
    def test_simple_set_expr_card(self):
        # Build AST: card(S)
        idExp = AIdentifierExpression("S")
        cardExp = ACardExpression()
        cardExp.children.append(idExp)

        #Test
        env = Environment()
        env.add_ids_to_frame(["S"])
        env.set_value("S", frozenset(["aa","bb"]))
        assert interpret(cardExp, env)==2
Esempio n. 9
0
    def test_genAST_pred_fun_app4(self):
        # Build AST:
        string_to_file("#PREDICATE f={((1,1,1),42),((2,2,2),777)} & zz=f(2,2,2)", file_name)
        ast_string = file_to_AST_str(file_name)
        root = str_ast_to_python_ast(ast_string)

        env = Environment()
        env.add_ids_to_frame(["zz","f"])
        env.set_value("f", frozenset([(((1,1),1),42),(((2,2),2),777)]))
        env.set_value("zz", 777)
        assert interpret(root.children[0],env)
Esempio n. 10
0
    def test_genAST_pred_set_contains3(self):
        # Build AST:
        string_to_file("#PREDICATE x:{x}", file_name)
        ast_string = file_to_AST_str(file_name)
        root = str_ast_to_python_ast(ast_string)

        # Test
        env = Environment()
        env.add_ids_to_frame(["x"])
        env.set_value("x", "x")
        assert interpret(root.children[0],env)
Esempio n. 11
0
    def test_genAST_max(self):
        # Build AST:
        string_to_file("#PREDICATE S={1,2,3,4,5} & max(S)=5", file_name)
        ast_string = file_to_AST_str(file_name)
        root = str_ast_to_python_ast(ast_string)

        # Test
        env = Environment()
        env.add_ids_to_frame(["S"])
        type_with_known_types(root.children[0], env, [], ["S"])
        env.set_value("S", frozenset([1, 2, 3, 4, 5]))
        assert interpret(root, env)
Esempio n. 12
0
    def test_genAST_pred_seq_reverse(self):
        # Build AST:
        string_to_file("#PREDICATE s=[a,b] & rev(s)=[b,a]", file_name)
        ast_string = file_to_AST_str(file_name)
        root = str_ast_to_python_ast(ast_string)

        env = Environment()
        env.add_ids_to_frame(["a","b","s"])
        env.set_value("s", frozenset([(1, 'a'), (2, 'b')]))
        env.set_value("a", "a")
        env.set_value("b", "b")
        assert interpret(root.children[0],env)
Esempio n. 13
0
    def test_types_card(self):
        # Build AST
        string_to_file("#PREDICATE card(S)=3", file_name)
        ast_string = file_to_AST_str(file_name)
        root = str_ast_to_python_ast(ast_string)

        # Type
        env = Environment()
        env.add_ids_to_frame(["S"])
        env.set_value("S", frozenset(["Huey", "Dewey", "Louie"]))
        lst = [("S", PowerSetType(SetType("X")))]
        type_with_known_types(root, env, lst, [])
Esempio n. 14
0
    def test_genAST_pred_rel_id(self):
        # Build AST:
        string_to_file("#PREDICATE r=id(S)", file_name)
        ast_string = file_to_AST_str(file_name)
        root = str_ast_to_python_ast(ast_string)

        # Test
        env = Environment()
        env.add_ids_to_frame(["S","r"])
        env.set_value("S", frozenset(["a","b","c"]))
        env.set_value("r", frozenset([("a","a"),("b","b"),("c","c")]))
        assert interpret(root.children[0],env)
Esempio n. 15
0
    def test_genAST_pred_set_orderd_pair(self):
        # Build AST:
        string_to_file("#PREDICATE x|->y:{(x,y)}", file_name)
        ast_string = file_to_AST_str(file_name)
        root = str_ast_to_python_ast(ast_string)

        # Test
        env = Environment()
        env.add_ids_to_frame(["x","y"])
        env.set_value("x", "x")
        env.set_value("y", "y")
        assert interpret(root.children[0],env)
Esempio n. 16
0
    def test_genAST_pred_seq_conc1(self):
        # Build AST:
        string_to_file("#PREDICATE s:perm(S) & t:perm(S) => s^t:seq(S)", file_name)
        ast_string = file_to_AST_str(file_name)
        root = str_ast_to_python_ast(ast_string)

        env = Environment()
        env.add_ids_to_frame(["s","S","t"])
        env.set_value("S", frozenset(["a","b"]))
        env.set_value("s", frozenset([(2, 'a'), (1, 'b')]))
        env.set_value("t", frozenset([(1, 'a'), (2, 'b')]))
        assert interpret(root.children[0],env)
Esempio n. 17
0
    def test_genAST_pred_minint(self):
        # Build AST
        string_to_file("#PREDICATE x>MININT", file_name)
        ast_string = file_to_AST_str(file_name)
        root = str_ast_to_python_ast(ast_string)

        # Test
        env = Environment()
        env.add_ids_to_frame(["x"])
        env.set_value("x", 2)
        type_with_known_types(root.children[0], env, [], "x")
        assert interpret(root.children[0], env)
Esempio n. 18
0
    def test_genAST_pred_sigma2(self):
        # Build AST:
        string_to_file("#PREDICATE 4=(SIGMA zz . (zz:POW(ID) | card(zz)))", file_name)
        ast_string = file_to_AST_str(file_name)
        root = str_ast_to_python_ast(ast_string)

        # Test
        env = Environment()
        env.add_ids_to_frame(["ID"])
        lst = [("ID", PowerSetType(SetType("ID")))]
        env.set_value("ID", frozenset(["a", "b"]))
        type_with_known_types(root.children[0], env, lst, "")
        assert interpret(root.children[0], env)
Esempio n. 19
0
    def test_genAST_pred_exist_subset_nat(self):
        # Build AST:
        string_to_file("#PREDICATE  #(x).(x:S & x>4999) & S={5000}", file_name)
        ast_string = file_to_AST_str(file_name)
        root = str_ast_to_python_ast(ast_string)

        # Test
        env = Environment()
        env.add_ids_to_frame(["S"])
        env.set_value("S", frozenset([5000]))
        env._max_int = 2 ** 16
        type_with_known_types(root.children[0], env, [], ["S"])
        assert interpret(root.children[0], env)
Esempio n. 20
0
    def test_genAST_pred_seq_of_seq(self):
        # Build AST:
        string_to_file("#PREDICATE s:perm(perm(S))", file_name)
        ast_string = file_to_AST_str(file_name)
        root = str_ast_to_python_ast(ast_string)

        env = Environment()
        env._min_int = -1
        env._max_int = 5
        env.add_ids_to_frame(["S","s"])
        env.set_value("S", frozenset(["a","b"]))
        env.set_value("s", frozenset([(2, frozenset([(1, 'a'), (2, 'b')])), (1, frozenset([(2, 'a'), (1, 'b')]))]))
        assert interpret(root.children[0],env)
Esempio n. 21
0
    def test_genAST_lambda2(self):
        # Build AST
        string_to_file("#PREDICATE f="+"%"+"x,y,z.(x:1..2 & y:1..2 & z:1..2|x+y+z)", file_name)
        ast_string = file_to_AST_str(file_name)
        root = str_ast_to_python_ast(ast_string)

        env = Environment()
        env._min_int = -2**8
        env._max_int = 2**8        
        env.add_ids_to_frame(["f"])
        type_with_known_types(root, env, [], ["f","x"])
        env.set_value("f", frozenset([(((1,1),1),3),(((1,1),2),4),(((1,2),1),4),(((2,1),1),4),(((1,2),2),5),(((2,2),1),5),(((2,1),2),5),(((2,2),2),6)]))
        assert interpret(root.children[0],env)
Esempio n. 22
0
    def test_genAST_lambda(self):
        # Build AST
        string_to_file("#PREDICATE f="+"%"+"x.(x>0 & x<4|x*x)", file_name)
        ast_string = file_to_AST_str(file_name)
        root = str_ast_to_python_ast(ast_string)

        env = Environment()
        env._min_int = -2**8
        env._max_int = 2**8
        env.add_ids_to_frame(["f"])
        type_with_known_types(root, env, [], ["f","x"])
        env.set_value("f", frozenset([(1,1),(2,4),(3,9)]))
        assert interpret(root.children[0],env)
Esempio n. 23
0
    def test_simple_set_pred_empt_set(self):
        # Build AST: {}<:A
        eSetExp = AEmptySetExpression()
        idExp = AIdentifierExpression("A")
        inclPred = ASubsetPredicate()
        inclPred.children.append(eSetExp)
        inclPred.children.append(idExp)

        #Test
        env = Environment()
        env.add_ids_to_frame(["A"])
        env.set_value("A", frozenset(["aa","bb"]))
        assert interpret(inclPred, env)
Esempio n. 24
0
    def test_genAST_pred_set_diff2(self):
        # Build AST:
        string_to_file("#PREDICATE A={1,2,3,4,5} & B={3,4,5,6,7} & C = A\B", file_name)
        ast_string = file_to_AST_str(file_name)
        root = str_ast_to_python_ast(ast_string)

        # Test
        env = Environment()
        env.add_ids_to_frame(["A","B","C"])
        env.set_value("A", frozenset([1,2,3,4,5]))
        env.set_value("B", frozenset([3,4,5,6,7]))
        env.set_value("C", frozenset([1,2]))
        assert interpret(root.children[0],env)
Esempio n. 25
0
    def test_genAST_pred_set_cart(self):
        # Build AST:
        string_to_file("#PREDICATE u:S*T", file_name)
        ast_string = file_to_AST_str(file_name)
        root = str_ast_to_python_ast(ast_string)

        # Test
        env = Environment()
        env.add_ids_to_frame(["T","S","u"])
        env.set_value("S", frozenset(["a","b"]))
        env.set_value("T", frozenset(["x","y"]))
        env.set_value("u", ("a","x"))
        assert interpret(root.children[0],env)
Esempio n. 26
0
    def test_genAST_pred_exist4(self):
        # Build AST:
        string_to_file("#PREDICATE T<:POW(ID) & #(X).(X<:POW(ID) => X=T )", file_name)
        ast_string = file_to_AST_str(file_name)
        root = str_ast_to_python_ast(ast_string)

        # Test
        env = Environment()
        env.add_ids_to_frame(["ID","T"])
        env.set_value("ID", frozenset(["a","b"]))
        env.set_value("T", frozenset([frozenset(["a","b"]),frozenset(["a"]),frozenset(["b"]),frozenset([])]))
        lst = [("ID", PowerSetType(SetType("ID")))]
        type_with_known_types(root.children[0], env, lst, ["T"])
        assert interpret(root.children[0],env)
Esempio n. 27
0
    def test_simple_set_pred_not_member(self):
        # Build AST: yy/:ID
        idExp = AIdentifierExpression("yy")
        idExp2 = AIdentifierExpression("ID")
        notbelPred = ANotMemberPredicate()
        notbelPred.children.append(idExp)
        notbelPred.children.append(idExp2)

        #Test
        env = Environment()
        env.add_ids_to_frame(["ID","yy"])
        env.set_value("yy", "aa")
        env.set_value("ID", frozenset(["aa","bb"]))
        assert not interpret(notbelPred, env)
Esempio n. 28
0
    def test_simple_set_pred_card(self):
        # Build AST: card(S)>0
        idExp = AIdentifierExpression("S")
        cardExp = ACardExpression()
        cardExp.children.append(idExp)
        intExp = AIntegerExpression(0)
        gtPred = AGreaterPredicate()
        gtPred.children.append(cardExp)
        gtPred.children.append(intExp)

        #TestInterp
        env = Environment()
        env.add_ids_to_frame(["S"])
        env.set_value("S", frozenset(["aa","bb"]))
        assert interpret(gtPred, env)
Esempio n. 29
0
    def test_genAST_pred_fun_app2(self):
        # Build AST:
        string_to_file("#PREDICATE f:S*T>->>V & x:S*T & f(x)=y", file_name)
        ast_string = file_to_AST_str(file_name)
        root = str_ast_to_python_ast(ast_string)

        env = Environment()
        env.add_ids_to_frame(["S","T","f","V","x","y"])
        env.set_value("S", frozenset(["x1","x2"]))
        env.set_value("T", frozenset(["y1","y2"]))
        env.set_value("V", frozenset(["z1","z2","z3","z4"]))
        env.set_value("x", ("x1","y1"))
        env.set_value("f", frozenset([(("x1","y1"),"z1"),(("x2","y2"),"z2"),(("x1","y2"),"z3"),(("x2","y1"),"z4")]))
        env.set_value("y", "z1")
        assert interpret(root.children[0],env)
Esempio n. 30
0
    def test_genAST_pred_forall4(self):
        # Build AST:
        string_to_file("#PREDICATE S:POW(ID) & !(X,y).(X<:S => card(X)=y)", file_name)
        ast_string = file_to_AST_str(file_name)
        root = str_ast_to_python_ast(ast_string)

        # Test
        env = Environment()
        env._min_int = -1
        env._max_int = 5
        env.add_ids_to_frame(["S","ID"])
        env.set_value("ID", frozenset(["a","b"]))
        env.set_value("S", frozenset(["a","b"]))
        lst = [("ID", PowerSetType(SetType("ID")))]
        type_with_known_types(root.children[0], env, lst, ["S"])
        assert not interpret(root.children[0],env)