Ejemplo n.º 1
0
 def test_build_method_matrix_clsgen(self, cls_gen):
     weight_ssm = 0.5
     weight_cdm = 0.5
     metrics = [(StructuralSimilarityBetweenMethods(), weight_ssm),
         (CallBasedDependenceBetweenMethods(), weight_cdm)]
     cmmm = CrisMethodByMethodMatrix(metrics)
     for simple_cls in cls_gen.generate(100, 10, 10):
         cls_source = simple_cls.get_source_code()
         logging.info("TestCrisMethodByMethodMatrix::" + \
             "test_build_method_matrix:simple_cls.source_code:\n" + \
             cls_source)
         custom_matrix = simple_cls.get_matrix(weight_ssm, weight_cdm)
         ast_wrapper = AstClassWrapper(simple_cls.get_ast_node())
         method_matrix = cmmm.build_method_matrix(ast_wrapper)
         logging.info("\ncustom_matrix:\n" + str(
             print_matrix(custom_matrix)))
         matrix = method_matrix.get_matrix()
         logging.info("\nmatrix_under_test:\n" + str(print_matrix(matrix)))
         assert matrix == custom_matrix
Ejemplo n.º 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)