Fix bug when excluding candidate with 0 votes

This commit is contained in:
RunasSudo 2021-05-30 18:27:28 +10:00
parent a595f2ff6b
commit 5189a74010
Signed by: RunasSudo
GPG Key ID: 7234E476BF21C61A
1 changed files with 46 additions and 42 deletions

View File

@ -445,6 +445,9 @@ where
panic!("Invalid --exclusion");
}
let mut checksum = N::new();
if votes.len() > 0 {
let value = &votes[0].value / &votes[0].ballot.orig_value;
// Count next preferences
@ -457,8 +460,6 @@ where
}
// Transfer candidate votes
let mut checksum = N::new();
for (candidate, entry) in result.candidates.into_iter() {
let parcel = entry.votes as Parcel<N>;
let count_card = state.candidates.get_mut(candidate).unwrap();
@ -491,7 +492,10 @@ where
count_card.transfer(&-result.total_votes);
// By definition, there is no loss by fraction
} else {
}
}
if votes_remaining == 0 {
// Finalise candidate votes
let count_card = state.candidates.get_mut(excluded_candidate).unwrap();
checksum -= &count_card.votes;