Im working in a java class in which I want a method to contain a division by zero fault and at least two branches, such that (1) it is possible to create a test suite that achieves 100% path coverage and does not reveal the fault, and (2) every possible test suite that achieves 100% branch coverage reveals the fault.
In a simple implementation of something like this:
int i;
read(i);
print(10/i-3);
I could have a test suite of (1,-5), (-1,2.5), and (0,-3). This achieve 100% path coverage and does not reveal the division by 0 fault. In attempting to do this using a minimum of two branches, my solutions keep coming up incorrect.
public static void dbz(int x, int y) { // Change the signature as needed
if (x > 0) {
if (y > 0) {
int result = 99 / (x - x); // This will cause division by zero if executed
System.out.println(result);
} else {
System.out.println("Branch 1");
}
} else {
System.out.println("Branch 2");
}
}
Here, 100% path coverage would require x > 0 and y > 0 causing my division by zero path to be revealed. Is this even possible?