nus-cs2103-AY2324S2 / forum

16 stars 0 forks source link

Confusion between branch and condition coverage #1035

Closed cheahTJ closed 6 months ago

cheahTJ commented 6 months ago

What is the main distinctive difference between these 2?

dillontkh commented 6 months ago

image

if (x > 2 && x < 44) {
    // path a
} else {
    // path b
}

Given the above example, to achieve 100% branch coverage you just need to ensure your test cases hit path a and path b.

However to hit 100% condition coverage, you need to ensure that x > 2 gets evaluated to true and false, and x < 44 gets evaluated to true and false.

damithc commented 6 months ago

Good answer @dillontkh

cheahTJ commented 6 months ago

Thank you !! @dillontkh