---
title: "Test cases for a quadratic equation program"
subject: "Software Engineering"
chapter: 8
key: "semester_5/software_engineering:quadratic-test-cases"
source: https://www.bctengineer.com/q/semester_5/software_engineering/quadratic-test-cases
site: BCT Engineering
---

# Test cases for a quadratic equation program

Software Engineering · Chapter 8: Software Testing and cost Estimation

- Asked in: 2068 Chaitra, 5 marks
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_5/software_engineering/quadratic-test-cases
- Whole chapter: https://www.bctengineer.com/md/semester_5/software_engineering/chapter-8

## Question

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.

## 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.

## Answer

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).

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. For a quadratic with a != 0, D = b^2 - 4ac. Which is correct?
   A. D < 0 gives real roots
   B. D = 0 gives equal roots
   C. D > 0 gives imaginary roots
   D. D = 0 gives imaginary roots
   Answer: B. D > 0 gives real roots, D = 0 equal roots, D < 0 imaginary roots. a = 0 is not quadratic. (Key point: Discriminant rules)

2. How many boundary value test cases does the answer use for 3 variables?
   A. 3
   B. 9
   C. 13 (4n + 1)
   D. 27
   Answer: C. Each variable takes min, min+, nominal, max- and max while the others stay nominal, giving 4n + 1 = 13. (Key point: Number of BVA cases)

3. What extra values does robustness testing add, and how many cases result?
   A. -1 and 101, giving 6n + 1 = 19
   B. 0 and 100, giving 13
   C. 50 only, giving 3
   D. 1 and 99, giving 9
   Answer: A. Robustness adds values just outside the range (-1 and 101) for each variable, giving 6n + 1 = 19 cases. (Key point: Robustness cases)

## Related in Software Engineering

- [Why unit tests are not enough](https://www.bctengineer.com/question.md?key=semester_5%2Fsoftware_engineering%3Aunit-test-not-enough) — Software Engineering, chapter 8

## Related in other subjects

- [Quadratic equation roots in FORTRAN](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Afortran-quadratic-roots) — Computer Programming, chapter 11, asked 2×
- [Roots of quadratic equation in C](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Aquadratic-roots-c) — Computer Programming, chapter 5
- [Algorithm and flowchart: quadratic roots](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Aalgo-flowchart-quadratic) — Computer Programming, chapter 2
- [Poker test, 10,000 four-digit values (2070)](https://www.bctengineer.com/question.md?key=semester_8%2Fsimulation_and_modeling%3Apoker-test-numerical-2070-bhadra) — Simulation and Modeling, chapter 6
