From 90beffa9ffa0051478eb0be60f1b0725a6a179f0 Mon Sep 17 00:00:00 2001 From: RunasSudo Date: Sun, 20 Jun 2021 01:44:54 +1000 Subject: [PATCH] Fix error in scotland_linn07_gfixed5 test resulting in failure to actually use GuardedFixed --- tests/scotland.rs | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/tests/scotland.rs b/tests/scotland.rs index 5dbce94..9acaef0 100644 --- a/tests/scotland.rs +++ b/tests/scotland.rs @@ -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::(stv_opts); } -fn scotland_linn07(stv_opts: stv::STVOptions) { +fn scotland_linn07(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, +{ // 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(stv_opts: stv::STVOptions) { let file_reader = io::BufReader::new(file); let lines = file_reader.lines(); - let mut election: Election = Election::from_blt(lines.map(|r| r.expect("IO Error").to_string()).into_iter()); + let mut election: Election = 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(s: String) -> N { + if s == "-" { return N::zero(); } + return N::parse(&s); }