Add test cases for tie-breaking

This commit is contained in:
RunasSudo 2021-06-13 15:03:10 +10:00
parent 4845ebe52f
commit c9d714bf25
Signed by: RunasSudo
GPG Key ID: 7234E476BF21C61A
4 changed files with 96 additions and 3 deletions

45
Cargo.lock generated
View File

@ -6,6 +6,15 @@ version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
[[package]]
name = "aho-corasick"
version = "0.7.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e37cfd5e7657ada45f742d6e99ca5788580b5c529dc78faf11ece6dc702656f"
dependencies = [
"memchr",
]
[[package]]
name = "assert_cmd"
version = "1.0.5"
@ -222,6 +231,15 @@ dependencies = [
"miniz_oxide",
]
[[package]]
name = "float-cmp"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e1267f4ac4f343772758f7b1bdcbe767c218bbab93bb432acbf5162bbf85a6c4"
dependencies = [
"num-traits",
]
[[package]]
name = "generic-array"
version = "0.14.4"
@ -363,6 +381,12 @@ dependencies = [
"autocfg",
]
[[package]]
name = "normalize-line-endings"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "61807f77802ff30975e01f4f071c8ba10c022052f98b3294119f3e615d13e5be"
[[package]]
name = "num-bigint"
version = "0.4.0"
@ -429,6 +453,7 @@ dependencies = [
"num-rational",
"num-traits",
"paste",
"predicates",
"rug",
"sha2",
"wasm-bindgen",
@ -454,7 +479,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f49cfaf7fdaa3bfacc6fa3e7054e65148878354a5cfddcf661df4c851f8021df"
dependencies = [
"difference",
"float-cmp",
"normalize-line-endings",
"predicates-core",
"regex",
]
[[package]]
@ -536,6 +564,17 @@ version = "0.6.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "34cf66eb183df1c5876e2dcf6b13d57340741e8dc255b48e40a26de954d06ae7"
[[package]]
name = "regex"
version = "1.5.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d07a8629359eb56f1e2fb1652bb04212c072a87ba68546a04065d525673ac461"
dependencies = [
"aho-corasick",
"memchr",
"regex-syntax",
]
[[package]]
name = "regex-automata"
version = "0.1.9"
@ -545,6 +584,12 @@ dependencies = [
"byteorder",
]
[[package]]
name = "regex-syntax"
version = "0.6.25"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b"
[[package]]
name = "rug"
version = "1.12.0"

View File

@ -12,6 +12,7 @@ derive_more = "0.99.14"
git-version = "0.3.4"
ibig = "0.3.2"
itertools = "0.10.1"
predicates = "1.0.8"
num-traits = "0.2"
sha2 = "0.9.5"
wasm-bindgen = "0.2.74"

View File

@ -15,9 +15,8 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
use assert_cmd::prelude::*;
use std::process::Command;
use assert_cmd::Command;
use predicates::prelude::*;
#[test]
fn cli_ers97() {
@ -25,3 +24,37 @@ fn cli_ers97() {
.args(&["stv", "tests/data/ers97.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"])
.assert().success();
}
#[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"));
}

14
tests/data/meekm.blt Normal file
View File

@ -0,0 +1,14 @@
4 2
-2
3 1 3 4 0
4 1 3 2 0
2 4 1 3 0
1 2 0
2 2 4 3 1 0
1 3 4 2 0
0
"Adam"
"Basil"
"Charlotte"
"Donald"
"Title"