Possibly Wrong Coverage Outcome

32 views
Skip to first unread message

Rohan Garg

unread,
May 1, 2018, 3:28:16 AM5/1/18
to JaCoCo and EclEmma Users
I have the following code :
 

package my;

import java.util.Scanner;

public class greatest {

public static void findGreat(int a,int b,int c)
{
if(a>c)
System.out.println(a+" is greatest");
else
System.out.println(c+" is greatest");
if(b>c)
System.out.println(b+" is greatest");
else
System.out.println(c+ " is greatest");
}
public static void main(String[] args) { 
// TODO Auto-generated method stub
Scanner my = new Scanner(System.in);
int a = Integer.parseInt(args[0]);
int b = Integer.parseInt(args[1]);
int c = Integer.parseInt(args[2]);
findGreat(a,b,c);
}

}


The McCabe complexity for this is 3, which is correctly reported by the tool.
However running JaCoCo for just two of the following arguments:

my.greatest 4 2 3 (TF)
my.greatest 1 3 2 (FT)

gives missed complexity as 0

Should it not report 1 as missed complexity as it still missed one of the Linearly Independent Paths?

Thanks and regards,
Rohan

Marc Hoffmann

unread,
May 2, 2018, 6:03:54 PM5/2/18
to jac...@googlegroups.com
Hi Rohan,

here you can find some details how JaCoCo calculates complexity figures:


This also includes a definition how we calculate covered/missed complexity based on covered branches. We use coverage status of branches because this is what we can measure (JaCoCo hat noch mechanism to record path coverage).

Also cyclomatic complexity is is an upper bound for the number of required test cases. In your case is is actually possible to get full branch coverage with 2 test cases. See https://en.wikipedia.org/wiki/Cyclomatic_complexity#Implications_for_software_testing

Regards,
-marc

--
You received this message because you are subscribed to the Google Groups "JaCoCo and EclEmma Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jacoco+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jacoco/9c588e6f-6ec8-4a6a-9071-d324ad1319ad%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Rohan Garg

unread,
May 3, 2018, 6:11:32 AM5/3/18
to JaCoCo and EclEmma Users
Hello Marc,

Thanks for the info.

Regards,
Rohan
Reply all
Reply to author
Forward
This conversation is locked
You cannot reply and perform actions on locked conversations.
0 new messages