//! Error types for risk analyzer use thiserror::Error; /// Result type for risk analyzer operations pub type Result = std::result::Result; /// Error types for risk analysis operations #[derive(Debug, Error)] pub enum RiskAnalyzerError { /// Invalid configuration parameter #[error("Invalid configuration: {0}")] InvalidConfig(String), /// Insufficient data for analysis #[error("Insufficient data: {0}")] InsufficientData(String), /// Calculation error #[error("Calculation error: {0}")] CalculationError(String), /// Invalid portfolio weights #[error("Invalid portfolio weights: {0}")] InvalidWeights(String), /// Matrix operation error #[error("Matrix operation failed: {0}")] MatrixError(String), /// Serialization error #[error("Serialization error: {0}")] SerializationError(#[from] serde_json::Error), } #[cfg(test)] mod tests { use super::*; #[test] fn test_invalid_config_error() { let error = RiskAnalyzerError::InvalidConfig("test error".to_string()); assert!(error.to_string().contains("Invalid configuration")); assert!(error.to_string().contains("test error")); } #[test] fn test_insufficient_data_error() { let error = RiskAnalyzerError::InsufficientData("need more data".to_string()); assert!(error.to_string().contains("Insufficient data")); } #[test] fn test_calculation_error() { let error = RiskAnalyzerError::CalculationError("division by zero".to_string()); assert!(error.to_string().contains("Calculation error")); } #[test] fn test_invalid_weights_error() { let error = RiskAnalyzerError::InvalidWeights("weights don't sum to 1".to_string()); assert!(error.to_string().contains("Invalid portfolio weights")); } #[test] fn test_matrix_error() { let error = RiskAnalyzerError::MatrixError("singular matrix".to_string()); assert!(error.to_string().contains("Matrix operation failed")); } #[test] fn test_error_is_send_sync() { fn assert_send_sync() {} assert_send_sync::(); } }