use optionstratlib::error::{CurveError, GraphError, SurfaceError};
use std::error::Error;
use std::io;
#[test]
fn test_graph_error_display() {
let render_error = GraphError::Render("Test render error".to_string());
assert_eq!(format!("{render_error}"), "Render error: Test render error");
let io_error = GraphError::Io(io::Error::new(io::ErrorKind::NotFound, "File not found"));
assert!(format!("{io_error}").contains("IO error"));
assert!(format!("{io_error}").contains("File not found"));
}
#[test]
fn test_graph_error_source() {
let render_error = GraphError::Render("Test render error".to_string());
assert!(render_error.source().is_none());
let io_error = GraphError::Io(io::Error::new(io::ErrorKind::NotFound, "File not found"));
assert!(io_error.source().is_some());
}
#[test]
fn test_graph_error_from_io_error() {
let io_error = io::Error::new(io::ErrorKind::PermissionDenied, "Permission denied");
let graph_error: GraphError = io_error.into();
match graph_error {
GraphError::Io(_) => { }
_ => panic!("Expected GraphError::Io variant"),
}
}
#[test]
fn test_graph_error_from_box_dyn_error() {
let io_error = io::Error::other("Generic error");
let graph_error: GraphError = io_error.into();
match graph_error {
GraphError::Io(_) => { }
_ => panic!("Expected GraphError::Io variant"),
}
}
#[test]
fn test_graph_error_from_curve_error() {
let curve_error = CurveError::RenderError {
backend: "plotters",
reason: "Invalid curve data".to_string(),
};
let graph_error: GraphError = curve_error.into();
match graph_error {
GraphError::Curve(_) => {
}
_ => panic!("Expected GraphError::Curve variant"),
}
}
#[test]
fn test_graph_error_from_surface_error() {
let surface_error = SurfaceError::RenderError {
backend: "plotters",
reason: "Invalid surface data".to_string(),
};
let graph_error: GraphError = surface_error.into();
match graph_error {
GraphError::Surface(_) => {
}
_ => panic!("Expected GraphError::Surface variant"),
}
}