use scirs2_interpolate::auto_select::{
auto_select as auto_select_method, auto_select_validated, InterpolationMethod,
InterpolationProblem,
};
type ProblemInterpolationMethod = InterpolationMethod;
#[test]
fn small_smooth_1d_picks_cubic_spline() {
let prob = InterpolationProblem {
n_points: 100,
dim: 1,
smoothness_estimate: Some(0.9),
available_memory_mb: None,
require_derivatives: false,
time_budget_ms: None,
};
let rec = auto_select_method(&prob);
assert_eq!(
rec.method,
ProblemInterpolationMethod::CubicSpline,
"1-D smooth data: expected CubicSpline, got {:?}",
rec.method
);
assert!(!rec.reason.is_empty(), "Reason must be non-empty");
}
#[test]
fn large_n_picks_rff() {
let prob = InterpolationProblem {
n_points: 100_000,
dim: 3,
smoothness_estimate: Some(0.5),
available_memory_mb: None,
require_derivatives: false,
time_budget_ms: None,
};
let rec = auto_select_method(&prob);
assert_eq!(
rec.method,
ProblemInterpolationMethod::RandomFeaturesRbf,
"n=100k d=3: expected RandomFeaturesRbf, got {:?}",
rec.method
);
}
#[test]
fn gridded_picks_smooth_method() {
let prob = InterpolationProblem {
n_points: 1_000,
dim: 2,
smoothness_estimate: Some(0.8),
available_memory_mb: None,
require_derivatives: false,
time_budget_ms: None,
};
let rec = auto_select_method(&prob);
let is_smooth = matches!(
rec.method,
ProblemInterpolationMethod::Rbf(_)
| ProblemInterpolationMethod::CubicSpline
| ProblemInterpolationMethod::ThinPlateSpline
);
assert!(
is_smooth,
"Gridded smooth data (n=1000, d=2): expected a smooth method, got {:?}",
rec.method
);
}
#[test]
fn noisy_2d_small_picks_thinplate() {
let prob = InterpolationProblem {
n_points: 200,
dim: 2,
smoothness_estimate: Some(0.3), available_memory_mb: None,
require_derivatives: false,
time_budget_ms: None,
};
let rec = auto_select_method(&prob);
assert_eq!(
rec.method,
ProblemInterpolationMethod::ThinPlateSpline,
"Noisy 2-D small-n: expected ThinPlateSpline, got {:?}",
rec.method
);
}
#[test]
fn high_dim_small_n_picks_kriging() {
let prob = InterpolationProblem {
n_points: 500,
dim: 8,
smoothness_estimate: Some(0.7),
available_memory_mb: None,
require_derivatives: false,
time_budget_ms: None,
};
let rec = auto_select_method(&prob);
assert_eq!(
rec.method,
ProblemInterpolationMethod::Kriging,
"High-dim small-n: expected Kriging, got {:?}",
rec.method
);
}
#[test]
fn memory_constrained_picks_rff() {
let prob = InterpolationProblem {
n_points: 5_000,
dim: 2,
smoothness_estimate: None,
available_memory_mb: Some(5), require_derivatives: false,
time_budget_ms: None,
};
let rec = auto_select_method(&prob);
assert_eq!(
rec.method,
ProblemInterpolationMethod::RandomFeaturesRbf,
"Memory-constrained: expected RandomFeaturesRbf, got {:?}",
rec.method
);
}
#[test]
fn validated_rejects_zero_points() {
let prob = InterpolationProblem {
n_points: 0,
dim: 1,
..Default::default()
};
let result = auto_select_validated(&prob);
assert!(result.is_err(), "0 points should yield an error");
}
#[test]
fn validated_rejects_zero_dim() {
let prob = InterpolationProblem {
n_points: 10,
dim: 0,
..Default::default()
};
let result = auto_select_validated(&prob);
assert!(result.is_err(), "dim=0 should yield an error");
}
#[test]
fn recommendation_has_positive_memory_estimate() {
let cases = [
InterpolationProblem {
n_points: 50,
dim: 1,
..Default::default()
},
InterpolationProblem {
n_points: 500,
dim: 2,
..Default::default()
},
InterpolationProblem {
n_points: 5_000,
dim: 3,
..Default::default()
},
InterpolationProblem {
n_points: 100_000,
dim: 4,
..Default::default()
},
];
for (i, prob) in cases.iter().enumerate() {
let rec = auto_select_method(prob);
assert!(
rec.estimated_memory_mb >= 0.0,
"Case {i}: memory estimate must be non-negative, got {}",
rec.estimated_memory_mb
);
assert!(!rec.reason.is_empty(), "Case {i}: reason must be non-empty");
}
}