Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Few extra tests for phragmen (#4451)
Browse files Browse the repository at this point in the history
  • Loading branch information
kianenigma authored and bkchr committed Dec 19, 2019
1 parent ab4aca3 commit 7ba240f
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions primitives/phragmen/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -354,3 +354,54 @@ fn phragmen_linear_equalize() {

run_and_compare(candidates, voters, stake_of, 2, 2);
}

#[test]
fn elect_has_no_entry_barrier() {
let candidates = vec![10, 20, 30];
let voters = vec![
(1, vec![10]),
(2, vec![20]),
];
let stake_of = create_stake_of(&[
(1, 10),
(2, 10),
]);

let PhragmenResult { winners, assignments: _ } = elect::<_, _, _, TestCurrencyToVote>(
3,
3,
candidates,
voters,
stake_of,
).unwrap();

// 30 is elected with stake 0. The caller is responsible for stripping this.
assert_eq_uvec!(winners, vec![
(10, 10),
(20, 10),
(30, 0),
]);
}

#[test]
fn minimum_to_elect_is_respected() {
let candidates = vec![10, 20, 30];
let voters = vec![
(1, vec![10]),
(2, vec![20]),
];
let stake_of = create_stake_of(&[
(1, 10),
(2, 10),
]);

let maybe_result = elect::<_, _, _, TestCurrencyToVote>(
10,
10,
candidates,
voters,
stake_of,
);

assert!(maybe_result.is_none());
}

0 comments on commit 7ba240f

Please sign in to comment.