cqfn / jpeek

Hosted and command-line calculator of cohesion metrics for Java code
https://i.jpeek.org
MIT License
209 stars 81 forks source link

Problem with CCM metric addition #522

Open User123363 opened 3 years ago

User123363 commented 3 years ago

The problem with CCM metrics was found in the file "org/jpeek/metrics/CCM.xsl" in line 65 the variable 'ncc' is assigned the number of methods connected by edges, but^ according to the definition NCC is the number of connectivity components in a graph.

Definition of graph component - https://en.wikipedia.org/wiki/Component_(graph_theory)

An example implementation of an algorithm for finding connectivity components in a graph - https://www.geeksforgeeks.org/connected-components-in-an-undirected-graph/

The class on which the metric works in error:

public class Worker {

    String name;

    public void one() {
        name = "1";
    }

    public void two() {
        name = "2";
    }

    public void three() {
        name = "3";
    }

    public void four() {
        name = "4";
    }

    public void five() {
        name = "5";
    }

}

Снимок экрана 2021-05-06 в 16 08 32

In the above example you can see that all 5 methods are one connectivity component, however, jpeek says that NCC = 5, so we can conclude that instead of connectivity components he counts the number of connected methods.

According to the definition of CCM, the class given as an example should get a score of 1 because:

Снимок экрана 2021-05-06 в 16 13 26

Indeed, if we calculate the connectivity components of the graph from the example, then NCC = 1, substituting the correct value in the formula:

Снимок экрана 2021-05-06 в 16 14 52

The CCM metric will be 1, this will be the correct answer.

starkda commented 8 months ago

@yegor256 i want to take that issue. Do you think implementing dfs inside xsl file is a good approach?

yegor256 commented 8 months ago

@starkda you can try. Indeed, implementing all metrics in XSL is what this project is about. Only if it's absolutely impossible to do so, we resort to Java.

starkda commented 8 months ago

@yegor256 now i am quite confident that using java is the only applicable approach. What i want to do is to append information about connectivity components to the end skeleton.xml after it is generated so ccm.xsl would capture it. What do you think?

yegor256 commented 8 months ago

@starkda let's try!