本文整理汇总了Python中util.type_with_known_types函数的典型用法代码示例。如果您正苦于以下问题:Python type_with_known_types函数的具体用法?Python type_with_known_types怎么用?Python type_with_known_types使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了type_with_known_types函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_constraint_forAll2
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))
示例2: test_types_seq_conc3
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)
示例3: test_types_lambda2
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)
示例4: test_types_simple_parprod
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"
示例5: test_types_type_arg2
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"])
示例6: test_types_ls2
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, [], [])
示例7: test_types_simple_dirprod2
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"])
示例8: test_types_simple_equal5
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, [], [])
示例9: test_types_expr_pred
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, [], [])
示例10: test_types_set_cart_tuple
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)
示例11: test_types_simple_set_empty
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)
示例12: test_types_exist3
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)
示例13: test_types_expr_minint
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)
示例14: test_types_pi
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)
示例15: test_types_simple_equal3
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"])