use thiserror::Error;
#[derive(Debug, Error)]
pub enum ObjectiveError {
#[error("No candidates available")]
NoCandidates,
#[error("No candidate met criteria: {0}")]
NoMatch(String),
#[error("Invalid configuration: {0}")]
InvalidConfig(String),
#[error("Objective not found: {0}")]
NotFound(String),
#[error("Scoring error: {0}")]
Scoring(String),
#[error("Fold error: {0}")]
Fold(#[from] crate::FoldError),
}
pub type ObjectiveResult<T> = Result<T, ObjectiveError>;
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_no_candidates_display() {
let err = ObjectiveError::NoCandidates;
assert_eq!(err.to_string(), "No candidates available");
}
#[test]
fn test_no_match_display() {
let err = ObjectiveError::NoMatch("score < 0.5".into());
assert!(err.to_string().contains("score < 0.5"));
}
#[test]
fn test_invalid_config_display() {
let err = ObjectiveError::InvalidConfig("missing weight".into());
assert!(err.to_string().contains("missing weight"));
}
#[test]
fn test_not_found_display() {
let err = ObjectiveError::NotFound("relevance_v1".into());
assert!(err.to_string().contains("relevance_v1"));
}
#[test]
fn test_scoring_display() {
let err = ObjectiveError::Scoring("NaN result".into());
assert!(err.to_string().contains("NaN result"));
}
}