Skip to main content

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.abcD = b² − 4acExpected output
105050–Not a quadratic equation
2150502300Real roots
3505050−7500Imaginary roots
4995050−17300Imaginary roots
51005050−17500Imaginary roots
650050−10000Imaginary roots
750150−9999Imaginary roots
8509950−199Imaginary roots
950100500Equal roots
10505002500Real roots
11505012300Real roots
12505099−17300Imaginary roots
135050100−17500Imaginary 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:

abcExpected output
−15050Invalid input
1015050Invalid input
50−150Invalid input
5010150Invalid input
5050−1Invalid input
5050101Invalid 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)

All Software Engineering chapter 8 questions →