OpenTally/tests/tests_impl/vs_prsa_count.rs

91 lines
3.4 KiB
Rust

/* 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 <https://www.gnu.org/licenses/>.
*/
// Compare results under PRSA 1977 (no deferred surpluses) with results produced by count.nl at https://gitlab.com/RunasSudo/prsa_count
// CSV files automatically generated from count.nl output
// Elections comprise all elections from https://gitlab.com/RunasSudo/stvdb which can be counted by count.nl
use crate::utils;
use opentally::numbers::Rational;
use opentally::stv;
use opentally::ties::TieStrategy;
macro_rules! mk_test {
($name:ident, $file:expr) => {
#[test]
fn $name() {
let stv_opts = stv::STVOptionsBuilder::default()
.round_surplus_fractions(Some(3))
.round_values(Some(3))
.round_votes(Some(3))
.round_quota(Some(3))
.quota_criterion(stv::QuotaCriterion::GreaterOrEqual)
.ties(vec![TieStrategy::Backwards, TieStrategy::Random(String::from("0"))])
.surplus(stv::SurplusMethod::EG)
.surplus_order(stv::SurplusOrder::ByOrder)
.transferable_only(true)
.exclusion(stv::ExclusionMethod::ParcelsByOrder)
.early_bulk_elect(false)
.build().unwrap();
utils::read_validate_election::<Rational>(&format!("tests/data/vs_prsa_count/{}.csv", $file), &format!("tests/data/vs_prsa_count/{}.blt", $file), stv_opts, None, &["exhausted"]);
}
}
}
mk_test!(vs_prsa_count_2001, "2001");
mk_test!(vs_prsa_count_2014_prsavt, "2014_prsav-t_council_ballots");
mk_test!(vs_prsa_count_a2, "A2");
mk_test!(vs_prsa_count_a8, "A8");
mk_test!(vs_prsa_count_a16, "A16");
mk_test!(vs_prsa_count_a24, "A24");
mk_test!(vs_prsa_count_a25, "A25");
mk_test!(vs_prsa_count_a27, "A27");
mk_test!(vs_prsa_count_a28, "A28");
mk_test!(vs_prsa_count_a29, "A29");
mk_test!(vs_prsa_count_a30, "A30");
mk_test!(vs_prsa_count_a31, "A31");
mk_test!(vs_prsa_count_a32, "A32");
mk_test!(vs_prsa_count_a51, "A51");
mk_test!(vs_prsa_count_a57, "A57");
mk_test!(vs_prsa_count_a58, "A58");
mk_test!(vs_prsa_count_a60, "A60");
mk_test!(vs_prsa_count_a61, "A61");
mk_test!(vs_prsa_count_a62, "A62");
mk_test!(vs_prsa_count_a63, "A63");
mk_test!(vs_prsa_count_a64, "A64");
mk_test!(vs_prsa_count_a65, "A65");
mk_test!(vs_prsa_count_a66, "A66");
mk_test!(vs_prsa_count_a69, "A69");
mk_test!(vs_prsa_count_a72, "A72");
mk_test!(vs_prsa_count_a74, "A74");
mk_test!(vs_prsa_count_a75, "A75");
mk_test!(vs_prsa_count_a76, "A76");
mk_test!(vs_prsa_count_a77, "A77");
mk_test!(vs_prsa_count_a78, "A78");
mk_test!(vs_prsa_count_a79, "A79");
mk_test!(vs_prsa_count_a80, "A80");
mk_test!(vs_prsa_count_a82, "A82");
mk_test!(vs_prsa_count_a84, "A84");
mk_test!(vs_prsa_count_a86, "A86");
mk_test!(vs_prsa_count_a87, "A87");
mk_test!(vs_prsa_count_a89, "A89");
mk_test!(vs_prsa_count_a97, "A97");
mk_test!(vs_prsa_count_a98, "A98");
mk_test!(vs_prsa_count_a99, "A99");