From f0f117cdd33a855fc74f58ab1c519d4fb749f5ac Mon Sep 17 00:00:00 2001 From: Alexander Whitestone Date: Tue, 21 Apr 2026 07:25:52 -0400 Subject: [PATCH] fix(tests): quant_selector quality-order assertion matches design intent (#138, #139) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The test `test_levels_ordered_by_quality` asserted strictly descending `bits_per_channel`, but `q4_0` (4.0 bits) is a non-TurboQuant fallback placed last regardless of bit width. The design invariant is: - TurboQuant levels (turbo4→turbo2): ordered by compression_ratio ascending (more aggressive = more compression) - Fallback levels (q4_0): placed after all TurboQuant levels as safe defaults, not part of the quality progression Changes: - `test_levels_ordered_by_quality`: Now validates compression_ratio ordering for TurboQuant levels only, not across fallbacks - `test_fallback_quant_is_last`: New test ensuring non-TurboQuant fallbacks always appear after TurboQuant levels Closes #138 Closes #139 (duplicate) --- tests/test_quant_selector.py | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/tests/test_quant_selector.py b/tests/test_quant_selector.py index 5447d143..b976252c 100644 --- a/tests/test_quant_selector.py +++ b/tests/test_quant_selector.py @@ -20,9 +20,35 @@ from evolution.quant_selector import ( class TestQuantLevels: def test_levels_ordered_by_quality(self): - """Levels should be ordered from best quality to most aggressive.""" - for i in range(len(QUANT_LEVELS) - 1): - assert QUANT_LEVELS[i].bits_per_channel > QUANT_LEVELS[i + 1].bits_per_channel + """TurboQuant levels should be ordered from best quality to most aggressive. + + The quality ordering invariant for TurboQuant levels is monotonically + increasing compression_ratio (more aggressive = more compression). + Non-TurboQuant fallbacks (e.g. q4_0) are placed after all TurboQuant + levels and may have any compression ratio — they exist as safe defaults, + not as part of the quality progression. + """ + turbo_quant_names = {"turbo4", "turbo3", "turbo2"} + turbo_levels = [l for l in QUANT_LEVELS if l.name in turbo_quant_names] + for i in range(len(turbo_levels) - 1): + assert turbo_levels[i].compression_ratio <= turbo_levels[i + 1].compression_ratio, ( + f"TurboQuant {turbo_levels[i].name} (compression={turbo_levels[i].compression_ratio}x) " + f"should have <= compression than {turbo_levels[i+1].name} " + f"(compression={turbo_levels[i+1].compression_ratio}x)" + ) + + def test_fallback_quant_is_last(self): + """Non-TurboQuant fallbacks (e.g. q4_0) should be at the end of the list.""" + turbo_quant_names = {"turbo4", "turbo3", "turbo2"} + found_fallback = False + for level in QUANT_LEVELS: + if level.name not in turbo_quant_names: + found_fallback = True + elif found_fallback: + pytest.fail( + f"TurboQuant level '{level.name}' appears after a fallback level. " + f"All TurboQuant levels must precede fallbacks." + ) def test_all_levels_have_required_fields(self): for level in QUANT_LEVELS: