Generate boundary Value analysis, robust and worst-case test case for the program to find the median of three numbers. Its input is a triple of positive integers (say x, y, and z) and the minimum value can be 100 and maximum can be 500.

**Median** of three numbers is the middle number when all three numbers are sorted.

**Example –**

10, 40, 20

In this case, the median is 20 (10, 20, 40).

**1. Boundary Value Test Cases** are –

for x, y, z : min value = 100 close to min = 101 nominal = 300 close to max = 499 max = 500

Test cases are,

4*3 + 1 = 13

X | Y | Z | Median |
---|---|---|---|

100 | 300 | 300 | 300 |

101 | 300 | 300 | 300 |

300 | 300 | 300 | 300 |

499 | 300 | 300 | 300 |

500 | 300 | 300 | 300 |

300 | 100 | 300 | 300 |

300 | 101 | 300 | 300 |

300 | 499 | 300 | 300 |

300 | 500 | 300 | 300 |

300 | 300 | 100 | 300 |

300 | 300 | 101 | 300 |

300 | 300 | 499 | 300 |

300 | 300 | 500 | 300 |

**2. Robust Test Cases –**

Here, we go outside the legitimate boundary, it is an extension of boundary value analysis.

for x, y, z : min value : 100 close to min : 101 nominal : 300 close to max : 499 max : 500 lesser than min value : 99 larger than max value : 501

Total test cases,

= 6*n+1 = 6*3+1 = 19

So there will be extra 6 cases apart from the above 13 cases –

X | Y | Z |
---|---|---|

99 | 300 | 300 |

501 | 300 | 300 |

300 | 99 | 300 |

300 | 501 | 300 |

300 | 300 | 99 |

300 | 300 | 501 |

**3. Worst Test Cases –**

If we reject “single” fault assumption theory of reliability, and consider cases where more than 1 variable has extreme values, then it is known as worst case analysis.

Total no. of test cases,

5^n = 5^3 = 125 cases

X | Y | Z | Median |
---|---|---|---|

100 | 100 | 100 | 100 |

101 | 100 | 100 | 100 |

300 | 100 | 100 | 100 |

499 | 100 | 100 | 100 |

500 | 100 | 100 | 100 |

100 | 101 | 100 | 100 |

101 | 101 | 100 | 101 |

300 | 101 | 100 | 101 |

499 | 101 | 100 | 101 |

… | … | … | … |

Mathematically, the test cases will be a cross product of 3 sets –

{100, 101, 300, 499, 500} x {100, 101, 300, 499, 500} x {100, 101, 300, 499, 500}

Let set A,

= {100, 101, 300, 499, 500}

So, the set of worst cases will be represented by,

= A x A x A

Attention reader! Don’t stop learning now. Get hold of all the important CS Theory concepts for SDE interviews with the **CS Theory Course** at a student-friendly price and become industry ready.