Add CSP parsing tests
This commit is contained in:
parent
be8a6e83fc
commit
0c97755813
@ -142,3 +142,35 @@ pub fn parse_reader<R: Read, N: Number>(reader: R, require_1: bool, require_sequ
|
||||
constraints: None,
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn csp_formal() {
|
||||
let csp_data = "A,B,C\n1,2,3";
|
||||
let election = parse_reader::<_, crate::numbers::Rational>(csp_data.as_bytes(), false, false, false).unwrap();
|
||||
assert_eq!(election.ballots.first().unwrap().preferences, vec![vec![0], vec![1], vec![2]]);
|
||||
|
||||
let csp_data = "A,B,C\n2,3,4";
|
||||
let election = parse_reader::<_, crate::numbers::Rational>(csp_data.as_bytes(), false, false, false).unwrap();
|
||||
assert_eq!(election.ballots.first().unwrap().preferences, vec![vec![0], vec![1], vec![2]]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn csp_no1() {
|
||||
let csp_data = "A,B,C\n2,3,4";
|
||||
let election = parse_reader::<_, crate::numbers::Rational>(csp_data.as_bytes(), true, false, false).unwrap();
|
||||
assert_eq!(election.ballots.first().unwrap().preferences.len(), 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn csp_skipped_preference() {
|
||||
let csp_data = "A,B,C\n1,3,4";
|
||||
let election = parse_reader::<_, crate::numbers::Rational>(csp_data.as_bytes(), false, true, false).unwrap();
|
||||
assert_eq!(election.ballots.first().unwrap().preferences, vec![vec![0]]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn csp_duplicate_preference() {
|
||||
let csp_data = "A,B,C\n1,2,2";
|
||||
let election = parse_reader::<_, crate::numbers::Rational>(csp_data.as_bytes(), false, false, true).unwrap();
|
||||
assert_eq!(election.ballots.first().unwrap().preferences, vec![vec![0]]);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user