03 Quiz: Equivalence Classes
November 2025 (2802 Words, 16 Minutes)
Instructions
- This quiz tests your understanding of key concepts from Chapter 03 (Testing Basics): Equivalence Classes
- Each question has 4 options with exactly one correct answer
- Try to answer without referring to the lecture materials first
- Focus on understanding concepts, not memorizing specific numbers or code
- Take your time to think through each question
Question 1: Definition of Equivalence Classes
What is the primary purpose of equivalence class partitioning in testing?
A) To test every possible input value exhaustively
B) To group similar inputs that produce the same category of behavior and test one representative from each group
C) To focus only on boundary values between input ranges
D) To eliminate the need for any testing by proving correctness mathematically
Show Answer
Correct Answer: B
Equivalence class partitioning groups inputs that are expected to be processed in the same way by the function, producing the same category of output or behavior. By testing one representative from each group, we achieve high test coverage without exhaustive testing. Option A is impossible (32 billion years!), C describes boundary value analysis (a different technique), and D is not achievable for most real-world software.
Question 2: Key Properties of Equivalence Classes
Which of the following is NOT a required property of equivalence classes?
A) Disjoint - each input belongs to exactly one equivalence class
B) Complete - every possible input belongs to some equivalence class
C) Representative - test one value from each class instead of all values
D) Ordered - equivalence classes must be tested in a specific sequence
Show Answer
Correct Answer: D
Equivalence classes do not need to be tested in any particular order. The three required properties are: disjoint (no overlap between classes), complete (all inputs are covered), and representative testing (test one value per class). The order of testing doesn’t affect the validity of the equivalence class partition.
Question 3: Output Categories Determine Input Classes
For the function reciprocal_sum(x, y, z) = 1/(x+y+z), how many equivalence classes are there?
A) 27 classes (3 parameters × 3 possible signs = 3³)
B) 9 classes (3 parameters × 3 possible values)
C) 3 classes (based on the sign of the sum: positive, negative, or zero)
D) Infinite classes (because inputs are continuous floats)
Show Answer
Correct Answer: C
Even though the function has 3 parameters, there are only 3 equivalence classes! The key insight from white-box testing is that the function computes total = x + y + z first, then returns 1/total. What matters is the sum, not individual parameter values. The three output categories are: positive result (sum > 0), negative result (sum < 0), and error (sum ≈ 0). This is a critical concept: output categories determine input classes, not the number of input parameters.
Question 4: White-Box vs. Black-Box Testing
How does white-box testing help with finding equivalence classes?
A) It eliminates the need for equivalence classes entirely
B) It allows you to see the implementation and identify what determines the output (e.g., that reciprocal_sum computes x+y+z first)
C) It requires testing all possible combinations of inputs
D) It only works for functions with fewer than 3 parameters
Show Answer
Correct Answer: B
White-box testing means you can see the implementation code. This reveals exactly what determines the function’s behavior. For example, seeing total = x + y + z in reciprocal_sum immediately tells you that the sum is what matters, not individual parameter values. This makes finding equivalence classes easier and more accurate than black-box testing where you’d have to guess based on the function signature and documentation.
Question 5: Granularity of Partitions
For reciprocal(x) = 1/x, you could choose 2 classes (non-zero, zero) or 3 classes (positive, negative, zero). What determines which is better?
A) The 3-class partition is always mathematically correct; the 2-class partition is wrong
B) The number of input parameters determines the number of classes
C) It’s a trade-off based on code paths, mathematical significance, bug risk, and cost of failure
D) You must always choose the partition with the most classes for maximum coverage
Show Answer
Correct Answer: C
Both partitions are mathematically valid! The choice depends on your testing goals. The 3-class partition (positive/negative/zero) catches sign-related bugs and is usually better for mathematical functions. The 2-class partition (non-zero/zero) is faster but might miss sign bugs. Factors to consider: code branches, mathematical properties, domain significance, bug risk history, and cost of failure. Granularity is a design choice, not a mathematical mandate.
Question 6: Zero as a Special Case
Why does calculate_ray_slope(angle) have 4 equivalence classes instead of 3?
A) Because it has more code lines than reciprocal(x)
B) Because zero (horizontal ray) has special geometric significance, separating it from positive/negative slopes
C) Because it uses NumPy instead of plain Python
D) Because the function signature is longer
Show Answer
Correct Answer: B
The function has 4 classes (downward/horizontal/upward/vertical) instead of 3 because zero (horizontal ray) has critical geometric significance in ray tracing. Horizontal rays (slope = 0) behave fundamentally differently than angled rays. Additionally, vertical rays (±90°) return None instead of a float, creating a fourth distinct category. This demonstrates that the number of classes depends on meaningful behavioral differences, not code complexity.
Question 7: Array Structural Classes
What makes testing array-based functions more complex than testing simple numeric functions?
A) Arrays can only contain positive numbers
B) Arrays require more memory to process
C) Arrays introduce two dimensions of equivalence: structural (length, shape) and value-based (content patterns)
D) Arrays cannot be tested using equivalence classes
Show Answer
Correct Answer: C
Arrays are harder to test because they have two dimensions of equivalence classes. The structural dimension includes: empty (length 0), single element (length 1), two elements (minimum non-trivial), and many elements. The value dimension includes: all positive, all negative, mixed signs, contains zeros, all zeros. These dimensions multiply: 4 structural × 5 value = 20 potential combinations! You must consider both dimensions when designing tests.
Question 8: Over-Testing the Same Class
Which approach is wasteful?
A) Testing reciprocal(1.0), reciprocal(2.0), reciprocal(5.0), reciprocal(10.0), reciprocal(100.0)
B) Testing reciprocal(5.0), reciprocal(-5.0), reciprocal(0.0)
C) Testing reciprocal_sum(1,2,3), reciprocal_sum(-1,-2,-3), reciprocal_sum(1,-0.5,-0.5)
D) Testing calculate_ray_slope(-45), calculate_ray_slope(0), calculate_ray_slope(45), calculate_ray_slope(90)
Show Answer
Correct Answer: A
Option A tests 5 different positive numbers, but they all belong to the same equivalence class (positive inputs → positive outputs). Testing one representative (e.g., reciprocal(5.0)) is sufficient! This is over-testing - it wastes time without increasing coverage. Options B, C, and D all test different equivalence classes, so they’re efficient approaches.
Question 9: Combinatorial Explosion
For find_intersection() with 5 dimensions of complexity (array structure: 5 classes, angle: 5 classes, camera position: 6 classes, outcome: 4 classes, road shape: 3 classes), how many total combinations are theoretically possible?
A) 23 tests (5+5+6+4+3)
B) 150 tests (5×5×6)
C) 600 tests (5×5×6×4)
D) 1800 tests (5×5×6×4×3)
Show Answer
Correct Answer: C
The math is 5 × 5 × 6 × 4 = 600 tests! (We simplified road shape to avoid going over 1000). This demonstrates combinatorial explosion - complexity multiplies quickly with multiple dimensions. However, we don’t actually need all 600 tests. Human domain knowledge can reduce this to 25-30 strategic tests by recognizing which combinations are redundant or impossible (e.g., “downward ray from camera above road looking down” vs. “upward ray from camera below road looking up” test different physics).
Question 10: Human Insight vs. AI Limitations
Why can’t LLMs (like ChatGPT/Claude) simply generate all necessary tests for complex functions like find_intersection()?
A) LLMs don’t have enough computing power
B) LLMs lack geometric intuition, domain knowledge, and can’t prioritize which combinations are actually important
C) LLMs are only trained on English text, not code
D) LLMs can generate all tests perfectly; human review is unnecessary
Show Answer
Correct Answer: B
LLMs struggle with complex testing because they lack: (1) geometric intuition - can’t visualize ray-road intersections, (2) domain knowledge - don’t understand camera-road physical relationships, (3) prioritization - treat all combinations equally, don’t know what’s important, (4) edge case awareness - miss parallel rays, degenerate geometry, (5) pattern recognition - generate repetitive tests with different numbers. Humans provide domain expertise to prune 600 tests down to 25-30 strategic ones. LLMs can help implement tests, but humans must design the equivalence classes.
Question 11: Reduction Strategy
How do you practically reduce 600 potential test combinations to ~30 strategic tests?
A) Pick 30 tests randomly from the 600
B) Test only the first dimension and ignore the rest
C) Cover each dimension with 2-3 representatives, ensure all outcome types appear, and add edge cases based on domain knowledge
D) Use automated tools to generate all 600 tests
Show Answer
Correct Answer: C
The reduction strategy is: (1) Cover each dimension with 2-3 representatives (not all values), (2) Ensure all outcome types appear somewhere in the test suite (intersection found, no intersection, parallel case, etc.), (3) Add edge cases identified by domain knowledge (vertical ray, camera after road, etc.). This gives roughly: 3 + 3 + 2 + 4 + 2 = 14 base tests, plus ~10 edge cases = 25-30 tests. The key is using human insight to identify which combinations are redundant or impossible.
Question 12: Mathematical Foundation
What does the equivalence relation x ~ y mean for a function f?
A) The inputs x and y have the same numerical value
B) The outputs f(x) and f(y) belong to the same output category (e.g., both positive, both negative)
C) The inputs x and y must be tested in the same test case
D) The function f must return the exact same value for x and y
Show Answer
Correct Answer: B
The equivalence relation x ~ y means “the outputs f(x) and f(y) belong to the same output category.” For example, in reciprocal(x), we have 5.0 ~ 100.0 because both produce positive outputs (same category), even though reciprocal(5.0) = 0.2 and reciprocal(100.0) = 0.01 are different values. The relation is about behavioral similarity (same output category), not numerical equality.
Question 13: Partition Completeness
What does it mean for equivalence classes to be “complete”?
A) All test cases must pass successfully
B) Every possible input belongs to exactly one equivalence class
C) The implementation must be finished before testing
D) Testing must achieve 100% code coverage
Show Answer
Correct Answer: B
“Complete” means every possible input value belongs to some equivalence class - no input is left uncategorized. Combined with “disjoint” (no input belongs to multiple classes), this ensures the classes form a partition of the input space. For reciprocal(x), every float is either positive (E₁), negative (E₂), or zero (E₃), so E₁ ∪ E₂ ∪ E₃ = ℝ (all real numbers). Completeness guarantees we’re not missing any input categories.
Question 14: Value-Based vs. Structural Classes
For array_sum(arr), which of these is a STRUCTURAL equivalence class, not a value-based one?
A) All elements are positive
B) Array contains mixed signs (positive and negative)
C) Array has exactly two elements
D) All elements are zero
Show Answer
Correct Answer: C
“Array has exactly two elements” is a structural class - it’s about the array’s shape/length, not its content. Options A, B, and D are value-based classes - they describe what values the elements contain. Arrays require testing both dimensions: structural (empty, single, two, many elements) AND value-based (all positive, all negative, mixed, contains zeros, all zeros). This orthogonal partitioning creates the complexity of array testing.
Question 15: Equivalence Classes and Code Paths
Which statement is most accurate about equivalence classes and code paths?
A) Each equivalence class must correspond to exactly one code path through the function
B) Equivalence classes are based on output behavior categories, which often (but not always) align with code paths
C) Code paths are irrelevant to equivalence class identification
D) You need as many equivalence classes as lines of code in the function
Show Answer
Correct Answer: B
Equivalence classes are fundamentally based on output behavior categories. These often align with code paths (e.g., the if x == 0 branch in reciprocal(x) creates a distinct output category), but not always. For example, reciprocal_sum(1,2,3) and reciprocal_sum(100,-50,-44) follow the same code path but could be considered different structural classes if you care about sign combinations. The best approach uses white-box testing to identify code structure, then groups inputs by similar output behavior.
Question 16: When to Choose Fine vs. Coarse Granularity
When should you choose a FINER partition (more equivalence classes)?
A) When the function has fewer than 5 lines of code
B) When the function is security-critical, handles financial data, or has a history of bugs in that area
C) When you have less time for testing
D) When the function uses simple data types like integers
Show Answer
Correct Answer: B
Choose finer granularity (more equivalence classes) when: (1) High bug risk - the function has been problematic before, (2) Critical domain - security, finance, medical, safety systems, (3) Complex logic - many code branches and edge cases, (4) Cost of failure - bugs would be expensive or dangerous. Conversely, use coarser granularity for: simple/low-risk functions, quick smoke tests, or when resources are limited. The choice is risk-based, not based on code length or data types.
Question 17: Representative Values
What makes a good representative value for an equivalence class?
A) It must be the smallest possible value in the class
B) It should be a “typical” value that clearly belongs to the class and is easy to reason about
C) It must be a boundary value at the edge of the class
D) It should be randomly selected from the class
Show Answer
Correct Answer: B
A good representative is a typical value that clearly belongs to the class and is easy to understand. For the “positive numbers” class in reciprocal(x), we chose x = 5.0 - it’s clearly positive, produces an easy-to-verify result (0.2), and is far from boundaries. While boundary values are important (covered in boundary value analysis), they’re not the best representatives for equivalence class testing. The goal is to test the core behavior of each class with a clear, unambiguous example.
Question 18: Testing Philosophy
What is the fundamental philosophy behind equivalence class testing?
A) Test all inputs exhaustively to guarantee correctness
B) Test only the most likely inputs that users will provide
C) You’re not testing all inputs - you’re testing all behaviors by grouping similar inputs
D) Test inputs randomly until you reach a time limit
Show Answer
Correct Answer: C
The core insight of equivalence class testing is: we’re testing behaviors, not individual inputs. Instead of testing infinite inputs, we identify distinct behavioral categories (e.g., positive output, negative output, error) and test one representative from each. This achieves high confidence without exhaustive testing. The shift in mindset from “test all inputs” (impossible) to “test all behaviors” (achievable) is the foundation of practical software testing.
Scoring Guide
- 16-18 correct: Excellent! You have a strong grasp of equivalence class concepts and can apply them to real-world testing
- 13-15 correct: Good understanding! Review the questions you missed, especially around human insight and reduction strategies
- 10-12 correct: Fair understanding. Revisit the lecture sections on granularity choices and array complexity
- Below 10: Please review the lecture carefully, focusing on the core definition, key properties, and the relationship between output categories and input classes
Key Takeaways to Remember
-
Equivalence classes group inputs by similar behavior - Inputs that produce the same category of output belong to the same equivalence class
-
Three key properties - Disjoint (no overlap), Complete (all inputs covered), Representative (test one per class)
-
Output categories determine input classes - The number of equivalence classes equals the number of output categories you define, not the number of input parameters
-
White-box testing reveals what matters - Seeing the code (e.g.,
total = x+y+z) tells you what determines behavior -
Granularity is a choice - You choose coarse (2-3 classes) vs. fine (5-10 classes) based on risk, bug history, and domain criticality
-
Arrays have two dimensions - Structural (length, shape) AND value-based (content patterns) equivalence classes
-
Combinatorial explosion is real - Multiple parameters/dimensions multiply complexity (5×5×6×4 = 600 combinations!)
-
Human insight reduces complexity - Domain knowledge prunes 600 theoretical tests to 25-30 strategic ones
-
AI has limitations - LLMs lack geometric intuition, domain knowledge, and prioritization ability for complex functions
-
Test behaviors, not inputs - The fundamental shift: instead of testing all inputs (impossible), test all behavioral categories (achievable)