OpenTally/tests/tests_impl/cli.rs

68 lines
2.9 KiB
Rust
Raw Normal View History

2021-06-12 07:37:41 +02:00
/* 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/>.
*/
2021-06-13 07:03:10 +02:00
use assert_cmd::Command;
use predicates::prelude::*;
2021-06-12 07:37:41 +02:00
#[test]
fn cli_ers97old() {
2021-06-12 07:37:41 +02:00
Command::cargo_bin("opentally").expect("Cargo Error")
.args(&["stv", "tests/data/ers97old.blt", "--numbers", "fixed", "--decimals", "5", "--round-tvs", "2", "--round-weights", "2", "--round-votes", "2", "--round-quota", "2", "--quota", "droop_exact", "--quota-mode", "ers97", "--surplus", "eg", "--transferable-only", "--exclusion", "by_value"])
2021-06-12 07:37:41 +02:00
.assert().success();
}
2021-06-13 07:03:10 +02:00
2021-09-12 19:43:17 +02:00
#[test]
fn cli_ers97_transfers_detail() {
Command::cargo_bin("opentally").expect("Cargo Error")
.args(&["stv", "tests/data/ers97.blt", "--numbers", "fixed", "--decimals", "5", "--round-surplus-fractions", "2", "--round-values", "2", "--round-votes", "2", "--round-quota", "2", "--quota", "droop_exact", "--quota-criterion", "geq", "--quota-mode", "ers97", "--surplus", "eg", "--transferable-only", "--exclusion", "by_value", "--bulk-exclude", "--defer-surpluses", "--transfers-detail"])
.assert().success();
}
2021-06-13 07:03:10 +02:00
#[test]
fn cli_meekm_wigm_ties_prompt() {
Command::cargo_bin("opentally").expect("Cargo Error")
.args(&["stv", "tests/data/meekm.blt", "--ties", "prompt"])
.write_stdin("1")
.assert().stdout(predicate::str::contains("Charlotte is excluded"));
Command::cargo_bin("opentally").expect("Cargo Error")
.args(&["stv", "tests/data/meekm.blt", "--ties", "prompt"])
.write_stdin("2")
.assert().stdout(predicate::str::contains("Donald is excluded"));
}
#[test]
fn cli_meekm_wigm_ties_forwards() {
Command::cargo_bin("opentally").expect("Cargo Error")
.args(&["stv", "tests/data/meekm.blt", "--ties", "forwards", "prompt"])
.assert().stdout(predicate::str::contains("Charlotte is excluded"));
}
#[test]
fn cli_meekm_wigm_ties_backwards() {
Command::cargo_bin("opentally").expect("Cargo Error")
.args(&["stv", "tests/data/meekm.blt", "--ties", "backwards", "prompt"])
.assert().stdout(predicate::str::contains("Charlotte is excluded"));
}
#[test]
fn cli_meekm_wigm_ties_random() {
Command::cargo_bin("opentally").expect("Cargo Error")
.args(&["stv", "tests/data/meekm.blt", "--ties", "random", "--random-seed", "foo"])
.assert().stdout(predicate::str::contains("Donald is excluded"));
}