46 lines
1.6 KiB
Rust
46 lines
1.6 KiB
Rust
#[cfg(test)]
|
|
mod tests {
|
|
use crate::error::{AutoMLError, AutoMLResult};
|
|
|
|
#[test]
|
|
fn test_automl_error_creation() {
|
|
let config_error = AutoMLError::ConfigurationError("Invalid configuration".to_string());
|
|
assert!(matches!(config_error, AutoMLError::ConfigurationError(_)));
|
|
|
|
let opt_error = AutoMLError::OptimizationError("Optimization failed".to_string());
|
|
assert!(matches!(opt_error, AutoMLError::OptimizationError(_)));
|
|
}
|
|
|
|
#[test]
|
|
fn test_automl_error_display() {
|
|
let error = AutoMLError::ResourceError("GPU memory insufficient".to_string());
|
|
let display_str = format!("{}", error);
|
|
assert!(display_str.contains("GPU memory insufficient"));
|
|
}
|
|
|
|
#[test]
|
|
fn test_automl_result_ok() {
|
|
let result: AutoMLResult<i32> = Ok(42);
|
|
assert!(result.is_ok());
|
|
assert_eq!(result.unwrap(), 42);
|
|
}
|
|
|
|
#[test]
|
|
fn test_automl_result_err() {
|
|
let result: AutoMLResult<i32> =
|
|
Err(AutoMLError::TimeoutError("Timeout occurred".to_string()));
|
|
assert!(result.is_err());
|
|
assert!(matches!(result.unwrap_err(), AutoMLError::TimeoutError(_)));
|
|
}
|
|
|
|
#[test]
|
|
fn test_automl_error_serialization() {
|
|
let error = AutoMLError::ConfigurationError("Serialization test".to_string());
|
|
let serialized = serde_json::to_string(&error).expect("Failed to serialize");
|
|
let deserialized: AutoMLError =
|
|
serde_json::from_str(&serialized).expect("Failed to deserialize");
|
|
|
|
assert!(matches!(deserialized, AutoMLError::ConfigurationError(_)));
|
|
}
|
|
}
|