use optionstratlib::error::{
CurveError, GraphError, GreeksError, InterpolationError, MetricsError, OperationErrorKind,
OptionsError,
};
#[test]
fn test_curve_error_from_options_error() {
let options_error = OptionsError::validation_error("field", "options error test");
let curve_error: CurveError = options_error.into();
match curve_error {
CurveError::Options(_) => {
}
_ => panic!("Expected Options variant, got something else"),
}
}
#[test]
fn test_curve_error_from_greeks_error() {
let greeks_error = GreeksError::invalid_volatility(-1.0, "greeks error test");
let curve_error: CurveError = greeks_error.into();
match curve_error {
CurveError::Greeks(_) => {
}
_ => panic!("Expected Greeks variant, got something else"),
}
}
#[test]
fn test_curve_error_from_interpolation_error() {
let interpolation_error = InterpolationError::Linear("interpolation error test".to_string());
let curve_error: CurveError = interpolation_error.into();
match curve_error {
CurveError::InterpolationOp(_) => {
}
_ => panic!("Expected InterpolationOp variant, got something else"),
}
}
#[test]
fn test_curve_error_from_metrics_error() {
let metrics_error = MetricsError::BasicError("metrics error test".to_string());
let curve_error: CurveError = metrics_error.into();
match curve_error {
CurveError::MetricsError(msg) => {
assert!(msg.contains("metrics error test"));
}
_ => panic!("Expected MetricsError variant, got something else"),
}
}
#[test]
fn test_curve_error_from_graph_error() {
let graph_error = GraphError::Render("graph error test".to_string());
let curve_error: CurveError = graph_error.into();
match curve_error {
CurveError::Graph(_) => {
}
_ => panic!("Expected Graph variant, got something else"),
}
}
#[test]
fn test_curve_error_construction_error() {
let error = CurveError::ConstructionError("construction error test".to_string());
assert_eq!(
format!("{error}"),
"Construction error: construction error test"
);
assert!(format!("{error:?}").contains("construction error test"));
}
#[test]
fn test_curve_error_operation_not_supported() {
let operation = "calculate";
let reason = "TestStrategy";
let error = CurveError::operation_not_supported(operation, reason);
match error {
CurveError::OperationError(OperationErrorKind::NotSupported {
operation: ref op,
reason: ref r,
}) => {
assert_eq!(op, operation);
assert_eq!(r, reason);
}
_ => panic!("Expected OperationError with NotSupported variant"),
}
assert_eq!(
format!("{error}"),
"Operation error: Operation 'calculate' is not supported for strategy 'TestStrategy'"
);
}
#[test]
fn test_curve_error_invalid_parameters() {
let operation = "interpolate";
let reason = "insufficient data points";
let error = CurveError::invalid_parameters(operation, reason);
match error {
CurveError::OperationError(OperationErrorKind::InvalidParameters {
operation: ref op,
reason: ref r,
}) => {
assert_eq!(op, operation);
assert_eq!(r, reason);
}
_ => panic!("Expected OperationError with InvalidParameters variant"),
}
assert_eq!(
format!("{error}"),
"Operation error: Invalid parameters for operation 'interpolate': insufficient data points"
);
}
#[test]
fn test_curve_error_point2d_error() {
let error = CurveError::Point2DError {
reason: "invalid coordinates",
};
assert_eq!(format!("{error}"), "Error: invalid coordinates");
assert!(format!("{error:?}").contains("invalid coordinates"));
}
#[test]
fn test_curve_error_render_error() {
let error = CurveError::RenderError {
backend: "plotters",
reason: "io error test".to_string(),
};
match error {
CurveError::RenderError { backend, reason } => {
assert_eq!(backend, "plotters");
assert!(reason.contains("io error test"));
}
_ => panic!("Expected RenderError variant, got something else"),
}
}