nus-cs2103-AY2223S2 / forum

12 stars 0 forks source link

Question regarding Boundary value analysis #408

Closed StanleyNeoh closed 1 year ago

StanleyNeoh commented 1 year ago

Hello,

Suppose we have a function with the following equivalence partition:

I understand that some of the boundary values to consider are:

However how about the boundary values for near 0?

Should -1, 0, 1 be considered the boundary values or should it be 0, 1, 2 instead?

Thank you in advance.

hingen commented 1 year ago

From my understanding of BVA, I think there's a bit of confusion here. Using your provided EPs:

The values at the boundary are MIN_INT, 0, 1, and MAX_INT. Don't think there's any ambiguity for this.

What you're probably referring to is how to apply BVA which is described here. Quoting from the textbook:

Typically, you should choose three values around the boundary to test: one value from the boundary, one value just below the boundary, and one value just above the boundary.

Thus, a possible set of values to choose for each EP would be:

Hence, the set of possible values that covers all EPs could be: MIN_INT, MIN_INT + 1, -1, 0, 1, 2, MAX_INT - 1, MAX_INT

Notice that for MIN_INT, we don't provide a value below the boundary. We could probably do a MIN_INT - 1. However, doing so in Java would lead to an integer underflow and result in MAX_INT instead. Hence, there is no way to choose a value that is below the boundary for MIN_INT (assuming we are using the int data type). Can try running the following code to see the behaviour:

public class Main {
    public static void main(String[] args) {
        System.out.println(Integer.MIN_VALUE - 1);
    }
}

Same argument applies for why there is no value above the boundary for MAX_INT.

damithc commented 1 year ago

Good question @StanleyNeoh and good inputs @hingen

The values at the boundary are MIN_INT, 0, 1, and MAX_INT. Don't think there's any ambiguity for this.

Correct. Typically, we should give higher priority to testing them.


If we can afford a few more test cases, we can go for one non-boundary value from each partition e.g.,

MIN_INT, -5, 0, 1, 5, MAX_INT

These will catch cases where the code works on the boundary but nowhere else -- rare, but can happen (e.g., if the code used == when it should have used >=).


If we can afford even more test cases, we can test the two values adjacent to the boundary (instead of the middle):

MIN_INT, MIN_INT+1, -1, 0, 1, 2, MIN_INT - 1, MAX_INT

Note that it will be even rarer for these values to be specifically involved in the branching instructions in the code, and hence, to be the cause of a bug. So, in this case, most likely testing one value in the middle is almost as good as testing two boundary-adjacent values i.e., if the code works for 1 and 5, it is likely to work for 2 as well.