def test_constraint_forAll2(self): # !x.(P=>Q) # Build AST: string_to_file("#PREDICATE f={(1,7),(2,8),(3,9)} & S={1,2,3} & !(x,y).(y:INTEGER &(x:S & f(x)<y) & y<42 =>y:T)", file_name) ast_string = file_to_AST_str(file_name) root = str_ast_to_python_ast(ast_string) # Test env = Environment() lst = [("S", PowerSetType(IntegerType())),("f", PowerSetType(CartType(PowerSetType(IntegerType()), PowerSetType(IntegerType()))))] type_with_known_types(root, env, lst, ["T"]) assert isinstance(get_type_by_name(env, "x"), IntegerType) assert isinstance(get_type_by_name(env, "y"), IntegerType) assert isinstance(get_type_by_name(env, "T"), PowerSetType) assert isinstance(get_type_by_name(env, "T").data, IntegerType) env.add_ids_to_frame(["f","S","T"]) env.set_value("f", frozenset([(1,7),(2,8),(3,9)])) env.set_value("S", frozenset([1,2,3])) env.set_value("T", frozenset(range(10,42))) env._min_int = -2**8 env._max_int = 2**8 unqantPred = root.children[0].children[1] assert isinstance(unqantPred, AForallPredicate) varList = unqantPred.children[0:-1] P = unqantPred.children[-1].children[0] Q = unqantPred.children[-1].children[1] domain = compute_using_external_solver(P, env, varList) assert frozenset([x["x"] for x in domain])==frozenset([1,2,3]) domain = compute_using_external_solver(P, env, varList) assert frozenset([x["y"] for x in domain])==frozenset(range(8,42))
def test_types_seq_conc3(self): # Build AST string_to_file("#PREDICATE S=[[2, 5], [-1, -2, 9], [], [5]] & s=conc(S)", file_name) ast_string = file_to_AST_str(file_name) root = str_ast_to_python_ast(ast_string) # Type env = Environment() type_with_known_types(root, env, [], ["s", "S"]) assert isinstance(get_type_by_name(env, "s"), PowerSetType) assert isinstance(get_type_by_name(env, "s").data, CartType) assert isinstance(get_type_by_name(env, "s").data.left, PowerSetType) assert isinstance(get_type_by_name(env, "s").data.right, PowerSetType) assert isinstance(get_type_by_name(env, "s").data.left.data, IntegerType) assert isinstance(get_type_by_name(env, "s").data.right.data, IntegerType) assert isinstance(get_type_by_name(env, "S"), PowerSetType) assert isinstance(get_type_by_name(env, "S").data, CartType) assert isinstance(get_type_by_name(env, "S").data.left, PowerSetType) assert isinstance(get_type_by_name(env, "S").data.right, PowerSetType) assert isinstance(get_type_by_name(env, "S").data.left.data, IntegerType) assert isinstance(get_type_by_name(env, "S").data.right.data.data, CartType) assert isinstance(get_type_by_name(env, "S").data.right.data.data.left, PowerSetType) assert isinstance(get_type_by_name(env, "S").data.right.data.data.right, PowerSetType) assert isinstance(get_type_by_name(env, "S").data.right.data.data.left.data, IntegerType) assert isinstance(get_type_by_name(env, "S").data.right.data.data.right.data, IntegerType)
def test_types_lambda2(self): # Build AST string_to_file("#PREDICATE f=" + "%" + "(x,y).(x=0 & y=10|TRUE)", file_name) ast_string = file_to_AST_str(file_name) root = str_ast_to_python_ast(ast_string) # Type env = Environment() type_with_known_types(root, env, [], ["f", "x", "y"]) assert isinstance(get_type_by_name(env, "f"), PowerSetType) assert isinstance(get_type_by_name(env, "f").data, CartType) assert isinstance(get_type_by_name(env, "f").data.left, PowerSetType) assert isinstance(get_type_by_name(env, "f").data.right, PowerSetType) dom_type = get_type_by_name(env, "f").data.left img_type = get_type_by_name(env, "f").data.right # only present if lambda is ass. to var assert isinstance(img_type.data, BoolType) assert isinstance(dom_type.data, CartType) assert isinstance(dom_type.data.left, PowerSetType) assert isinstance(dom_type.data.right, PowerSetType) assert isinstance(dom_type.data.left.data, IntegerType) assert isinstance(dom_type.data.right.data, IntegerType) lambda_node = root.children[0].children[1] assert isinstance(lambda_node, ALambdaExpression) image_type = env.get_lambda_type_by_node(lambda_node) # this function always returns a type assert isinstance(image_type, BoolType)
def test_types_simple_parprod(self): # Build AST string_to_file("#PREDICATE r1:A<->B & r2:C<->D & r3=(r1 || r2)", file_name) ast_string = file_to_AST_str(file_name) root = str_ast_to_python_ast(ast_string) # Type env = Environment() lst = [("A", PowerSetType(SetType("X"))),("B", PowerSetType(SetType("Y"))),("C", PowerSetType(SetType("M"))),("D", PowerSetType(SetType("N")))] type_with_known_types(root, env, lst, ["r1","r2","r3"]) assert isinstance(get_type_by_name(env, "r3"), PowerSetType) assert isinstance(get_type_by_name(env, "r3").data, CartType) assert isinstance(get_type_by_name(env, "r3").data.left.data, CartType) assert isinstance(get_type_by_name(env, "r3").data.right.data, CartType) x = get_type_by_name(env, "r3").data.left.data.left.data y = get_type_by_name(env, "r3").data.left.data.right.data m = get_type_by_name(env, "r3").data.right.data.left.data n = get_type_by_name(env, "r3").data.right.data.right.data assert isinstance(x, SetType) assert isinstance(m, SetType) assert isinstance(y, SetType) assert isinstance(n, SetType) assert x.name == "X" assert y.name == "M" assert m.name == "Y" assert n.name == "N"
def test_types_type_arg2(self): # Build AST string_to_file("#PREDICATE f: NAT * NAT * BOOL --> BOOL & !(x,y,z).(f(x,y,z) = FALSE => 1+1=2)", file_name) ast_string = file_to_AST_str(file_name) root = str_ast_to_python_ast(ast_string) # Type env = Environment() type_with_known_types(root, env, [], ["f"])
def test_types_ls2(self): # Build AST: string_to_file("#PREDICATE 1*1<1+1", file_name) ast_string = file_to_AST_str(file_name) root = str_ast_to_python_ast(ast_string) # Type env = Environment() type_with_known_types(root, env, [], [])
def test_types_simple_dirprod2(self): # Build AST string_to_file("#PREDICATE f = {7|->11} & g = {7|->20} & f >< g = {(7|->(11|->20))}", file_name) ast_string = file_to_AST_str(file_name) root = str_ast_to_python_ast(ast_string) # Type env = Environment() type_with_known_types(root, env, [], ["f","g"])
def test_types_simple_equal5(self): # Build AST string_to_file("#PREDICATE 2 ** 4 = 16", file_name) ast_string = file_to_AST_str(file_name) root = str_ast_to_python_ast(ast_string) # Type env = Environment() type_with_known_types(root, env, [], [])
def test_types_expr_pred(self): # Build AST string_to_file("#PREDICATE 2=pred(3)", file_name) ast_string = file_to_AST_str(file_name) root = str_ast_to_python_ast(ast_string) # Type env = Environment() type_with_known_types(root, env, [], [])
def test_types_set_cart_tuple(self): # Build AST string_to_file("#PREDICATE x=(1,2)", file_name) ast_string = file_to_AST_str(file_name) root = str_ast_to_python_ast(ast_string) # Type env = Environment() type_with_known_types(root, env, [], ["x"]) assert isinstance(get_type_by_name(env, "x"), CartType)
def test_types_simple_set_empty(self): # Build AST string_to_file("#PREDICATE ID={} & ID<:NAT", file_name) ast_string = file_to_AST_str(file_name) root = str_ast_to_python_ast(ast_string) # Type env = Environment() type_with_known_types(root, env, [], ["ID"]) assert isinstance(get_type_by_name(env, "ID"), PowerSetType)
def test_types_exist3(self): # Build AST string_to_file("#PREDICATE #(z).(z:S) & S<:NAT", file_name) ast_string = file_to_AST_str(file_name) root = str_ast_to_python_ast(ast_string) # Type env = Environment() type_with_known_types(root, env, [], ["S"]) assert isinstance(get_type_by_name(env, "z"), IntegerType)
def test_types_expr_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) # Type env = Environment() type_with_known_types(root, env, [], ["x"]) assert isinstance(get_type_by_name(env, "x"), IntegerType)
def test_types_pi(self): # Build AST: string_to_file("#PREDICATE (PI zz . (zz:1..5 | zz))=120", file_name) ast_string = file_to_AST_str(file_name) root = str_ast_to_python_ast(ast_string) # Type env = Environment() type_with_known_types(root, env, [], []) assert isinstance(get_type_by_name(env, "zz"), IntegerType)
def test_types_simple_equal3(self): # Build AST string_to_file("#PREDICATE y=1+1", file_name) ast_string = file_to_AST_str(file_name) root = str_ast_to_python_ast(ast_string) # Type env = Environment() lst = [("y", IntegerType())] # number not important type_with_known_types(root, env, lst, ["y"])
def test_types_bool2(self): # Build AST string_to_file("#PREDICATE A=bool(1<2)", file_name) ast_string = file_to_AST_str(file_name) root = str_ast_to_python_ast(ast_string) # Type env = Environment() type_with_known_types(root, env, [], ["A"]) assert isinstance(get_type_by_name(env, "A"), BoolType)
def test_genAST_pred_pi(self): # Build AST: string_to_file("#PREDICATE (PI zz . (zz:1..5 | zz))=120", file_name) ast_string = file_to_AST_str(file_name) root = str_ast_to_python_ast(ast_string) # Test env = Environment() type_with_known_types(root.children[0], env, [], []) assert interpret(root.children[0], env)
def test_types_string(self): # Build AST string_to_file("#PREDICATE s=\"HalloWelt\"", file_name) ast_string = file_to_AST_str(file_name) root = str_ast_to_python_ast(ast_string) # Type env = Environment() type_with_known_types(root, env, [], ["s"]) assert isinstance(get_type_by_name(env, "s"), StringType)
def test_genAST_pred_set_compreh2(self): # Build AST: string_to_file("#PREDICATE (1,2):{(x,y) | x>0 & x <4 & x/=0 or y/=x}", file_name) ast_string = file_to_AST_str(file_name) root = str_ast_to_python_ast(ast_string) # Test env = Environment() type_with_known_types(root.children[0], env, [], []) assert interpret(root,env)
def test_genAST_pred_fun_app5(self): # Build AST: string_to_file("#PREDICATE f={(2,42),(1,777)} & #z.(z:NAT & 42=f(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 type_with_known_types(root.children[0], env, [], ["f"]) assert interpret(root,env)
def test_types_simple_mul_unify2(self): # Build AST string_to_file("#PREDICATE 42=a*b", file_name) ast_string = file_to_AST_str(file_name) root = str_ast_to_python_ast(ast_string) # Type env = Environment() type_with_known_types(root, env, [], ["b","a"]) assert isinstance(get_type_by_name(env, "a"), IntegerType) assert isinstance(get_type_by_name(env, "b"), IntegerType)
def test_types_interval2(self): # Build AST: string_to_file("#PREDICATE x=1..5", file_name) ast_string = file_to_AST_str(file_name) root = str_ast_to_python_ast(ast_string) # Type env = Environment() type_with_known_types(root, env, [], ["x"]) assert isinstance(get_type_by_name(env, "x"), PowerSetType) assert isinstance(get_type_by_name(env, "x").data, IntegerType)
def test_types_function_app2(self): # Build AST string_to_file('#PREDICATE f= {1 |-> "aa", 2 |-> "bb"}(xx) & xx=1 ', file_name) ast_string = file_to_AST_str(file_name) root = str_ast_to_python_ast(ast_string) # Type env = Environment() type_with_known_types(root, env, [], ["xx", "f"]) assert isinstance(get_type_by_name(env, "f"), StringType) assert isinstance(get_type_by_name(env, "xx"), IntegerType)
def type_check_sequence(self, ast_string): root = str_ast_to_python_ast(ast_string) # Type env = Environment() lst = [("S", PowerSetType(SetType("X")))] type_with_known_types(root, env, lst, ["s"]) assert isinstance(get_type_by_name(env, "s"), PowerSetType) assert isinstance(get_type_by_name(env, "s").data, CartType) assert isinstance(get_type_by_name(env, "s").data.left.data, IntegerType) assert isinstance(get_type_by_name(env, "s").data.right.data, SetType)
def test_types_set_power_unify2(self): # Build AST string_to_file("#PREDICATE 1:S ", file_name) ast_string = file_to_AST_str(file_name) root = str_ast_to_python_ast(ast_string) # Type env = Environment() type_with_known_types(root, env, [], ["S"]) assert isinstance(get_type_by_name(env, "S"), PowerSetType) assert isinstance(get_type_by_name(env, "S").data, IntegerType)
def test_types_seq_size(self): # Build AST string_to_file("#PREDICATE s:perm(S) & x=size(s)", file_name) ast_string = file_to_AST_str(file_name) root = str_ast_to_python_ast(ast_string) # Type env = Environment() lst = [("S", PowerSetType(SetType("X")))] type_with_known_types(root, env, lst, ["x", "s"]) assert isinstance(get_type_by_name(env, "x"), IntegerType)
def test_types_simple_equal2(self): # Build AST string_to_file("#PREDICATE y=x", file_name) ast_string = file_to_AST_str(file_name) root = str_ast_to_python_ast(ast_string) # Type env = Environment() lst = [("y", IntegerType())] type_with_known_types(root, env, lst, ["x"]) assert isinstance(get_type_by_name(env, "x"), IntegerType)
def test_types_range(self): # Build AST string_to_file("#PREDICATE r:S<->T & x:ran(r)", file_name) ast_string = file_to_AST_str(file_name) root = str_ast_to_python_ast(ast_string) # Type env = Environment() lst = [("S", PowerSetType(SetType("X"))),("T", PowerSetType(SetType("Y")))] type_with_known_types(root, env, lst, ["r","x"]) assert isinstance(get_type_by_name(env, "x"), SetType) assert get_type_by_name(env, "x").name == "Y"
def test_types_simple_rev(self): # Build AST string_to_file("#PREDICATE r:A<->B & f = r~ & x:dom(f)", file_name) ast_string = file_to_AST_str(file_name) root = str_ast_to_python_ast(ast_string) # Type env = Environment() lst = [("A", PowerSetType(SetType("X"))),("B", PowerSetType(SetType("Y")))] type_with_known_types(root, env, lst, ["r","x","f"]) assert isinstance(get_type_by_name(env, "x"), SetType) assert get_type_by_name(env, "x").name =="Y"
def test_types_simple_sub_res(self): # Build AST string_to_file("#PREDICATE r:A<->B & v=S <| r", file_name) ast_string = file_to_AST_str(file_name) root = str_ast_to_python_ast(ast_string) # Type env = Environment() lst = [("S", PowerSetType(SetType("X"))),("A", PowerSetType(SetType("X"))),("B", PowerSetType(SetType("Y")))] type_with_known_types(root, env, lst, ["r","v"]) assert isinstance(get_type_by_name(env, "v"), PowerSetType) assert isinstance(get_type_by_name(env, "v").data, CartType)