OpenTally/tests/tests_impl/convert.rs
2021-09-13 03:43:17 +10:00

56 lines
2.0 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/>.
*/
use assert_cmd::Command;
use std::fs;
#[test]
fn convert_ers97_blt_bin() {
let blt_input = fs::read_to_string("tests/data/ers97_wd.blt").expect("IO Error");
Command::cargo_bin("opentally").expect("Cargo Error")
.args(&["convert", "tests/data/ers97_wd.blt", "/tmp/opentally.bin"])
.assert().success();
Command::cargo_bin("opentally").expect("Cargo Error")
.args(&["convert", "/tmp/opentally.bin", "/tmp/opentally.blt"])
.assert().success();
let blt_roundtrip = fs::read_to_string("/tmp/opentally.blt").expect("IO Error");
assert_eq!(blt_input, blt_roundtrip);
}
#[test]
fn convert_ers97_blt_csp() {
// Withdrawn candidates not supported
let blt_input = fs::read_to_string("tests/data/ers97_wd.blt").expect("IO Error")
.replace(r#""ERS Model - 1997 Edition""#, r#""""#)
.replace("-1 -2\n", "");
Command::cargo_bin("opentally").expect("Cargo Error")
.args(&["convert", "tests/data/ers97_wd.blt", "/tmp/opentally.csp"])
.assert().success();
Command::cargo_bin("opentally").expect("Cargo Error")
.args(&["convert", "/tmp/opentally.csp", "/tmp/opentally.blt", "--seats", "6"])
.assert().success();
let blt_roundtrip = fs::read_to_string("/tmp/opentally.blt").expect("IO Error");
assert_eq!(blt_input, blt_roundtrip);
}