use std::error::Error;
use std::fmt;
#[derive(Debug)]
pub enum StatsError {
BadParams,
ArgMustBePositive(&'static str),
ArgNotNegative(&'static str),
ArgIntervalIncl(&'static str, f64, f64),
ArgIntervalExcl(&'static str, f64, f64),
ArgIntervalExclMin(&'static str, f64, f64),
ArgIntervalExclMax(&'static str, f64, f64),
ArgGt(&'static str, f64),
ArgGtArg(&'static str, &'static str),
ArgGte(&'static str, f64),
ArgGteArg(&'static str, &'static str),
ArgLt(&'static str, f64),
ArgLtArg(&'static str, &'static str),
ArgLte(&'static str, f64),
ArgLteArg(&'static str, &'static str),
ContainersMustBeSameLength,
ComputationFailedToConverge,
ContainerExpectedSum(&'static str, f64),
ContainerExpectedSumVar(&'static str, &'static str),
SpecialCase(&'static str),
}
impl Error for StatsError {
fn description(&self) -> &str {
"Error performing statistical calculation"
}
}
impl fmt::Display for StatsError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
StatsError::BadParams => write!(f, "Bad distribution parameters"),
StatsError::ArgMustBePositive(s) => write!(f, "Argument {} must be positive", s),
StatsError::ArgNotNegative(s) => write!(f, "Argument {} must be non-negative", s),
StatsError::ArgIntervalIncl(s, min, max) => {
write!(f, "Argument {} not within interval [{}, {}]", s, min, max)
}
StatsError::ArgIntervalExcl(s, min, max) => {
write!(f, "Argument {} not within interval ({}, {})", s, min, max)
}
StatsError::ArgIntervalExclMin(s, min, max) => {
write!(f, "Argument {} not within interval ({}, {}]", s, min, max)
}
StatsError::ArgIntervalExclMax(s, min, max) => {
write!(f, "Argument {} not within interval [{}, {})", s, min, max)
}
StatsError::ArgGt(s, val) => write!(f, "Argument {} must be greater than {}", s, val),
StatsError::ArgGtArg(s, val) => {
write!(f, "Argument {} must be greater than {}", s, val)
}
StatsError::ArgGte(s, val) => {
write!(f, "Argument {} must be greater than or equal to {}", s, val)
}
StatsError::ArgGteArg(s, val) => {
write!(f, "Argument {} must be greater than or equal to {}", s, val)
}
StatsError::ArgLt(s, val) => write!(f, "Argument {} must be less than {}", s, val),
StatsError::ArgLtArg(s, val) => write!(f, "Argument {} must be less than {}", s, val),
StatsError::ArgLte(s, val) => {
write!(f, "Argument {} must be less than or equal to {}", s, val)
}
StatsError::ArgLteArg(s, val) => {
write!(f, "Argument {} must be less than or equal to {}", s, val)
}
StatsError::ContainersMustBeSameLength => {
write!(f, "Expected containers of same length")
}
StatsError::ComputationFailedToConverge => write!(f, "Computation failed to converge"),
StatsError::ContainerExpectedSum(s, sum) => {
write!(f, "Elements in container {} expected to sum to {}", s, sum)
}
StatsError::ContainerExpectedSumVar(s, sum) => {
write!(f, "Elements in container {} expected to sum to {}", s, sum)
}
StatsError::SpecialCase(s) => write!(f, "{}", s),
}
}
}