Learning Objectives
By the end of this lesson you will be able to:
- Identify all mathematically undefined operations relevant to software testing
- Design a complete undefined-math test suite for any calculator application
- Evaluate whether an application handles undefined math correctly
The Catalog of Undefined Mathematical Operations
Beyond division by zero, there are several other operations that are undefined or produce special values:
| Operation | Undefined/Special When | IEEE 754 Result | Integer Result |
|---|---|---|---|
a / b |
b = 0 | Infinity (float), exception (int) | Exception |
a % b |
b = 0 | NaN | Exception |
sqrt(x) |
x < 0 | NaN | Not applicable |
log(x) |
x ≤ 0 | NaN (x<0), -Infinity (x=0) | Not applicable |
pow(0, 0) |
Both zero | 1.0 (IEEE 754 convention) | Implementation-dependent |
Infinity - Infinity |
Both infinite | NaN | Not applicable |
The Testing Strategy: Probe All Singularities
For any calculator application, generate a systematic test matrix:
- Division: divisor = 0, divisor = -0 (yes, -0.0 exists in IEEE 754)
- Modulo: modulus = 0
- Square root (if present): negative input, -0
- Logarithm (if present): input = 0, input = -1
- Power (if present): base = 0 and exponent = 0
What Good Error Handling Looks Like
The application should:
- Validate inputs before performing calculations
- Return a specific, helpful error message: "Divisor cannot be zero" rather than just "Error"
- NOT display
Infinity,NaN, or a stack trace to the user - Return HTTP 400 or 422 (not 500) — the input was invalid, not the server broken
The Regression Test: Does Infinity Leak Forward?
A subtle test: what happens if one calculation produces Infinity, and you use that result as the input to a second calculation?
Step 1: Calculate 1 / 0 → "Error: divisor is zero" (correct behavior)
Step 2: If the app stores intermediate results, verify the error doesn't propagate as Infinity
In a well-designed system, each operation is validated independently. In a poorly designed system, Infinity from step 1 might silently flow into step 2.
Documenting Undefined Math Bugs
When the application returns Infinity or NaN to the user:
Title: Division form displays "Infinity" when divisor is 0.0
Steps:
1. Enter dividend: 5
2. Enter divisor: 0.0 (float zero)
3. Submit
Expected: Error message "Divisor cannot be zero"
Actual: Form displays result "Infinity"
Note: Integer input of divisor=0 correctly returns an error. Bug is specific
to float zero (0.0) being passed as the divisor.
Pro Tip: Always test both integer zero (0) and float zero (0.0) as divisors. They may follow different code paths and produce different results.
Key Takeaways
- Division, modulo, sqrt, and log all have undefined inputs that should be tested
- Both integer and float zero can be divisors — test both
- Good behavior: validate inputs, return 4xx with helpful message
- Bad behavior: display Infinity/NaN, return 500, silently produce wrong result