Fix error in scotland_linn07_gfixed5 test resulting in failure to actually use GuardedFixed
This commit is contained in:
parent
cd42899ba8
commit
90beffa9ff
|
@ -21,11 +21,11 @@ use opentally::election::{CandidateState, CountState, Election};
|
||||||
use opentally::numbers::{Fixed, GuardedFixed, Number};
|
use opentally::numbers::{Fixed, GuardedFixed, Number};
|
||||||
use opentally::stv;
|
use opentally::stv;
|
||||||
|
|
||||||
use num_traits::Zero;
|
|
||||||
use xmltree::Element;
|
use xmltree::Element;
|
||||||
|
|
||||||
use std::io::{self, BufRead};
|
use std::io::{self, BufRead};
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
|
use std::ops;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn scotland_linn07_fixed5() {
|
fn scotland_linn07_fixed5() {
|
||||||
|
@ -83,7 +83,14 @@ fn scotland_linn07_gfixed5() {
|
||||||
scotland_linn07::<GuardedFixed>(stv_opts);
|
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
|
// Read XML file
|
||||||
let file = File::open("tests/data/linn07.xml").expect("IO Error");
|
let file = File::open("tests/data/linn07.xml").expect("IO Error");
|
||||||
let root = Element::parse(file).expect("Parse 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 file_reader = io::BufReader::new(file);
|
||||||
let lines = file_reader.lines();
|
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 !!!
|
// !!! FOR SCOTTISH STV !!!
|
||||||
election.normalise_ballots();
|
election.normalise_ballots();
|
||||||
|
@ -171,8 +178,7 @@ fn get_cand_stage(candidate: &Element, idx: usize) -> &Element {
|
||||||
.nth(idx).unwrap();
|
.nth(idx).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_str(s: String) -> Fixed {
|
fn parse_str<N: Number>(s: String) -> N {
|
||||||
if s == "-" { return Fixed::zero(); }
|
if s == "-" { return N::zero(); }
|
||||||
let f: f64 = s.parse().expect("Syntax Error");
|
return N::parse(&s);
|
||||||
return Fixed::from(f);
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue