Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I determine branch coverage (from a control flow graph)?

I have the following piece of code (doesn't matter if it's a good method or not):

public boolean adjacent(Cell otherCell) {

  boolean result;
  boolean xdiffersone = Math.abs(getX() - otherCell.getX()) == 1;
  boolean ydiffersone = Math.abs(getY() - otherCell.getY()) == 1;

  if((xdiffersone && !ydiffersone) || (!xdiffersone && ydiffersone)) {

    result = true;
  }
  else {
    result = false;
  }

  return result;
}

The control flow graph of this method:

control flow graph

I know that statement coverage means whether all the nodes in a control flow graph have been executed/visited. But what exactly is branch coverage? How can I calculate/see that from a control flow graph (or from the code)?

like image 479
Loolooii Avatar asked Dec 11 '25 20:12

Loolooii


1 Answers

Statement coverage is about graph nodes. Branch coverage is about graph edges.

like image 147
Oliver Charlesworth Avatar answered Dec 14 '25 10:12

Oliver Charlesworth



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!