use optionstratlib::error::position::PositionValidationErrorKind;
use optionstratlib::error::{
GraphError, GreeksError, InterpolationError, OptionsError, PositionError, SurfaceError,
};
use std::error::Error;
#[test]
fn test_from_interpolation_error() {
let interpolation_error = InterpolationError::Linear("interpolation error test".to_string());
let surface_error = SurfaceError::from(interpolation_error);
match surface_error {
SurfaceError::AnalysisError(reason) => {
assert!(reason.contains("interpolation error test"));
}
_ => panic!("Expected AnalysisError variant, got something else"),
}
}
#[test]
fn test_from_options_error() {
let options_error = OptionsError::validation_error("field", "options error test");
let surface_error = SurfaceError::from(options_error);
match surface_error {
SurfaceError::Options(_) => {
}
_ => panic!("Expected Options variant, got something else"),
}
}
#[test]
fn test_from_greeks_error() {
let greeks_error = GreeksError::invalid_volatility(-1.0, "greeks error test");
let surface_error = SurfaceError::from(greeks_error);
match surface_error {
SurfaceError::Greeks(_) => {
}
_ => panic!("Expected Greeks variant, got something else"),
}
}
#[test]
fn test_from_graph_error() {
let graph_error = GraphError::Render("graph error test".to_string());
let surface_error = SurfaceError::from(graph_error);
match surface_error {
SurfaceError::Graph(_) => {
}
_ => panic!("Expected Graph variant, got something else"),
}
}
#[test]
fn test_surface_error_debug() {
let point_error = SurfaceError::Point3DError {
reason: "point debug test",
};
let debug_str = format!("{point_error:?}");
assert!(debug_str.contains("Point3DError"));
let op_error = SurfaceError::operation_not_supported("debug test", "not supported");
let debug_str = format!("{op_error:?}");
assert!(debug_str.contains("OperationError"));
let render_error = SurfaceError::RenderError {
backend: "plotters",
reason: "std debug test".to_string(),
};
let debug_str = format!("{render_error:?}");
assert!(debug_str.contains("RenderError"));
let construction_error = SurfaceError::ConstructionError("construction debug test".to_string());
let debug_str = format!("{construction_error:?}");
assert!(debug_str.contains("ConstructionError"));
let analysis_error = SurfaceError::AnalysisError("analysis debug test".to_string());
let debug_str = format!("{analysis_error:?}");
assert!(debug_str.contains("AnalysisError"));
}
#[test]
fn test_error_trait_implementation() {
let error = SurfaceError::AnalysisError("error trait test".to_string());
let _: Box<dyn Error> = Box::new(error);
}
#[test]
fn test_surface_error_render_error_variant() {
let error = SurfaceError::RenderError {
backend: "plotters",
reason: "file not found".to_string(),
};
match error {
SurfaceError::RenderError { backend, reason } => {
assert_eq!(backend, "plotters");
assert!(reason.contains("file not found"));
}
_ => panic!("Expected RenderError variant, got something else"),
}
}
#[test]
fn test_from_position_error_with_details() {
let validation_error =
PositionError::ValidationError(PositionValidationErrorKind::InvalidPosition {
reason: "invalid position details".to_string(),
});
let surface_error = SurfaceError::from(validation_error);
match surface_error {
SurfaceError::Position(_) => {
}
_ => panic!("Expected Position variant, got something else"),
}
}