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() ) + } > > > testDeltaE.2000 <- function() + { + printf( "\n--------------------- testDeltaE.2000() -----------------------" ) + + + # path = file.path( extdata, "ciede2000testdata.txt" ) #; print(path) + + path = system.file( 'extdata/ciede2000testdata.txt', package='spacesXYZ' ) + if( ! file.exists( path ) ) + { + print( getwd() ) + cat( "File ", path, " does not exist!\n", file=stderr() ) + return(FALSE) + } + + + df = read.table( path, sep='\t', quote='', head=T ) #; print(df) + + Lab1 = as.matrix( df[ , 1:3 ] ) + Lab2 = as.matrix( df[ , 4:6 ] ) + dE.true = df[ ,7] + + # print( cbind( Lab1, Lab2, DeltaE( Lab1, Lab2, metric=c(1976,2000) ) ) ) + + dE.mine = DeltaE( Lab1, Lab2, metric=2000 ) + + print( abs(dE.true - dE.mine) ) + err = max(abs(dE.true - dE.mine)) + printf( "Max error = %g", err ) + + # check for noLD (no long-double) + bytes.LD = .Machine$sizeof.longdouble + if( 0 < bytes.LD ) + # the usual case + tol = 1.e-4 + else + tol = 5.e-4 + + df = cbind( df, dE.mine=dE.mine ) + + #print( cbind( dE.true, dE.mine ) ) + #dig = decimalplaces( dE.true ) # ; print(dig) + # dE.true[1] = dE.true[1] + 10^(-dig) check for failure + # mask = round(dE.mine,dig) != dE.true #; print( mask ) + + mask = tol < abs(dE.true - dE.mine) + + if( any(mask) ) + { + printf( "DeltaE.2000 failed for %d samples. tol=%g", sum(mask), tol ) + print( df[ mask, ,drop=F ] ) + return(FALSE) + } + + return( TRUE ) + } > > decimalplaces <- function( x ) + { + for( i in 0:16 ) + if( identical( x, round(x,i) ) ) return(i) + + return(17) + } > > if( ! testDeltaE.2000() ) stop( "testDeltaE.2000() failed !", call.=FALSE ) --------------------- testDeltaE.2000() ----------------------- [1] 4.031984e-05 1.017475e-05 9.401309e-06 1.135248e-06 4.701074e-06 1.296762e-05 4.118083e-05 4.118083e-05 2.798865e-05 3.736000e-05 [11] 2.784771e-05 2.578753e-05 2.168577e-05 2.450821e-05 2.888619e-05 1.790417e-05 3.130075e-05 7.530193e-06 4.646864e-06 2.143339e-05 [21] 2.634337e-05 2.712703e-05 4.949898e-05 3.476172e-05 2.001360e-05 4.070174e-05 2.949988e-05 4.765841e-06 4.173029e-05 2.207751e-05 [31] 2.907809e-05 1.700544e-05 2.767188e-05 3.283960e-05 Max error = 4.9499e-05 > > > printf( "\nPassed all DeltaE tests !" ) Passed all DeltaE tests ! > > > proc.time() user system elapsed 0.18 0.03 0.20