nus-cs2103-AY2223S2 / forum

12 stars 0 forks source link

Question on practice exam part 3 #426

Closed Nicklelodeon closed 1 year ago

Nicklelodeon commented 1 year ago

Hi, in the question given below, it mentions a boundary partition is [-MAX..27], which I assume means MIN_INT to 27. However, in this case, shouldnt this boundary be split into [MIN_INT..0] and [0..27]?

Screenshot 2023-04-25 at 4 39 27 PM
joellow88 commented 1 year ago

The equivalence partitions are as such as in the range [MIN_INT..27], the expected return value of isValidMonthSize() is always false; ie: No month can have 27 days or less.

Similarly, in the range [28..31], the expected return value is always true, and for [32..MAX_INT], expected return value is false. Those form the 3 equivalence partitions.

damithc commented 1 year ago

@joellow88 I think @Nicklelodeon is asking if negative values should be put into a separate partition, rather than lump together into [-MAX..27] partition.

Zxun2 commented 1 year ago

@Nicklelodeon I assume you meant EP instead of boundary partitions (?) From the book,

The partitions derived depend on how one ‘speculates’ the SUT to behave internally. Applying EP under a glassbox or gray-box approach can yield more precise partitions

Since the underlying implementation is not provided, different people might have different ideas about how the underlying implementation is like. For example, one way to implement isValidMonthSize would be:

boolean isValidMonthSize(int days) {
    return days >= 27 && days <= 31;
}

resulting in a partitioning of [MIN_INT...27][27...31][32...MAX_INT]. On the other hand,

boolean isValidMonthSize(int days) {
    if (days < 0) return false; 
    if (days < 28) return false; 
    return days >= 27 && days <= 31;
}

is also a possible implementation, that will give the partition that OP desires. In fact, in the book, there was a similar example given

image

One might argue that the partition ["f", "t", "d"] is redundant. But again, it is rather dependent on the underlying implementation.

In my opinion, you should at least ensure that the partitions you proposed is consistent with the expected behavior. Please correct me if i'm wrong!

Nicklelodeon commented 1 year ago

Ahh ok I get it thanks!! @joellow88 @Zxun2

damithc commented 1 year ago

Good answer @Zxun2

Yup, if we anticipate that the execution path for [MIN_INT..0] will be different from the path for [0..27] or if we think it is possible for a certain bug to happen in [MIN_INT..0] but not in [0..27], we can put have them as separate partitions. Otherwise no need.