Use MAX associated const (#9196)

* Use MAX associated const
This commit is contained in:
Squirrel
2021-06-24 11:53:49 +01:00
committed by GitHub
parent 09d9c2c9f6
commit ea1f21a904
56 changed files with 178 additions and 178 deletions
@@ -33,7 +33,7 @@ use sp_std::prelude::*;
/// The denominator used for loads. Since votes are collected as u64, the smallest ratio that we
/// might collect is `1/approval_stake` where approval stake is the sum of votes. Hence, some number
/// bigger than u64::max_value() is needed. For maximum accuracy we simply use u128;
/// bigger than u64::MAX is needed. For maximum accuracy we simply use u128;
const DEN: ExtendedBalance = ExtendedBalance::max_value();
/// Execute sequential phragmen with potentially some rounds of `balancing`. The return type is list
@@ -181,7 +181,7 @@ pub(crate) fn apply_elected<AccountId: IdentifierT>(
) {
let elected_who = elected_ptr.borrow().who.clone();
let cutoff = elected_ptr.borrow().score.to_den(1)
.expect("(n / d) < u128::max() and (n' / 1) == (n / d), thus n' < u128::max()'; qed.")
.expect("(n / d) < u128::MAX and (n' / 1) == (n / d), thus n' < u128::MAX'; qed.")
.n();
let mut elected_backed_stake = elected_ptr.borrow().backed_stake;
@@ -386,10 +386,10 @@ mod tests {
#[test]
fn large_balance_wont_overflow() {
let candidates = vec![1u32, 2, 3];
let mut voters = (0..1000).map(|i| (10 + i, u64::max_value(), vec![1, 2, 3])).collect::<Vec<_>>();
let mut voters = (0..1000).map(|i| (10 + i, u64::MAX, vec![1, 2, 3])).collect::<Vec<_>>();
// give a bit more to 1 and 3.
voters.push((2, u64::max_value(), vec![1, 3]));
voters.push((2, u64::MAX, vec![1, 3]));
let ElectionResult { winners, assignments: _ } = phragmms::<_, Perbill>(2, candidates, voters, Some((2, 0))).unwrap();
assert_eq!(winners.into_iter().map(|(w, _)| w).collect::<Vec<_>>(), vec![1u32, 3]);
@@ -458,11 +458,11 @@ fn phragmen_accuracy_on_large_scale_only_candidates() {
// candidate can have the maximum amount of tokens, and also supported by the maximum.
let candidates = vec![1, 2, 3, 4, 5];
let stake_of = create_stake_of(&[
(1, (u64::max_value() - 1).into()),
(2, (u64::max_value() - 4).into()),
(3, (u64::max_value() - 5).into()),
(4, (u64::max_value() - 3).into()),
(5, (u64::max_value() - 2).into()),
(1, (u64::MAX - 1).into()),
(2, (u64::MAX - 4).into()),
(3, (u64::MAX - 5).into()),
(4, (u64::MAX - 3).into()),
(5, (u64::MAX - 2).into()),
]);
let ElectionResult { winners, assignments } = seq_phragmen::<_, Perbill>(
@@ -489,13 +489,13 @@ fn phragmen_accuracy_on_large_scale_voters_and_candidates() {
];
voters.extend(auto_generate_self_voters(&candidates));
let stake_of = create_stake_of(&[
(1, (u64::max_value() - 1).into()),
(2, (u64::max_value() - 4).into()),
(3, (u64::max_value() - 5).into()),
(4, (u64::max_value() - 3).into()),
(5, (u64::max_value() - 2).into()),
(13, (u64::max_value() - 10).into()),
(14, u64::max_value().into()),
(1, (u64::MAX - 1).into()),
(2, (u64::MAX - 4).into()),
(3, (u64::MAX - 5).into()),
(4, (u64::MAX - 3).into()),
(5, (u64::MAX - 2).into()),
(13, (u64::MAX - 10).into()),
(14, u64::MAX.into()),
]);
let ElectionResult { winners, assignments } = seq_phragmen::<_, Perbill>(