Differential and Metamorphic Testing
Compare independent implementations where a small reference is trusted and use transformations whose output relationships are known.
- Source
- Anbloq
- Language
- English
- Created
- Updated
- Chapters
- 2
- Reading time
- 1 min
In this article2 chapters
A clear small reference can check an optimized implementation
For a range-sum structure, store test data in a plain array and sum each interval directly. Generate a deterministic sequence of additions and queries. After each query compare the optimized value to that reference. Include endpoint conventions and large enough values for the intended arithmetic model. When results differ, preserve a reproducible prefix of operations that reaches the failing state.
A metamorphic relation checks a result without its exact value
For range sums, splitting a range into two adjacent parts should give subrange results adding to the original result. This relation can find errors even without a separate answer for every case, although a consistently wrong implementation may still satisfy it. Independently chosen oracles reduce shared mistakes. Property-based testing helps generate and shrink input sequences. Translation validation addresses a stronger, symbolic comparison between two program fragments.[1][2]