Skip to content

Add golden-value colorimetry tests - #20

Merged
roytsmart merged 1 commit into
mainfrom
golden-colorimetry-tests
Aug 19, 2026
Merged

Add golden-value colorimetry tests#20
roytsmart merged 1 commit into
mainfrom
golden-colorimetry-tests

Conversation

@roytsmart

Copy link
Copy Markdown
Contributor

Most of the test suite asserts only types and shapes, so it would pass even if the colors produced were completely wrong. This PR adds tests that assert published colorimetric values, completing the work started in #17, which added the peak of the luminous efficiency function, the out-of-range values, and the D65 white point.

New tests

  • test_XYZcie1931_from_spd_equal_energy: a flat, equal-energy spectrum is CIE standard illuminant E, which sits at the center of the chromaticity diagram. The computed chromaticity is x = 0.333315, y = 0.333288 against the exact 1/3. Because the CIE 1931 color matching functions are normalized to have equal integrals, the tristimulus values also come out equal to each other and to the standard value of about 106.857, which the test asserts as well. This is a direct check that the tabulated data added in Use the tabulated CIE 1931 color matching functions #17 is correctly scaled.
  • test_sRGB_white_point: sRGB is defined against the D65 white point, so those tristimulus values must map to pure white. The result is (1.0000055, 0.99999031, 1.00007973).
  • test_sRGB_monochromatic: monochromatic sources at 450, 550, and 610 nm must be dominated by the blue, green, and red channel respectively. These check the color space conversions directly rather than through rgb(), which remaps its input onto the visible range and so would not test the absolute wavelength-to-color relationship.
  • test_xyY_from_XYZ_cie_roundtrip: converting to the xyY color space and back must be the identity. The observed error is 4.4e-16.

These tests were checked against deliberate mutations, since an assertion that cannot fail is worth nothing:

  • scaling the tabulated x-bar by 1% makes the equal-energy test fail,
  • swapping the tabulated x-bar and z-bar makes the monochromatic test fail, with 450 nm becoming red-dominant and 610 nm green-dominant.

One sharp edge found while writing these, not changed here. xyY_from_XYZ_cie() cannot accept tristimulus values that carry a unit, because x and y are dimensionless ratios while Y keeps the unit of the input, and the three cannot be stacked into one array. This means the natural pipeline of passing a dimensionless spectrum through XYZcie1931_from_spd() and then into xyY_from_XYZ_cie() raises a UnitConversionError, since the tristimulus values pick up the unit of the wavelength. Giving the spectrum a per-wavelength unit, as this test does, makes the tristimulus values dimensionless and avoids it. That is arguably the physically correct way to specify a spectral power distribution, so this may be acceptable as is, but the failure mode is not obvious from the error message.

🤖 Generated with Claude Code

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@codecov

codecov Bot commented Aug 19, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (9027720) to head (0633733).

Additional details and impacted files
@@            Coverage Diff            @@
##              main       #20   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            3         3           
  Lines          431       452   +21     
=========================================
+ Hits           431       452   +21     
Flag Coverage Δ
unittests 100.00% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@roytsmart
roytsmart merged commit 548d747 into main Aug 19, 2026
16 checks passed
@roytsmart
roytsmart deleted the golden-colorimetry-tests branch August 19, 2026 22:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant