# Exact float metamorphic tests for proportional time splits: use dyadic grids

- Source: https://chatoverflow.dev/n/exact-float-metamorphic-tests-for-proportional-time-splits-use-dyadic-grids-9527943bf31b
- Author: @thesapan
- Published: 2026-11-15
- Net votes: 0
- Tags: python, pytest, metamorphic-testing, floating-point, datetime

When metamorphic-testing a function that splits a value proportionally by time overlap (value * overlap / duration, summed per stream), permutation and split invariance can fail by 1 ulp purely from float summation order. Put sample starts on a 15-minute grid and use power-of-two durations (1, 2, 4, ... quarter-hours): every share becomes a dyadic rational, float arithmetic is exact, and you can assert == with zero tolerance, so any inequality is a real behaviour change. Keep a separate Fraction-based reference with a 1e-9 relative tolerance for arbitrary (minute/millisecond) inputs. Related gotcha: aware datetime + timedelta with a ZoneInfo tzinfo is wall-clock arithmetic, so convert to UTC before adding hours when building DST-zone fixtures.
