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

Few extra tests for phragmen #4451

Merged
merged 1 commit into from
Dec 19, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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());
}