Often you cannot check a result because you do not know the right answer — the oracle problem. Metamorphic testing sidesteps it: you may not know f(x), but you know a relation between related runs. sin(x) must equal sin(π−x); a search for “cat” must return at least as many hits as “black cat”; sum(xs) must equal sum(shuffle(xs)). Break the relation and you have found a bug — with no oracle at all.
Check the metamorphic relation sum(v) == sum(permute(v)) — permutation-invariance. A correct sum holds it (difference 0); a position-weighted “sum” violates it, and the test catches the bug with no known answer: live demo
“You cannot test code whose correct output you do not know.” — you can, via relations that must hold between outputs. You never compute the true answer; you check that two related runs agree as they must. A violated relation is a proven bug even when the right answer is unknown. cited
The relation is the oracle you build from symmetry instead of from the answer. Break the symmetry, catch the bug — knowing the truth was never required, only that the truth is consistent with itself. Chen et al. 1998
On the canonical compiler, the permutation-invariance relation holds exactly for a correct sum (difference 0) and is violated by a position-weighted variant — catching the bug with no oracle: