use thiserror::Error;
use crate::math::sampling::SamplingError;
#[derive(Debug, Error)]
pub enum Error {
#[error("Palette extraction process failed with error: {details}")]
PaletteExtractionError {
details: String,
},
#[error("Swatch selection process failed with error: {cause}")]
SwatchSelectionError {
#[from]
cause: SamplingError,
},
#[error("Unsupported algorithm specified: '{name}'")]
UnsupportedAlgorithm {
name: String,
},
#[error("Unsupported theme specified: '{name}'")]
UnsupportedTheme {
name: String,
},
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_palette_extraction_error() {
let actual = Error::PaletteExtractionError {
details: "Details about the failure.".to_string(),
};
assert_eq!(
actual.to_string(),
"Palette extraction process failed with error: Details about the failure."
);
}
#[test]
fn test_swatches_selection_error() {
let cause = SamplingError::DiversityOutOfRange;
let actual = Error::SwatchSelectionError { cause };
assert_eq!(
actual.to_string(),
"Swatch selection process failed with error: invalid diversity factor: value must be in range [0.0, 1.0]"
);
}
#[test]
fn test_unsupported_algorithm() {
let actual = Error::UnsupportedAlgorithm {
name: "xmeans".to_string(),
};
assert_eq!(
actual.to_string(),
"Unsupported algorithm specified: 'xmeans'"
);
}
#[test]
fn test_unsupported_theme() {
let actual = Error::UnsupportedTheme {
name: "pastel".to_string(),
};
assert_eq!(actual.to_string(), "Unsupported theme specified: 'pastel'");
}
}