nus-cs2103-AY2425S1 / forum

11 stars 0 forks source link

Path Coverage for loops #886

Closed seah-minlong closed 2 days ago

seah-minlong commented 3 days ago

Just to clarify, when it is said that a loop can increase path coverage greatly, it is not really due to the loop itself but the fact that names can be of variable length right?

image

For instance, a fixed loop would only have 1 path. Is that correct?

void foo (String s) {
  for (int i = 0; i < 10; i++) {
    print("Hello World");
  }
}
gohsl99 commented 3 days ago

For your example, I think there is only one path because the for loop will iterate 10 times regardless.

DennieDan commented 3 days ago

Yes, I think you are right.

image

As per this example, I believe we need Integer.MAX_VALUE + 1 test cases:

damithc commented 2 days ago

@seah-minlong

Just to clarify, when it is said that a loop can increase path coverage greatly, it is not really due to the loop itself but the fact that names can be of variable length right?

Yes, specifically, a loop with a loop count that is not pre-determined.

For instance, a fixed loop would only have 1 path. Is that correct?

Yes, correct.

@DennieDan The image is missing in your comment.

For your example, I think there is only one path because the for loop will iterate 10 times regardless.

@gohsl99 Correct.

seah-minlong commented 2 days ago

Okay thank you prof!

DennieDan commented 2 days ago

@damithc I updated my image, it is actually the example given by @seah-minlong