Repository navigation
test(gfx): assert hue ramps are continuous instead of printing them (#668) - #3809
Conversation
…668) The "HSV to RGB Conversion - Hue Sweep Test" contained no assertion. It printed 64 sampled rows through FL_WARN and always passed, so it could not have failed for any input. It also stepped the hue by 4, meaning a single bad hue -- the entire failure mode it nominally covered -- fell between samples. That is precisely the defect #668 reported in 2018: one unexpected red pixel partway through the yellow region of a 114-LED fill_rainbow strip. Replace it with a check that walks every adjacent hue pair, including the 255->0 wrap, and bounds the per-channel step. Measured maxima at full saturation/value are rainbow=6, spectrum=4, fullspectrum=6; the bound is 8, leaving room to nudge a constant without hiding a break. The ramps are hand-written piecewise functions -- eight 32-hue sections chosen by bit tests, joined by magic constants (K85/K170/K171) and compile-time switches (Y1/Y2/G2/Gscale). Nothing structurally forces a section to end on the value the next one begins from, so a wrong constant surfaces as exactly one off-colour pixel. Verified the new test fails on the bug it targets: changing K171 to 151 in the O->Y section reports "rainbow: discontinuity of 21 between hue 31 and 32" and fails both cases. The current ramps are continuous, so #668 no longer reproduces -- this pins that. Co-Authored-By: Claude <[email protected]>
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe HSV-to-RGB accuracy tests now replace sampled hue diagnostics with exhaustive adjacent-hue continuity checks. They also validate continuity across 114 pixels generated by ChangesHSV/RGB continuity validation
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Correcting a claim in the description above, since leaving it would be worse than the gap it papers over. I wrote that #668 "does not reproduce" and that "the colour math is sound." That is wrong about the cause. #668 did reproduce, and #3808 — merged shortly before this — is its actual fix: What I actually measured was that the ramps are continuous in the native build. That is a different property, and it could never have caught #668: the R1 hazard is AVR-only inline-asm ABI damage, invisible to a host-compiled test. So, to be precise about what this PR does and does not do:
That second gap is the more valuable target and wants a different mechanism — a lint or AST check pairing every The continuity guard still stands on its own merits (verified failing via the injected-constant mutation above); it just should not be read as coverage of #668's root cause. |
Closes #668.
The finding
tests/fl/hsv2rgb_accuracy.cpphad a test case named "HSV to RGB Conversion - Hue Sweep Test". It contained no assertion — 22 lines ofFL_WARNprinting 64 sampled rows, then nothing. It could not have failed for any input, on any platform, ever.It also stepped the hue by 4:
A single bad hue is the entire failure mode here, and sampling steps right over it. So the test was doubly unable to catch what it nominally covered.
Why that matters for #668
#668 (2018) reported one unexpected red pixel partway through the yellow region of a 114-LED strip filled with
fill_rainbow(leds, 114, hue, 1), reproduced across three Nanos and two strips.hsv2rgb_rainbowis a hand-written piecewise function: eight 32-hue sections selected by bit tests on the hue, joined by magic constants (K85/K170/K171) and compile-time switches (Y1/Y2/G2/Gscale). Nothing structurally forces one section to end on the value the next one starts from — a wrong constant surfaces as exactly one off-colour pixel mid-ramp.The change
Walk every adjacent hue pair, including the 255→0 wrap, and bound the per-channel step, for all three converters. Plus a case reproducing #668's exact call.
Measured maxima at full saturation/value:
Bound set at 8 — room to nudge a constant without hiding a real break, which is tens.
Verified the test can fail
The point of this PR is a test that fails on the bug it targets, so I injected one. Changing
K171→151in the O→Y section:It pinpoints the exact section boundary and the magnitude, and both cases fire. Reverted before commit.
Status of #668 itself
It does not reproduce. The current ramps are continuous everywhere — sections join within 6/255 at every boundary. The colour math is sound today; this pins it so it stays that way.
Validation
bash test --cppbash lintTests-only change; no
src/diff.🤖 Generated with Claude Code
Summary by CodeRabbit