Fix error in scotland_linn07_gfixed5 test resulting in failure to actually use GuardedFixed

This commit is contained in:
RunasSudo 2021-06-20 01:44:54 +10:00
parent cd42899ba8
commit 90beffa9ff
No known key found for this signature in database
GPG Key ID: 7234E476BF21C61A

View File

@ -21,11 +21,11 @@ use opentally::election::{CandidateState, CountState, Election};
use opentally::numbers::{Fixed, GuardedFixed, Number};
use opentally::stv;
use num_traits::Zero;
use xmltree::Element;
use std::io::{self, BufRead};
use std::fs::File;
use std::ops;
#[test]
fn scotland_linn07_fixed5() {
@ -83,7 +83,14 @@ fn scotland_linn07_gfixed5() {
scotland_linn07::<GuardedFixed>(stv_opts);
}
fn scotland_linn07<N: Number>(stv_opts: stv::STVOptions) {
fn scotland_linn07<N: Number>(stv_opts: stv::STVOptions)
where
for<'r> &'r N: ops::Add<&'r N, Output=N>,
for<'r> &'r N: ops::Sub<&'r N, Output=N>,
for<'r> &'r N: ops::Mul<&'r N, Output=N>,
for<'r> &'r N: ops::Div<&'r N, Output=N>,
for<'r> &'r N: ops::Neg<Output=N>,
{
// Read XML file
let file = File::open("tests/data/linn07.xml").expect("IO Error");
let root = Element::parse(file).expect("Parse Error");
@ -105,7 +112,7 @@ fn scotland_linn07<N: Number>(stv_opts: stv::STVOptions) {
let file_reader = io::BufReader::new(file);
let lines = file_reader.lines();
let mut election: Election<Fixed> = Election::from_blt(lines.map(|r| r.expect("IO Error").to_string()).into_iter());
let mut election: Election<N> = Election::from_blt(lines.map(|r| r.expect("IO Error").to_string()).into_iter());
// !!! FOR SCOTTISH STV !!!
election.normalise_ballots();
@ -171,8 +178,7 @@ fn get_cand_stage(candidate: &Element, idx: usize) -> &Element {
.nth(idx).unwrap();
}
fn parse_str(s: String) -> Fixed {
if s == "-" { return Fixed::zero(); }
let f: f64 = s.parse().expect("Syntax Error");
return Fixed::from(f);
fn parse_str<N: Number>(s: String) -> N {
if s == "-" { return N::zero(); }
return N::parse(&s);
}