Пример #1
0
 def assemble_classes(self, simple_cls):
     method_chains = simple_cls.get_method_chains(
         self.w_ssm,
         self.w_cdm,
         self.min_coupling
     )
     merged_chains = simple_cls.merge_trivial_chains(
         l_to_s(method_chains),
         self.min_length,
         self.w_ssm,
         self.w_cdm
     )
     return simple_cls.assemble_classes(merged_chains)
Пример #2
0
 def test_filter_process(self, cls_gen):
     w_ssm = 0.5
     w_cdm = 0.5
     min_coupling = 0.4
     min_length = 2
     metrics = [(StructuralSimilarityBetweenMethods(), w_ssm),
         (CallBasedDependenceBetweenMethods(), w_cdm)]
     cmmm = CrisMethodByMethodMatrix(metrics)
     cmca = CrisMethodChainsAssembler()
     ccomct = CrisCOMConstantThresholdFilter(min_coupling)
     ctcm = CrisTrivialChainMerger(metrics, min_length)
     for simple_cls in cls_gen.generate(1000, 10, 10):
         cls_source = simple_cls.get_source_code()
         self.log("simple_cls source", cls_source)
         class_node = simple_cls.get_ast_node()
         class_wrapper = AstClassWrapper(class_node)
         method_matrix = cmmm.build_method_matrix(class_wrapper)
         method_matrix_matrix = method_matrix.get_matrix()
         custom_matrix = simple_cls.get_matrix(w_ssm, w_cdm)
         filtered_matrix = ccomct.filter_process(method_matrix)
         filtered_matrix_matrix = filtered_matrix.get_matrix()
         method_chains = cmca.filter_process(filtered_matrix)
         custom_filtered_matrix = simple_cls.filter_matrix(w_ssm,
             w_cdm, min_coupling)
         self.log("filtered matrix",
             print_matrix(custom_filtered_matrix))
         assert custom_filtered_matrix == filtered_matrix_matrix
         # method_names = [[node.name for node in mc.method_ast_nodes]
         #     for mc in method_chains]
         custom_chains = simple_cls.get_method_chains(w_ssm,
             w_cdm, min_coupling)
         custom_merged_chains = simple_cls.merge_trivial_chains(
                 l_to_s(custom_chains),
                 min_length,
                 w_ssm,
                 w_cdm
             )
         merged_chains = ctcm.filter_process(method_chains)
         method_names = [x.get_method_names() for x in merged_chains]
         self.log("custom merged chains",
             print_chains(custom_merged_chains))
         self.log("pipeline merged chains",
             print_chains(method_names))
         assert len(custom_merged_chains) == len(method_names)
         assert self.compare_chains(custom_merged_chains, method_names)