Skip to content

Commit eb60819

Browse files
committed
Add another test to spectral data
Signed-off-by: Aleksandr Motsjonov <[email protected]>
1 parent e49d549 commit eb60819

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

tests/test_SpectralData.cpp

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,13 +459,73 @@ void testSpectralData_ReshapeInterpolation()
459459
spectrum2.values[2], expected_390, 1e-10 ); /// Index 2 = 390 nm
460460
}
461461

462+
void testSpectralData_ReshapeBeforeSourceRange()
463+
{
464+
/// Test the case where source spectrum starts after ReferenceShape first wavelength
465+
/// Source: 400-450 nm with step 10 (so samples at 400, 410, 420, 430, 440, 450)
466+
/// Target: ReferenceShape 380-780 nm with step 5
467+
/// For wavelengths 380, 385, 390, 395 nm, we haven't reached source range yet,
468+
/// so we copy the first source value (values[0])
469+
rta::core::Spectrum::Shape source_shape = { 400, 450, 10 };
470+
rta::core::Spectrum spectrum( 0.0, source_shape );
471+
472+
/// Set known values
473+
spectrum.values[0] = 100.0; /// Value at 400 nm
474+
spectrum.values[1] = 200.0; /// Value at 410 nm
475+
spectrum.values[2] = 300.0; /// Value at 420 nm
476+
spectrum.values[3] = 400.0; /// Value at 430 nm
477+
spectrum.values[4] = 500.0; /// Value at 440 nm
478+
spectrum.values[5] = 600.0; /// Value at 450 nm
479+
480+
/// Verify initial shape
481+
OIIO_CHECK_EQUAL( spectrum.shape.first, 400 );
482+
OIIO_CHECK_EQUAL( spectrum.shape.last, 450 );
483+
OIIO_CHECK_EQUAL( spectrum.shape.step, 10 );
484+
OIIO_CHECK_EQUAL( spectrum.values.size(), 6 );
485+
486+
/// Reshape to ReferenceShape (380-780, step 5)
487+
spectrum.reshape();
488+
489+
/// Verify shape changed to ReferenceShape
490+
OIIO_CHECK_EQUAL( spectrum.shape.first, 380 );
491+
OIIO_CHECK_EQUAL( spectrum.shape.last, 780 );
492+
OIIO_CHECK_EQUAL( spectrum.shape.step, 5 );
493+
OIIO_CHECK_EQUAL(
494+
spectrum.values.size(),
495+
( 780 - 380 + 5 ) / 5 ); /// Should be 81 samples
496+
497+
/// Test that wavelengths before source range (380, 385, 390, 395) get first source value
498+
/// These should all copy values[0] = 100.0 because wl_src (400) > wl_dst
499+
OIIO_CHECK_EQUAL_THRESH(
500+
spectrum.values[0], 100.0, 1e-10 ); /// 380 nm - before source range
501+
OIIO_CHECK_EQUAL_THRESH(
502+
spectrum.values[1], 100.0, 1e-10 ); /// 385 nm - before source range
503+
OIIO_CHECK_EQUAL_THRESH(
504+
spectrum.values[2], 100.0, 1e-10 ); /// 390 nm - before source range
505+
OIIO_CHECK_EQUAL_THRESH(
506+
spectrum.values[3], 100.0, 1e-10 ); /// 395 nm - before source range
507+
508+
/// Test exact match at 400 nm (first source wavelength)
509+
OIIO_CHECK_EQUAL_THRESH(
510+
spectrum.values[4], 100.0, 1e-10 ); /// 400 nm - exact match
511+
512+
/// Test exact match at 410 nm
513+
OIIO_CHECK_EQUAL_THRESH(
514+
spectrum.values[6], 200.0, 1e-10 ); /// 410 nm - exact match
515+
516+
/// Test exact match at 420 nm
517+
OIIO_CHECK_EQUAL_THRESH(
518+
spectrum.values[8], 300.0, 1e-10 ); /// 420 nm - exact match
519+
}
520+
462521
int main( int, char ** )
463522
{
464523
testSpectralData_Spectrum();
465524
testSpectralData_Properties();
466525
testSpectralData_LoadSpst();
467526
testSpectralData_Operators();
468527
testSpectralData_ReshapeInterpolation();
528+
testSpectralData_ReshapeBeforeSourceRange();
469529

470530
return unit_test_failures;
471531
}

0 commit comments

Comments
 (0)