/* OpenTally: Open-source election vote counting * Copyright © 2021 Lee Yingtong Li (RunasSudo) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ mod utils; use opentally::election::{CountState, Election}; use opentally::numbers::Rational; use opentally::parser::blt; use opentally::stv; use opentally::ties::TieStrategy; #[test] fn insufficient_candidates1() { let stv_opts = stv::STVOptionsBuilder::default() .ties(vec![TieStrategy::Random(String::new())]) .build().unwrap(); let mut election: Election = blt::parse_path("tests/data/insufficient_candidates1.blt").expect("Syntax Error"); stv::preprocess_election(&mut election, &stv_opts); let mut state = CountState::new(&election); stv::count_init(&mut state, &stv_opts).unwrap(); loop { let result = stv::count_one_stage::(&mut state, &stv_opts); match result { Ok(done) => { assert_eq!(done, false); } Err(err) => { assert_eq!(err, stv::STVError::CannotCompleteCount("Insufficient continuing candidates to complete count")); break; } } } } #[test] fn insufficient_candidates2() { let stv_opts = stv::STVOptionsBuilder::default() .ties(vec![TieStrategy::Random(String::new())]) .build().unwrap(); let mut election: Election = blt::parse_path("tests/data/insufficient_candidates2.blt").expect("Syntax Error"); stv::preprocess_election(&mut election, &stv_opts); let mut state = CountState::new(&election); stv::count_init(&mut state, &stv_opts).unwrap(); loop { let result = stv::count_one_stage::(&mut state, &stv_opts); match result { Ok(done) => { assert_eq!(done, false); } Err(err) => { assert_eq!(err, stv::STVError::CannotCompleteCount("Insufficient continuing candidates to complete count")); break; } } } }