Topic
  • 3 replies
  • Latest Post - ‏2006-12-23T15:18:33Z by SystemAdmin
SystemAdmin
SystemAdmin
210 Posts

Pinned topic How JavaNCSS calculates cylcometric complexity

‏2006-10-19T16:42:04Z |
When experimenting with JavaNCSS I noticed that it's CC numbers were higher than other tools reported. I checked with the author and apparently return statements also increment the CCN. This seems to be different than standard practice and would definitely impact anyone using CCN as a guide to the number of unit tests needed for true 100% code coverage.
Updated on 2006-12-23T15:18:33Z at 2006-12-23T15:18:33Z by SystemAdmin
  • SystemAdmin
    SystemAdmin
    210 Posts

    Re: How JavaNCSS calculates cylcometric complexity

    ‏2006-10-20T14:24:40Z  
    It would be interesting if you could post some sample code and the different CCN numbers reported by the tools you looked at.
  • SystemAdmin
    SystemAdmin
    210 Posts

    Re: How JavaNCSS calculates cylcometric complexity

    ‏2006-10-24T14:20:34Z  
    It would be interesting if you could post some sample code and the different CCN numbers reported by the tools you looked at.
    For the example below JavaNCSS report CCN as 7. CheckStyle and the net.sourceforge.metrics plugin for Eclipse both report 4 (1 + 1 for each if statement). JavaNCSS increments the CCN for each return (over one) and each throws statement.

    public int execute(String[] args) {
    if (args.length == 0) {
    throw new RuntimeException();
    }

    if (args.length == 1) {
    return 1;
    }

    if (args.length == 2) {
    return 2;
    }

    return args.length;
    }
  • SystemAdmin
    SystemAdmin
    210 Posts

    Re: How JavaNCSS calculates cylcometric complexity

    ‏2006-12-23T15:18:33Z  
    For the example below JavaNCSS report CCN as 7. CheckStyle and the net.sourceforge.metrics plugin for Eclipse both report 4 (1 + 1 for each if statement). JavaNCSS increments the CCN for each return (over one) and each throws statement.

    public int execute(String[] args) {
    if (args.length == 0) {
    throw new RuntimeException();
    }

    if (args.length == 1) {
    return 1;
    }

    if (args.length == 2) {
    return 2;
    }

    return args.length;
    }
    For more thoughts on Cyclomatic complexity, check out "Complexity in multiple dimensions" at http://www.testearly.com/2006/12/19/complexity-in-multiple-dimensions/