1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
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"
);
}
}