Fix logic error where loss by fraction not updated in multi-stage exclusions
This commit is contained in:
parent
ceba059c53
commit
830362416d
|
@ -825,8 +825,6 @@ where
|
|||
let count_card = state.candidates.get_mut(excluded_candidate).unwrap();
|
||||
checksum -= &result.total_votes;
|
||||
count_card.transfer(&-result.total_votes);
|
||||
|
||||
// By definition, there is no loss by fraction
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -837,14 +835,14 @@ where
|
|||
count_card.transfers = -count_card.votes.clone();
|
||||
count_card.votes = N::new();
|
||||
|
||||
// Update loss by fraction
|
||||
state.loss_fraction.transfer(&-checksum);
|
||||
|
||||
if let ExclusionMethod::SingleStage = opts.exclusion {
|
||||
} else {
|
||||
state.logger.log_literal("Exclusion complete.".to_string());
|
||||
}
|
||||
}
|
||||
|
||||
// Update loss by fraction
|
||||
state.loss_fraction.transfer(&-checksum);
|
||||
}
|
||||
|
||||
fn finished_before_stage<N: Number>(state: &CountState<N>) -> bool {
|
||||
|
|
|
@ -80,12 +80,19 @@ where
|
|||
fn validate_stage<N: Number>(idx: usize, state: &CountState<N>, records: &Vec<StringRecord>) {
|
||||
println!("Col at idx {}", idx);
|
||||
|
||||
// Validate candidate votes
|
||||
//let mut candidate_votes: Vec<N> = records.iter().skip(2).map(|r| N::parse(&r[idx*2 + 1])).collect();
|
||||
let mut candidate_votes: Vec<N> = records.iter().skip(2).map(|r| N::from(r[idx*2 + 1].parse::<f64>().expect("Syntax Error"))).collect();
|
||||
|
||||
// Validate exhausted/LBF
|
||||
let lbf_votes = candidate_votes.pop().unwrap();
|
||||
let exhausted_votes = candidate_votes.pop().unwrap();
|
||||
|
||||
assert!(state.exhausted.votes == exhausted_votes);
|
||||
assert!(state.loss_fraction.votes == lbf_votes);
|
||||
|
||||
// Remove exhausted/LBF rows
|
||||
candidate_votes.truncate(candidate_votes.len() - 2);
|
||||
|
||||
// Validate candidate votes
|
||||
for (candidate, votes) in state.election.candidates.iter().zip(candidate_votes) {
|
||||
let count_card = state.candidates.get(candidate).unwrap();
|
||||
assert!(count_card.votes == votes, "Failed to validate votes for candidate {}. Expected {:}, got {:}", candidate.name, votes, count_card.votes);
|
||||
|
|
Loading…
Reference in New Issue