Changed map to filter map so that Phragmen ignores empty voters (#7378)

* Changed map to filter map so that Phragmen ignores empty voters

* Resolve flaws and added test case

* Updated test
This commit is contained in:
Krishna Singh
2020-12-03 18:14:53 +05:30
committed by GitHub
parent 3ce406c140
commit f717a20446
2 changed files with 52 additions and 6 deletions
@@ -72,6 +72,46 @@ fn float_phragmen_poc_works() {
);
}
#[test]
fn phragmen_core_test_without_edges() {
let candidates = vec![1, 2, 3];
let voters = vec![
(10, 10, vec![]),
(20, 20, vec![]),
(30, 30, vec![]),
];
let (candidates, voters) = setup_inputs(candidates, voters);
assert_eq!(
voters
.iter()
.map(|v| (
v.who,
v.budget,
(v.edges.iter().map(|e| (e.who, e.weight)).collect::<Vec<_>>()),
))
.collect::<Vec<_>>(),
vec![]
);
assert_eq!(
candidates
.iter()
.map(|c_ptr| (
c_ptr.borrow().who,
c_ptr.borrow().elected,
c_ptr.borrow().round,
c_ptr.borrow().backed_stake,
)).collect::<Vec<_>>(),
vec![
(1, false, 0, 0),
(2, false, 0, 0),
(3, false, 0, 0),
]
);
}
#[test]
fn phragmen_core_poc_works() {
let candidates = vec![1, 2, 3];