R Under development (unstable) (2025-09-27 r88882 ucrt) -- "Unsuffered Consequences" Copyright (C) 2025 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. > # Error handling and edge case tests for PSGP package > > library(psgp) Loading required package: intamap Loading required package: sp > > # Test 1: Invalid input validation > cat("Testing input validation...\n") Testing input validation... > > # Test with NULL inputs - should fail gracefully > tryCatch({ + estimateParameters(NULL, NULL, NULL) + stop("Should have failed with NULL inputs") + }, error = function(e) { + cat("PASS: NULL input validation working:", e$message, "\n") + }) PASS: NULL input validation working: there is no parameter estimation method or default method for objects of class NULL > > # Test 2: Empty data > cat("Testing empty data handling...\n") Testing empty data handling... > > tryCatch({ + empty_x <- numeric(0) + empty_y <- numeric(0) + estimateParameters(empty_x, empty_y, NULL) + stop("Should have failed with empty data") + }, error = function(e) { + cat("PASS: Empty data validation working:", e$message, "\n") + }) PASS: Empty data validation working: there is no parameter estimation method or default method for objects of class numeric > > # Test 3: Mismatched dimensions > cat("Testing dimension mismatch handling...\n") Testing dimension mismatch handling... > > tryCatch({ + x_coords <- c(1, 2, 3, 4) # 2 coordinate pairs + y_values <- c(1, 2, 3) # 3 values - mismatch + estimateParameters(x_coords, y_values, NULL) + stop("Should have failed with dimension mismatch") + }, error = function(e) { + cat("PASS: Dimension mismatch validation working:", e$message, "\n") + }) PASS: Dimension mismatch validation working: there is no parameter estimation method or default method for objects of class numeric > > # Test 4: Invalid prediction coordinates > cat("Testing invalid prediction coordinates...\n") Testing invalid prediction coordinates... > > # Set up valid training data > library(sp) > data(meuse) > observations <- data.frame(x = meuse$x[1:10], y = meuse$y[1:10], value = log(meuse$zinc[1:10])) > coordinates(observations) = ~x+y > > # Create invalid prediction locations (odd number of coordinates) > tryCatch({ + invalid_pred <- c(1, 2, 3) # Odd number - should be pairs + spatialPredict(observations, invalid_pred) + stop("Should have failed with invalid prediction coordinates") + }, error = function(e) { + cat("PASS: Invalid prediction coordinates validation working:", e$message, "\n") + }) PASS: Invalid prediction coordinates validation working: there is no prediction method or default method for objects of class SpatialPointsDataFrame > > # Test 5: Numerical stability with ill-conditioned data > cat("Testing numerical stability...\n") Testing numerical stability... > > # Create data points that are very close together (potential numerical issues) > close_x <- c(0, 0.000001, 0, 0.000001) > close_y <- c(0, 0, 0.000001, 0.000001) > close_values <- c(1, 1.1, 1.05, 1.15) > > close_obs <- data.frame(x = close_x, y = close_y, value = close_values) > coordinates(close_obs) = ~x+y > > tryCatch({ + result <- spatialPredict(close_obs, c(0.0005, 0.0005)) + cat("PASS: Numerical stability test completed without errors\n") + }, error = function(e) { + cat("WARNING: Numerical stability issue detected:", e$message, "\n") + }) WARNING: Numerical stability issue detected: there is no prediction method or default method for objects of class SpatialPointsDataFrame > > cat("Error handling tests completed.\n") Error handling tests completed. > > proc.time() user system elapsed 2.39 0.37 2.73