How Can We Check a Result When We Cannot Easily Write Down Every Expected Answer? Use relationships between deliberately related inputs and their outputs. Reordering a list should not change its arithmetic mean; adding four to every entry should increase that mean by four. A program that violates a justified relationship needs investigation, even when the complete answer to a larger original task is difficult to obtain.
This international computing lab develops an original exact-arithmetic example into a practical testing method. It extends Loop Invariants and Symmetry and Invariance by comparing separate executions, then asks another learner to reproduce the checks. AI can propose tests and explanations, while learners justify their conditions. The coursework, VCE and EnDist applications are proposed frameworks, not validated interventions; future superintelligence remains hypothetical.
- Define an input transformation and the output relationship it requires.
- Derive permutation, shift, scaling and duplication checks for an arithmetic mean.
- Combine subgroup results using their sizes rather than an unweighted average.
- Expose faulty programs that pass some checks and fail others.
- Separate a valid mathematical relation from assumptions about numerical software.
- Give an unfamiliar recipient a reproducible test and an appropriately limited conclusion.
Choose your reading route
Coursework series: Loop Invariants Lab · Symmetry and Invariance Lab · Proof and Counterexample Lab · Interface Contract Studio · Vocabulary Coding and Engineering
Continue this coursework series: Interval Bounds Lab · Metamorphic Testing Lab (this article) · Evaluation Leakage Lab · Temporal Alignment and Caption Meaning Studio
Full chapter index
Chapters 1–5
Chapters 6–10
Chapters 11–15
Chapters 16–20
Chapters 21–25
Chapter 26
CHAPTER 1 OF 26 · Understand the capability
1. The capability: test a relationship between executions
A testing task can begin with a question about change: if we alter the input in a specified way, what must happen to the answer? The learner supplies the reasoning that makes this relationship necessary. The computer supplies two observed outputs. Comparing those outputs can reveal an inconsistency without requiring a separately calculated answer for every large input.
The educational target is therefore more than generating extra examples. Learners must explain why the changed input is admissible, what relationship follows, and what a failure would establish. A loop invariant concerns a property maintained during one execution. This lab instead compares different executions of the same program on deliberately related inputs.
CHAPTER 2 OF 26 · Understand the capability
2. Define the source case, follow-up case and relation
Call the original input the source case and the transformed input the follow-up case. A metamorphic relation states a necessary relationship between their correct results, under explicit conditions. A test oracle is a way to judge an output’s correctness. Here, a relationship supplies a partial check when a complete answer is inconvenient.
Chen, Cheung and Yiu’s original metamorphic-testing report develops new tests from existing cases and discusses testing when an oracle is unavailable. Our small arithmetic example deliberately has answers learners can calculate: this lets them inspect how relational checks work before applying the approach to tasks whose complete outputs are harder to verify.
CHAPTER 3 OF 26 · Understand the capability
3. Vocabulary Coding and Engineering for test specifications
Use Vocabulary Coding and Engineering, or VCE, as a proposed discipline for making the test’s meaning explicit. Define list, entry, permutation, duplicate the whole list and arithmetic mean. Reordering entries preserves how many times each value occurs. Duplicating the whole list preserves every value’s proportion. Adding one extra copy of one entry generally does neither.
Write each test as an input operation, a precondition and an expected output relationship. For example: add a rational constant c to every entry of a nonempty rational list; the resulting mean must equal the original mean plus c. This specification is precise enough for a partner to challenge, implement and check independently.
CHAPTER 4 OF 26 · Work through the example
4. The original fictional mean service
A fictional classroom service claims to return the arithmetic mean of any finite, nonempty list of rational numbers. Its mathematical contract uses exact arithmetic: M(x) equals the sum of the entries divided by their count. There are no missing values, infinities, rounding operations or hidden weights. Repeated calls use the same deterministic implementation and settings.
Start with x = [2, 5, 11]. Its count is 3, its sum is 18 and its mean is 6. This known result is a useful anchor, not a substitute for relational reasoning. Record the source input and observed output before running follow-up cases, so a later correction cannot silently replace the evidence originally collected.
CHAPTER 5 OF 26 · Work through the example
5. Permutation preserves the mean
Move the last entry to the front, producing [11, 2, 5]. The sum remains 18 and the count remains 3, so the mean remains 6. More generally, any permutation preserves the sum and count under this exact-arithmetic contract. The necessary relationship is M(permuted x) = M(x), with repeated entries retained rather than discarded.
Choose a permutation that actually changes the input order. Testing [4, 4, 4] against itself would not challenge a program that accidentally depends on the first entry. For [2, 5, 11], moving 11 to the front exposes a different path through such a faulty implementation. A useful test pair combines a justified relation with values that can reveal the suspected mistake.
CHAPTER 6 OF 26 · Work through the example
6. Adding a constant shifts the mean
Add 4 to every entry: [6, 9, 15]. The new sum is 30 and the mean is 10, which equals 6 + 4. If a list has n entries and sum S, adding c to every entry changes the sum to S + nc. Dividing by n gives S/n + c, establishing the relation for every permitted nonempty list.
The operation changes every entry, not merely the total once. Adding 4 to only the first entry would instead change this list’s mean by 4/3. Ask the learner to describe the transformation before calculating its output. That small language check prevents an apparently sophisticated test from comparing the wrong pair of inputs.
CHAPTER 7 OF 26 · Work through the example
7. Scaling every entry scales the mean
Multiply every entry by −2 to obtain [−4, −10, −22]. Their sum is −36 and their mean is −12, matching −2 × 6. For any rational factor k, the transformed sum is kS and the count is unchanged, so M(kx) = kM(x). The rule includes negative factors and zero within our declared mathematical domain.
A negative factor reverses numerical ordering, but that does not invalidate this mean relationship. It would matter for a different claim about which entry is the largest. Keep the tested quantity visible: a valid relation for one function need not apply to another. Students should derive the relation from the function’s definition rather than attach a familiar transformation to any output.
| Follow-up operation | Resulting input | Required mean |
|---|---|---|
| Reorder | [11, 2, 5] | 6 |
| Add 4 to every entry | [6, 9, 15] | 10 |
| Multiply every entry by −2 | [−4, −10, −22] | −12 |
| Repeat the whole list twice | [2, 5, 11, 2, 5, 11] | 6 |
CHAPTER 8 OF 26 · Work through the example
8. Duplicating the whole list preserves proportions
Concatenate the list with itself: [2, 5, 11, 2, 5, 11]. Its sum doubles to 36 and its count doubles to 6, leaving its mean at 6. Repeating the whole list r times has the same effect for every positive integer r: both numerator and denominator acquire the same factor. Repeating it zero times would create an excluded empty list.
Duplicating only the final entry gives [2, 5, 11, 11], whose mean is 29/4 = 7.25. This is a different transformation and must not be labelled a failed whole-list duplication test. Require the test record to include the actual follow-up list; an operation name alone may conceal an implementation mistake in the checker.
CHAPTER 9 OF 26 · Work through the example
9. Recombine subgroup means with their sizes
Split x into A = [2, 5] and B = [11]. Their means are 3.5 and 11. The complete mean is (2 × 3.5 + 1 × 11)/(2 + 1) = 6. An unweighted average of the two subgroup means gives 7.25 and incorrectly treats the two-entry subgroup as if it represented only one entry.
For nonempty lists A and B of lengths n and m, the required relationship is M(A followed by B) = (nM(A) + mM(B))/(n + m). The input lists need not have equal lengths. This relation connects three executions and can reveal errors that simpler transformations miss. Record subgroup sizes alongside their outputs so the receiver can reconstruct the comparison.
CHAPTER 10 OF 26 · Identify failure modes
10. A first-entry program passes several checks
Consider a faulty function F that returns the first entry. On [2, 5, 11], it returns 2. After adding 4 everywhere it returns 6, satisfying F(x + 4) = F(x) + 4. After multiplying by −2 it returns −4, satisfying the scaling relation. Duplicating the whole list also leaves its answer at 2.
Yet the permutation [11, 2, 5] makes F return 11, violating the requirement that reordering preserve the mean. The program was wrong even while passing three relations. A set of green checks is evidence about those checks and inputs; it is not a certificate that the output implements the intended mathematical function.
CHAPTER 11 OF 26 · Identify failure modes
11. A wrong denominator survives different checks
Now define G(x) = sum(x)/n², where n is the number of entries. On the source list, G returns 18/9 = 2. It ignores order and scales linearly, so permutation and scaling tests pass. After adding 4 everywhere, however, G returns 30/9 = 10/3, while the required shifted answer relative to G(x) would be 2 + 4 = 6.
Whole-list duplication also exposes G: the duplicated sum is 36 and the squared count is 36, producing 1 instead of the required unchanged value 2. Different relations reveal different faults. The aim is not to maximise the number of near-identical tests but to choose checks that place meaningfully different demands on the claimed implementation.
CHAPTER 12 OF 26 · Identify failure modes
12. Even the median passes many mean relations
Let H return the median, using the average of the two middle sorted values for an even-length list. It passes permutation, constant-shift, scaling and whole-list duplication relations. On [2, 5, 11], however, H returns 5 rather than the mean 6. These familiar relationships alone do not distinguish the two mathematical functions.
Use unequal partitions A = [1, 2, 3] and B = [100]. Their medians are 2 and 100, so size-weighted recombination gives (3 × 2 + 100)/4 = 26.5. The median of the combined list is 2.5, not 26.5. The correct combined mean is 26.5. This counterexample shows why additional properties and direct known-answer cases remain valuable.
| Faulty function | Checks it can pass | A revealing failure |
|---|---|---|
| First entry | Shift, scaling, whole-list duplication | Reorder [2, 5, 11] to [11, 2, 5]: 2 becomes 11 |
| Sum divided by n² | Permutation and scaling | Duplicate [2, 5, 11]: 2 becomes 1 |
| Median | Permutation, shift, scaling, whole-list duplication | Partition [1, 2, 3] and [100]: required recombination 26.5 differs from median 2.5 |
CHAPTER 13 OF 26 · Identify failure modes
13. Check the domain before applying the relation
Every relation carries conditions. The mean service excludes the empty list, so deleting all entries does not create a valid mean comparison. The partition rule requires two nonempty subgroups because each subgroup mean must exist. Scaling by zero remains valid: the list still has entries, all now zero. Empty and zero-valued are different states.
A singleton list is allowed, but it is a weak choice for exposing the first-entry fault because the first entry is its correct mean. Include lists with different lengths, signs, repeated entries and unequal values for specified reasons. A random collection of inputs may help explore cases, but it does not replace explaining why the selected cases challenge a particular assumption.
CHAPTER 14 OF 26 · Identify failure modes
14. Interpret a failed relation precisely
If a justified relation fails under its stated conditions, the complete test setup is inconsistent with the specification. At least one program output, input transformation, comparison or declared assumption needs investigation. A relation comparing two unfamiliar outputs does not automatically identify which individual output is wrong. Inspect the test harness as well as the program being tested.
For G’s duplication failure, the record should retain both input lists, lengths 3 and 6, outputs 2 and 1, and the required equality. Our direct calculations additionally establish that both outputs are wrong: each true mean is 6. That stronger conclusion comes from extra known-answer evidence, not from the unequal pair alone.
CHAPTER 15 OF 26 · Identify failure modes
15. Distinguish exact arithmetic from machine arithmetic
The worked derivations use rational arithmetic without rounding. Actual numerical software may approximate values and accumulate rounding effects. The official Python explanation of floating-point arithmetic describes binary approximation, representation error and comparisons of inexact values. An exact mathematical equality therefore needs a justified numerical interpretation before it becomes a floating-point test.
Keep the classroom calculations exact first. For a later implementation, state the number format, accumulation method and an error allowance appropriate to the algorithm and task. Do not enlarge a tolerance simply until a failing program passes. A tolerance changes what the check can detect; it needs its own reasoning and boundary cases, including values close to zero.
CHAPTER 16 OF 26 · Identify failure modes
16. Combine relational checks with other evidence
Known-answer tests, inspection of the implementation, and mathematical proofs answer complementary questions. A direct test confirms a particular result against an independently established answer. A metamorphic test checks a relationship across executions. A proof can establish a general property under its assumptions. None should be silently reported as another type of evidence.
Two AI-generated implementations can share a misunderstanding, especially when both inherit the same incorrect specification. Agreement between them is therefore not sufficient by itself. Ask a learner to derive one relation without the tool, compute one small answer, and explain a deliberately faulty program. These tasks make the basis of the claimed understanding visible.
CHAPTER 17 OF 26 · Identify failure modes
17. Make the testing packet usable by a receiver
The related branch on creating knowledge that others can check and build on asks whether an unfamiliar recipient can reconstruct a result. Apply that idea to a test packet containing the contract, source input, transformation, follow-up input, observed outputs, expected relationship and conclusion. Include the actual version or rule being tested.
Have the receiver repeat one passing and one failing example without live coaching. Record where they need clarification rather than declaring the packet usable because it looks complete. A correct artifact, its author’s independent reasoning and the receiver’s ability to reproduce it are separate outcomes. Improving one does not establish the others automatically.
CHAPTER 18 OF 26 · Identify failure modes
18. A prompt for inspectable metamorphic tests
Try this prompt: “We are testing a deterministic arithmetic-mean service on finite nonempty rational lists, using exact arithmetic. Propose a source case and three related cases. For each, specify the transformation, prove the required output relationship, and state its domain conditions. Include one invalid proposed relation and explain why it is invalid.”
Then ask: “Construct a faulty function that passes at least two of your tests. Find a different test that exposes it. Keep observed outputs separate from required outputs, and do not call finite testing a proof of correctness.” Learners should check every calculation and justify one new test themselves before adopting the generated packet.
CHAPTER 19 OF 26 · Identify failure modes
19. A proposed assessment rubric
Assess five dimensions: specification precision, mathematical justification, input construction, interpretation of failures and reproducibility of evidence. For each dimension, zero means absent evidence; one indicates major errors; two indicates mostly correct work with an identified gap; and three indicates independently reproducible reasoning. Use concrete examples of the gap rather than treating the number as a complete description.
Ask the learner to repair one faulty relation and explain why a passing program may still be wrong. Keep permitted access supports distinct from assistance that supplies the target derivation. This rubric is a proposed classroom tool, not a validated measure of general intelligence or a demonstrated predictor of software reliability.
CHAPTER 20 OF 26 · Test independent transfer
20. Independent transfer: a new list and a suspect output
Use y = [−3, 1, 8, 10]. Its sum is 16, count 4 and mean 4. Adding 3 everywhere gives [0, 4, 11, 13], with mean 7. Negating every entry gives [3, −1, −8, −10], with mean −4. Duplicating the whole list leaves the mean at 4. Derive these answers before reading a generated solution.
Split y into [−3] and [1, 8, 10]. Their means are −3 and 19/3, so weighted recombination gives (−3 + 3 × 19/3)/4 = 4. A candidate service returning 4 for y and 8 for its shifted version violates the shift relation. Here the independent calculation identifies the shifted answer specifically as incorrect; its required value is 7.
CHAPTER 21 OF 26 · Test independent transfer
21. Primary learning: change the collection together
Begin with counters arranged in equal-share groups when the learner is ready for averages. Reorder the groups while preserving their contents, then give every group the same number of extra counters. Ask what changes and what stays the same in the fair share. Use concrete quantities that permit checking by redistribution rather than requiring formal notation immediately.
Show a pretend calculator that always chooses the first group. Find a reordering that exposes its mistake. The learning objective is to explain why the test works, not to memorise the term metamorphic. Keep the activity small enough for the learner to reconstruct the comparison independently, with ordinary accessibility supports as needed.
CHAPTER 22 OF 26 · Test independent transfer
22. Secondary learning: derive and challenge the properties
Connect the activity to algebra by writing sums and counts explicitly. Students can derive the shift and scaling laws, then build a table showing which faulty functions pass each chosen test. Use unequal subgroup sizes to reveal why the average of averages needs weights. Require at least one counterexample to an attractive but invalid rule.
An extension is to formulate tests for another familiar operation, such as a sum or maximum, and identify which mean relations no longer apply. For example, appending zero preserves a sum but can change a mean. Students should justify the new specification before transferring a testing pattern across functions.
CHAPTER 23 OF 26 · Test independent transfer
23. University, institutions and EnDist
At university or professional level, connect test relations to explicit software contracts, numerical analysis and review of scientific workflows. A team can exchange a small test specification and ask another team to implement the checker independently. Record shared assumptions so apparently independent checks do not simply reproduce the same unsupported interpretation.
Use EnDist as a proposed lens on usable progress after checking, clarification and rework. Ask whether the next person can locate the failure and reproduce it with less avoidable confusion. Keep these observations separate rather than inventing a universal EnDist score. This teaching exercise supplies no empirical claim about productivity gains or the reliability of any deployed AI system.
CHAPTER 24 OF 26 · Four-week coursework plan
24. A four-week Metamorphic Testing Lab
In week one, establish the mean contract and collect an unaided explanation of one small case under declared support conditions. In week two, derive the transformation rules and run them against the deliberately faulty functions. Keep a record of a test that initially looked sensible but was revised after its conditions were examined.
In week three, exchange packets and document what recipients can reproduce. In week four, use the fresh transfer list and ask learners to invent another fault-revealing case. Review independent reasoning, assisted packet quality and receiver performance separately. These observations can guide local teaching revisions; without a suitable evaluation design they do not establish that AI caused an improvement.
CHAPTER 25 OF 26 · Four-week coursework plan
25. Questions about checking relationships
Does passing all four simple mean relations prove correctness? No: the median counterexample passes them. Does a failed check prove the program is wrong? It establishes a conflict only after the relation, conditions and checking procedure are verified; the transformation or comparator may be faulty. Direct calculations can help identify which component failed.
Is this useful when small answers are easy to calculate? Yes, as an inspectable way to learn the method and combine different evidence. The point is not to avoid every known-answer test. Future superintelligence, if developed, would not remove the need to specify what an output should mean or explain why a particular check is relevant.
CHAPTER 26 OF 26 · Four-week coursework plan
26. Sources, boundaries and next steps
Read Chen, Cheung and Yiu’s original report, Metamorphic Testing: A New Approach for Generating Next Test Cases, for the testing idea, and the Python documentation on floating-point limitations for the boundary between exact mathematics and machine representation. The report is identified as HKUST-CS98-01; its later arXiv deposit should not be mistaken for the method’s original date.
All lists, faulty functions and transfer calculations in this lab are original teaching examples. They are not observations from a deployed service or evidence of educational effectiveness. Continue by choosing one familiar function, deriving two valid relations, inventing one plausible fault, and asking another learner to reproduce the revealing test. Preserve the assumptions with the result.