Property-Based Tests¶
Hypothesis-based invariants for placements, transforms, and schemas.
Warning
Pre-implementation. This page describes proposed contracts. Class signatures, parameter types, config field names, and behavior are subject to change before code lands. Once implementation exists, content here will be regenerated from docstrings or sourced from running tests.
Property-based testing with Hypothesis¶
For pure functions (label derivation, hash functions, taxonomy mapping), property-based tests catch edge cases unit tests miss.
from hypothesis import given, strategies as st
@given(
sample_rate=st.floats(min_value=1e3, max_value=1e9, allow_nan=False),
duration_s=st.floats(min_value=1e-6, max_value=1.0, allow_nan=False),
bw_hz=st.floats(min_value=1e3, max_value=1e9, allow_nan=False),
)
def test_bbox_yolo_always_in_unit_square(sample_rate, duration_s, bw_hz):
"""For any valid (sample_rate, duration, bw), YOLO coordinates are in [0, 1]."""
if bw_hz > sample_rate:
return # not a valid scene; let SceneConfig validator catch it
bbox = _make_bbox(sample_rate, duration_s, bw_hz)
assert 0 <= bbox.yolo.cx <= 1
assert 0 <= bbox.yolo.cy <= 1
assert 0 <= bbox.yolo.w <= 1
assert 0 <= bbox.yolo.h <= 1
@given(payload=st.binary(min_size=1, max_size=512))
def test_lora_encode_decode_roundtrip(payload):
"""Whatever bytes go in, they come out unchanged after encode→decode."""
encoded = lora_encode(payload, sf=7, bw=125000, cr="4-5")
decoded = lora_decode(encoded, sf=7, bw=125000, cr="4-5")
assert decoded == payload
@given(seed1=st.integers(min_value=0, max_value=2**63-1),
seed2=st.integers(min_value=0, max_value=2**63-1))
def test_seed_derivation_no_collision(seed1, seed2):
"""Different (global, shard) inputs produce different shard seeds (with overwhelming probability)."""
if seed1 == seed2:
return
s1 = derive_shard_seed(seed1, "shard-000")
s2 = derive_shard_seed(seed2, "shard-000")
assert s1 != s2
See Also¶
Test Contracts: overview, directory layout, and coverage gates.
Build and CI: workflow definitions.