1

I have a function that returns: if x=2y is true., x and y are both digits. A sample code is below:

public class MyClass {

  static boolean xDoubleY(int x, int y) {
    boolean result;
    int temp;

    temp = y * 2;
    if (x == temp) {
        result = true;
        System.out.println("X is twice Y");
    } else {
        result = false;
        System.out.println("X is not twice Y");
    }
    return result;
  }

  public static void main(String[] args) {       
    boolean result1,result2;
    int x1=4;
    int y1=2;
    int x2=5;

    result1 = xDoubleY(x1, y1);
    result2 = xDoubleY(x2, y1);      
 }
}

On one hand, I can think of values for each x and y which are less than, equal or more than zero.

On the other hand, I can think of relation of x and y, and which values would make the expression invalid/valid.

What would be the correct way of finding the correct partitions for this case?

Also, how can boundary value analysis be performed since we have two variables?

4
  • Can you show the actual code
    – Amias
    Commented Jan 28, 2019 at 23:40
  • @Amias, thanks, actually since this is Black Box testing, the code should matter.
    – User 19826
    Commented Jan 29, 2019 at 5:25
  • @Fabiana, the code always matters: Depending on the implementation, you will have overflows errors with different values. Commented Jan 29, 2019 at 6:13
  • @JoãoFarias I added a sample Java code
    – User 19826
    Commented Jan 29, 2019 at 9:31

1 Answer 1

1

You will have three possible outputs:

  • True:
    • this will depend on both X and Y. You can pick boundary values for X => { -1, 0, 1 } and its associated values for Y. You do the same for Y => {-1, 0, 1}.
  • False:
    • The same as above, but the "associated" value should yield a False result.
  • Invalid:
    • It seems to me that the only way to raise an exception is to create an overflow on y*2. Then, you can use y with { (Max int / 2) - 1, (Max int / 2), ( Max int / 2 ) + 1 }.

The values {(Max int / 2) - 1, (Max int / 2)} for y are actually valid - so you can create pairs with x values that will return true and false.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.