mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-14 04:01:10 +00:00
clean the interface of supports map (#9674)
* clean the interface of supports map, make it a bit cleaner and more efficients * Fix stiff * fix one test * Fix warnings
This commit is contained in:
@@ -24,7 +24,7 @@ use honggfuzz::fuzz;
|
||||
use rand::{self, SeedableRng};
|
||||
use sp_npos_elections::{
|
||||
assignment_ratio_to_staked_normalized, is_score_better, seq_phragmen, to_supports,
|
||||
to_without_backing, EvaluateSupport, VoteWeight,
|
||||
EvaluateSupport, VoteWeight,
|
||||
};
|
||||
use sp_runtime::Perbill;
|
||||
|
||||
@@ -58,8 +58,7 @@ fn main() {
|
||||
&stake_of,
|
||||
)
|
||||
.unwrap();
|
||||
let winners = to_without_backing(unbalanced.winners.clone());
|
||||
let score = to_supports(winners.as_ref(), staked.as_ref()).unwrap().evaluate();
|
||||
let score = to_supports(staked.as_ref()).evaluate();
|
||||
|
||||
if score[0] == 0 {
|
||||
// such cases cannot be improved by balancing.
|
||||
@@ -83,8 +82,7 @@ fn main() {
|
||||
&stake_of,
|
||||
)
|
||||
.unwrap();
|
||||
let winners = to_without_backing(balanced.winners);
|
||||
to_supports(winners.as_ref(), staked.as_ref()).unwrap().evaluate()
|
||||
to_supports(staked.as_ref()).evaluate()
|
||||
};
|
||||
|
||||
let enhance = is_score_better(balanced_score, unbalanced_score, Perbill::zero());
|
||||
|
||||
@@ -23,8 +23,8 @@ use common::*;
|
||||
use honggfuzz::fuzz;
|
||||
use rand::{self, SeedableRng};
|
||||
use sp_npos_elections::{
|
||||
assignment_ratio_to_staked_normalized, is_score_better, phragmms, to_supports,
|
||||
to_without_backing, EvaluateSupport, VoteWeight,
|
||||
assignment_ratio_to_staked_normalized, is_score_better, phragmms, to_supports, EvaluateSupport,
|
||||
VoteWeight,
|
||||
};
|
||||
use sp_runtime::Perbill;
|
||||
|
||||
@@ -58,8 +58,7 @@ fn main() {
|
||||
&stake_of,
|
||||
)
|
||||
.unwrap();
|
||||
let winners = to_without_backing(unbalanced.winners.clone());
|
||||
let score = to_supports(&winners, &staked).unwrap().evaluate();
|
||||
let score = to_supports(&staked).evaluate();
|
||||
|
||||
if score[0] == 0 {
|
||||
// such cases cannot be improved by balancing.
|
||||
@@ -80,8 +79,7 @@ fn main() {
|
||||
let staked =
|
||||
assignment_ratio_to_staked_normalized(balanced.assignments.clone(), &stake_of)
|
||||
.unwrap();
|
||||
let winners = to_without_backing(balanced.winners);
|
||||
to_supports(winners.as_ref(), staked.as_ref()).unwrap().evaluate()
|
||||
to_supports(staked.as_ref()).evaluate()
|
||||
};
|
||||
|
||||
let enhance = is_score_better(balanced_score, unbalanced_score, Perbill::zero());
|
||||
|
||||
@@ -104,13 +104,11 @@ fn generate_random_phragmen_assignment(
|
||||
}
|
||||
|
||||
fn assert_assignments_equal(
|
||||
winners: &Vec<AccountId>,
|
||||
ass1: &Vec<StakedAssignment<AccountId>>,
|
||||
ass2: &Vec<StakedAssignment<AccountId>>,
|
||||
) {
|
||||
let support_1 = to_support_map::<AccountId>(winners, ass1).unwrap();
|
||||
let support_2 = to_support_map::<AccountId>(winners, ass2).unwrap();
|
||||
|
||||
let support_1 = to_support_map::<AccountId>(ass1);
|
||||
let support_2 = to_support_map::<AccountId>(ass2);
|
||||
for (who, support) in support_1.iter() {
|
||||
assert_eq!(support.total, support_2.get(who).unwrap().total);
|
||||
}
|
||||
@@ -134,7 +132,7 @@ fn reduce_and_compare(assignment: &Vec<StakedAssignment<AccountId>>, winners: &V
|
||||
num_changed,
|
||||
);
|
||||
|
||||
assert_assignments_equal(winners, &assignment, &altered_assignment);
|
||||
assert_assignments_equal(&assignment, &altered_assignment);
|
||||
}
|
||||
|
||||
fn assignment_len(assignments: &[StakedAssignment<AccountId>]) -> u32 {
|
||||
|
||||
Reference in New Issue
Block a user