2021-09-02 14:35:10 +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-09-12 19:43:17 +02:00
|
|
|
use assert_cmd::Command;
|
2021-09-02 14:35:10 +02:00
|
|
|
|
|
|
|
use std::fs;
|
|
|
|
|
|
|
|
#[test]
|
2021-09-12 19:43:17 +02:00
|
|
|
fn convert_ers97_blt_bin() {
|
2021-09-02 14:35:10 +02:00
|
|
|
let blt_input = fs::read_to_string("tests/data/ers97_wd.blt").expect("IO Error");
|
|
|
|
|
2021-09-12 19:43:17 +02:00
|
|
|
Command::cargo_bin("opentally").expect("Cargo Error")
|
|
|
|
.args(&["convert", "tests/data/ers97_wd.blt", "/tmp/opentally.bin"])
|
|
|
|
.assert().success();
|
2021-09-02 14:35:10 +02:00
|
|
|
|
2021-09-12 19:43:17 +02:00
|
|
|
Command::cargo_bin("opentally").expect("Cargo Error")
|
|
|
|
.args(&["convert", "/tmp/opentally.bin", "/tmp/opentally.blt"])
|
|
|
|
.assert().success();
|
2021-09-02 14:35:10 +02:00
|
|
|
|
2021-09-12 19:43:17 +02:00
|
|
|
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", "");
|
2021-09-02 14:35:10 +02:00
|
|
|
|
2021-09-12 19:43:17 +02:00
|
|
|
Command::cargo_bin("opentally").expect("Cargo Error")
|
|
|
|
.args(&["convert", "tests/data/ers97_wd.blt", "/tmp/opentally.csp"])
|
|
|
|
.assert().success();
|
2021-09-02 14:35:10 +02:00
|
|
|
|
2021-09-12 19:43:17 +02:00
|
|
|
Command::cargo_bin("opentally").expect("Cargo Error")
|
|
|
|
.args(&["convert", "/tmp/opentally.csp", "/tmp/opentally.blt", "--seats", "6"])
|
|
|
|
.assert().success();
|
2021-09-02 14:35:10 +02:00
|
|
|
|
2021-09-12 19:43:17 +02:00
|
|
|
let blt_roundtrip = fs::read_to_string("/tmp/opentally.blt").expect("IO Error");
|
|
|
|
assert_eq!(blt_input, blt_roundtrip);
|
2021-09-02 14:35:10 +02:00
|
|
|
}
|