当前位置: 首页>>代码示例>>Python>>正文


Python util.get_type_by_name函数代码示例

本文整理汇总了Python中util.get_type_by_name函数的典型用法代码示例。如果您正苦于以下问题:Python get_type_by_name函数的具体用法?Python get_type_by_name怎么用?Python get_type_by_name使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了get_type_by_name函数的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))
开发者ID:hhu-stups,项目名称:pyB,代码行数:30,代码来源:test_constraintsolver.py

示例2: test_library_length

    def test_library_length(self):
        string = '''
        MACHINE LibraryStrings
        CONSTANTS length
        PROPERTIES
          /* compute the length of a string */
          length: STRING --> INTEGER &
          length = %x.(x:STRING|STRING_LENGTH(x)) 
        DEFINITIONS
          STRING_LENGTH(x) == length(x);
          EXTERNAL_FUNCTION_STRING_LENGTH == STRING --> INTEGER;
        ASSERTIONS
          length("abc") = 3;
          length("") = 0;
          length("hello") = 5
        END
        '''
        # Build AST
        string_to_file(string, file_name)
        ast_string = file_to_AST_str(file_name)
        root = str_ast_to_python_ast(ast_string)

        # Test
        env = Environment()
        dh = DefinitionHandler(env, str_ast_to_python_ast)                                   
        dh.repl_defs(root)
        mch = parse_ast(root, env)
        type_check_bmch(root, env, mch)
        assert isinstance(get_type_by_name(env, "length"), PowerSetType)
        assert isinstance(get_type_by_name(env, "length").data, CartType)
        assert isinstance(get_type_by_name(env, "length").data.left.data, StringType)
        assert isinstance(get_type_by_name(env, "length").data.right.data, IntegerType)
        arbitrary_init_machine(root, env, mch) # init VARIABLES and eval INVARIANT
        assert isinstance(root.children[4], AAssertionsMachineClause)
        interpret(root.children[4], env)
开发者ID:hhu-stups,项目名称:pyB,代码行数:35,代码来源:test_library.py

示例3: test_types_expr_leq

    def test_types_expr_leq(self):
        # Build AST
        string_to_file("#PREDICATE x<y & y=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, [], ["x","y"])
        assert isinstance(get_type_by_name(env, "x"), IntegerType)
        assert isinstance(get_type_by_name(env, "y"), IntegerType)
开发者ID:hhu-stups,项目名称:pyB,代码行数:11,代码来源:test_types_numbers.py

示例4: test_types_simple_mul_unify2

    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)
开发者ID:hhu-stups,项目名称:pyB,代码行数:11,代码来源:test_types_numbers.py

示例5: test_types_interval2

    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)
开发者ID:hhu-stups,项目名称:pyB,代码行数:11,代码来源:test_types_numbers.py

示例6: test_types_function_app2

    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)
开发者ID:hhu-stups,项目名称:pyB,代码行数:11,代码来源:test_types_functions.py

示例7: test_types_simple_set_com

    def test_types_simple_set_com(self):
        # Build AST
        string_to_file("#PREDICATE ID={x|x<10}", 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)
        assert isinstance(get_type_by_name(env, "x"), IntegerType)
开发者ID:hhu-stups,项目名称:pyB,代码行数:11,代码来源:test_types_sets.py

示例8: test_types_set_power_unify2

    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)
开发者ID:hhu-stups,项目名称:pyB,代码行数:11,代码来源:test_types_sets.py

示例9: type_check_sequence

    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)
开发者ID:hhu-stups,项目名称:pyB,代码行数:11,代码来源:test_types_functions.py

示例10: test_types_simple_pow

    def test_types_simple_pow(self):
        # Build AST
        string_to_file("#PREDICATE S=POW(B)", file_name)
        ast_string = file_to_AST_str(file_name)
        root = str_ast_to_python_ast(ast_string)

        # Type
        env = Environment()
        lst = [("B", 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, PowerSetType)
开发者ID:hhu-stups,项目名称:pyB,代码行数:12,代码来源:test_types_sets.py

示例11: test_types_simple_rev

    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"
开发者ID:hhu-stups,项目名称:pyB,代码行数:12,代码来源:test_types_relations.py

示例12: test_types_seq_last

    def test_types_seq_last(self):
        # Build AST
        string_to_file("#PREDICATE s:perm(S) & n=last(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, ["s", "n"])
        assert isinstance(get_type_by_name(env, "n"), SetType)
        assert get_type_by_name(env, "n").name == "X"
开发者ID:hhu-stups,项目名称:pyB,代码行数:12,代码来源:test_types_functions.py

示例13: test_types_simple_sub_res

    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)
开发者ID:hhu-stups,项目名称:pyB,代码行数:12,代码来源:test_types_relations.py

示例14: test_types_bool

    def test_types_bool(self):
        # Build AST
        string_to_file("#PREDICATE A:BOOL & B:BOOL & C:BOOL & (A=TRUE <=> (B=FALSE or C=FALSE)) & (B=TRUE <=> A=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, [], ["A","B","C"])
        assert isinstance(get_type_by_name(env, "A"), BoolType)
        assert isinstance(get_type_by_name(env, "B"), BoolType)
        assert isinstance(get_type_by_name(env, "C"), BoolType)
开发者ID:hhu-stups,项目名称:pyB,代码行数:12,代码来源:test_types_sets.py

示例15: test_types_function_app

    def test_types_function_app(self):
        # Build AST
        string_to_file("#PREDICATE f:S+->T & y=f(x)", file_name)
        ast_string = file_to_AST_str(file_name)
        root = str_ast_to_python_ast(ast_string)

        # Type
        env = Environment()
        lst = [("x", SetType("X")), ("S", PowerSetType(SetType("X"))), ("T", PowerSetType(SetType("Y")))]
        type_with_known_types(root, env, lst, ["y", "f"])
        assert isinstance(get_type_by_name(env, "y"), SetType)
        assert get_type_by_name(env, "y").name == "Y"
开发者ID:hhu-stups,项目名称:pyB,代码行数:12,代码来源:test_types_functions.py


注:本文中的util.get_type_by_name函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。