From 8511aadf5afa9e3c6bf5901ec8368b37b3ccdb04 Mon Sep 17 00:00:00 2001 From: Giorgio Nocera Date: Thu, 8 Feb 2024 16:37:20 +0100 Subject: [PATCH 1/3] fix: :pencil2: closes #46 fix typo in error string Fixing a typo in error string returned by select_from_weighted method. --- src/select_from_weighted.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/select_from_weighted.rs b/src/select_from_weighted.rs index cd3f29c..946f1e7 100644 --- a/src/select_from_weighted.rs +++ b/src/select_from_weighted.rs @@ -45,7 +45,7 @@ pub fn select_from_weighted( } total_weight = total_weight .checked_add(*weight) - .ok_or_else(|| String::from("Total weight is greater than maximum value of u32"))?; + .ok_or_else(|| String::from("Total weight is greater than maximum value of u128"))?; } debug_assert!( @@ -135,7 +135,14 @@ mod tests { let err = select_from_weighted(RANDOMNESS1, &elements).unwrap_err(); // Check that the selected element has the expected weight - assert_eq!(err, "Total weight is greater than maximum value of u32"); + assert_eq!(err, "Total weight is greater than maximum value of u128"); + } + + #[test] + fn select_from_weighted_fails_with_total_weight_not_too_high() { + let elements: Vec<(i32, u128)> = vec![(1, u32::MAX.into()), (2, 1)]; + + select_from_weighted(RANDOMNESS1, &elements).unwrap(); } #[test] From 8777fb7ccafbd6d88be4df51bde596c7d1d351f5 Mon Sep 17 00:00:00 2001 From: Giorgio Nocera Date: Fri, 9 Feb 2024 15:25:07 +0100 Subject: [PATCH 2/3] Update src/select_from_weighted.rs Use correct name for test function. Co-authored-by: Simon Warta <2603011+webmaster128@users.noreply.github.com> --- src/select_from_weighted.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/select_from_weighted.rs b/src/select_from_weighted.rs index 946f1e7..20a95dd 100644 --- a/src/select_from_weighted.rs +++ b/src/select_from_weighted.rs @@ -139,7 +139,7 @@ mod tests { } #[test] - fn select_from_weighted_fails_with_total_weight_not_too_high() { + fn select_from_weighted_passes_with_total_weight_not_too_high() { let elements: Vec<(i32, u128)> = vec![(1, u32::MAX.into()), (2, 1)]; select_from_weighted(RANDOMNESS1, &elements).unwrap(); From a9ebc76df12695c465b678ffa757e92d20fa0bca Mon Sep 17 00:00:00 2001 From: Giorgio Nocera Date: Fri, 9 Feb 2024 15:27:15 +0100 Subject: [PATCH 3/3] Update src/select_from_weighted.rs Fix message error string. Co-authored-by: Simon Warta <2603011+webmaster128@users.noreply.github.com> --- src/select_from_weighted.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/select_from_weighted.rs b/src/select_from_weighted.rs index 20a95dd..a4cb386 100644 --- a/src/select_from_weighted.rs +++ b/src/select_from_weighted.rs @@ -45,7 +45,7 @@ pub fn select_from_weighted( } total_weight = total_weight .checked_add(*weight) - .ok_or_else(|| String::from("Total weight is greater than maximum value of u128"))?; + .ok_or_else(|| String::from("Total weight is greater than maximum value"))?; } debug_assert!(