pub enum ElectionError {
ArithmeticOverflow,
FixedPointDigitsTooMany,
DegeneratedElectionGraph,
NotEnoughCandidates,
}
use std::error::Error;
impl Error for ElectionError {}
use std::fmt;
impl fmt::Debug for ElectionError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self)
}
}
impl fmt::Display for ElectionError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
use self::ElectionError::*;
match self {
FixedPointDigitsTooMany => write!(f, "Too many fixed-point digits"),
DegeneratedElectionGraph => write!(f, "Beat graph is degenerated"),
NotEnoughCandidates => write!(f, "Not enough candidates or votes"),
ArithmeticOverflow => write!(f, "Arithmetic overflow"),
}
}
}
#[derive(Copy, Clone)]
pub enum PairScore {
Winning,
Margin,
Opposition,
}
#[derive(Copy, Clone)]
pub enum Quota {
Hare,
HareInt,
Droop,
HagenbachBischoff,
}
#[derive(Clone, Copy)]
pub enum BordaKind {
Borda0,
Borda1,
Nauru,
}
#[derive(Clone, Copy)]
pub enum SetType {
Smith,
Schwartz,
}
#[doc(inline)]
pub use crate::tally::Transfer;
pub use crate::outcome::Outcome;
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn election_error_msg() {
assert_eq!(
format!("{:?}", ElectionError::ArithmeticOverflow),
"Arithmetic overflow"
);
assert_eq!(
format!("{:?}", ElectionError::FixedPointDigitsTooMany),
"Too many fixed-point digits"
);
assert_eq!(
format!("{:?}", ElectionError::NotEnoughCandidates),
"Not enough candidates or votes"
);
assert_eq!(
format!("{:?}", ElectionError::DegeneratedElectionGraph),
"Beat graph is degenerated"
);
}
}