R Under development (unstable) (2024-01-22 r85820 ucrt) -- "Unsuffered Consequences" Copyright (C) 2024 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > > > library( spacesXYZ ) > > options( width=144 ) > > printf <- function( msg, ... ) + { + mess = sprintf( msg[1], ... ) # should this really be msg[1] ? + cat( mess, '\n' ) #, file=stderr() ) + } > > > testFundamental <- function() + { + printf( "\n--------------------- testFundamental() -----------------------" ) + + C = standardXYZ( 'C' ) + D65 = standardXYZ( 'D65' ) + + # xyY_D65 = xyYfromXYZ( D65 ) + + for( method in c( "Bradford", "VonKries", "MCAT02", "Bianco", "scaling" ) ) + { + CtoD65 = CAT( C, D65, method=method ) + + xyY_gray = xyYfromXYZ( adaptXYZ(CtoD65,C) ) + + delta = max( abs(adaptXYZ(CtoD65,C) - D65) ) + + printf( "method='%s'. delta=%g", method, delta ) + + if( 5.e-16 < delta ) + { + printf( "Adaptation accuracy failed for method='%s'. delta=%g", method, delta ) + return(FALSE) + } + } + + return( TRUE ) + } > > > > testSymmetry <- function() + { + printf( "\n--------------------- testSymmetry() -----------------------" ) + + I3 = diag(3) + + for( method in c( "Bradford", "VonKries", "MCAT02", "Bianco", "scaling" ) ) + { + AtoB = CAT( 'A', 'B', method=method ) + + BtoA = CAT( 'B', 'A', method=method ) + + # the product of the Ms must be I + delta = max( abs(AtoB$M %*% BtoA$M - I3) ) # print(delta) + + printf( "method='%s'. delta=%g", method, delta ) + + if( 5.e-15 < delta ) + { + printf( "Adaptation symmetry failed for method='%s'. delta=%g", method, delta ) + return(FALSE) + } + } + + return( TRUE ) + } > > > testCommutativity <- function() + { + printf( "\n--------------- testCommutativity() -----------------------" ) + + for( method in c( "Bradford", "VonKries", "MCAT02", "Bianco", "scaling" ) ) + { + AtoB = CAT( 'A', 'B', method=method ) + + BtoC = CAT( 'B', 'C', method=method ) + + AtoC = CAT( 'A', 'C', method=method ) + + # compare matrix product + delta = max( abs(BtoC$M %*% AtoB$M - AtoC$M) ) + + printf( "method='%s'. delta=%g", method, delta ) + + if( 5.e-15 < delta ) + { + printf( "Adaptation commutativity failed for method='%s'. delta=%g", method, delta ) + return(FALSE) + } + } + + return( TRUE ) + } > > > > if( ! testFundamental() ) stop( "testFundamental() failed !", call.=FALSE ) --------------------- testFundamental() ----------------------- method='Bradford'. delta=2.22045e-16 method='VonKries'. delta=2.22045e-16 method='MCAT02'. delta=2.22045e-16 method='Bianco'. delta=3.33067e-16 method='scaling'. delta=0 > > if( ! testSymmetry() ) stop( "testSymmetry() failed !", call.=FALSE ) --------------------- testSymmetry() ----------------------- method='Bradford'. delta=2.22045e-16 method='VonKries'. delta=2.22045e-16 method='MCAT02'. delta=2.22045e-16 method='Bianco'. delta=4.52763e-16 method='scaling'. delta=1.11022e-16 > > if( ! testCommutativity() ) stop( "testCommutativity() failed !", call.=FALSE ) --------------- testCommutativity() ----------------------- method='Bradford'. delta=5.55112e-17 method='VonKries'. delta=4.44089e-16 method='MCAT02'. delta=4.44089e-16 method='Bianco'. delta=4.44089e-16 method='scaling'. delta=4.44089e-16 > > printf( "\nPassed all Adaptation tests !" ) Passed all Adaptation tests ! > > > proc.time() user system elapsed 0.18 0.03 0.20