- 2068 Chaitra · 5 marks
Test cases for a quadratic equation program
Short answer
Use boundary value analysis: for each of a, b, c take 0, 1, 50, 99, 100 with other variables at 50, giving 13 test cases. Expected outputs: a=0 gives Not quadratic; D=b^2-4ac positive gives Real, zero Equal, negative Imaginary. Robustness adds 6 invalid cases at -1 and 101.
Consider a program for the determination of the nature of roots of a quadratic equation. Its input is a triple of positive integers (say a, b, c) and values may be from interval [0, 100]. The program output may have one of the following words. [Not a quadratic equation; Real roots; Imaginary roots; Equal roots]. Design test cases to test this program.
The input domain of each of a, b and c is [0, 100]. Although the question says "positive", 0 is included in the interval and is needed for the output "Not a quadratic equation" (a = 0), so 0 is treated as a valid input. The nature of the roots depends on the discriminant D = b² − 4ac:
- a = 0 → Not a quadratic equation
- D > 0 → Real roots
- D = 0 → Equal roots
- D < 0 → Imaginary roots
Boundary value analysis
Boundary value analysis (BVA) tests each variable at min (0), min+ (1), nominal (50), max− (99) and max (100), keeping the other two variables at nominal. For n = 3 variables this gives 4n + 1 = 13 test cases.
| No. | a | b | c | D = b² − 4ac | Expected output |
|---|---|---|---|---|---|
| 1 | 0 | 50 | 50 | – | Not a quadratic equation |
| 2 | 1 | 50 | 50 | 2300 | Real roots |
| 3 | 50 | 50 | 50 | −7500 | Imaginary roots |
| 4 | 99 | 50 | 50 | −17300 | Imaginary roots |
| 5 | 100 | 50 | 50 | −17500 | Imaginary roots |
| 6 | 50 | 0 | 50 | −10000 | Imaginary roots |
| 7 | 50 | 1 | 50 | −9999 | Imaginary roots |
| 8 | 50 | 99 | 50 | −199 | Imaginary roots |
| 9 | 50 | 100 | 50 | 0 | Equal roots |
| 10 | 50 | 50 | 0 | 2500 | Real roots |
| 11 | 50 | 50 | 1 | 2300 | Real roots |
| 12 | 50 | 50 | 99 | −17300 | Imaginary roots |
| 13 | 50 | 50 | 100 | −17500 | Imaginary roots |
All four outputs are covered.
Robustness test cases
Robustness testing also tries values just outside the range (−1 and 101), giving 6n + 1 = 19 cases. The 6 extra cases are:
| a | b | c | Expected output |
|---|---|---|---|
| −1 | 50 | 50 | Invalid input |
| 101 | 50 | 50 | Invalid input |
| 50 | −1 | 50 | Invalid input |
| 50 | 101 | 50 | Invalid input |
| 50 | 50 | −1 | Invalid input |
| 50 | 50 | 101 | Invalid input |
Output-based equivalence classes
One more test for each output class, to check the logic away from the boundaries: (0, 10, 10) → Not quadratic; (1, 50, 1) → Real (D = 2496); (1, 2, 1) → Equal (D = 0); (2, 3, 4) → Imaginary (D = −23).
✓ Answer checked by Claude Opus 5.5 (high effort)
Related questions
- Why unit tests are not enough · Software Engineering, chapter 8
- Quadratic equation roots in FORTRAN · Computer Programming, chapter 11 · asked 2×
- Roots of quadratic equation in C · Computer Programming, chapter 5
- Algorithm and flowchart: quadratic roots · Computer Programming, chapter 2
- Poker test, 10,000 four-digit values (2070) · Simulation and Modeling, chapter 6