aboutsummaryrefslogtreecommitdiff
path: root/src/seq
diff options
context:
space:
mode:
Diffstat (limited to 'src/seq')
-rw-r--r--src/seq/index.rs8
-rw-r--r--src/seq/mod.rs13
2 files changed, 9 insertions, 12 deletions
diff --git a/src/seq/index.rs b/src/seq/index.rs
index ae36c32..b38e464 100644
--- a/src/seq/index.rs
+++ b/src/seq/index.rs
@@ -16,11 +16,11 @@
use alloc::collections::BTreeSet;
#[cfg(feature = "std")] use std::collections::HashSet;
-#[cfg(feature = "alloc")]
-use crate::distributions::{uniform::SampleUniform, Distribution, Uniform};
#[cfg(feature = "std")]
use crate::distributions::WeightedError;
-use crate::Rng;
+
+#[cfg(feature = "alloc")]
+use crate::{Rng, distributions::{uniform::SampleUniform, Distribution, Uniform}};
#[cfg(feature = "serde1")]
use serde::{Serialize, Deserialize};
@@ -380,7 +380,7 @@ where
#[cfg(not(feature = "nightly"))]
{
- use std::collections::BinaryHeap;
+ use alloc::collections::BinaryHeap;
// Partially sort the array such that the `amount` elements with the largest
// keys are first using a binary max heap.
diff --git a/src/seq/mod.rs b/src/seq/mod.rs
index 9eeb777..069e9e6 100644
--- a/src/seq/mod.rs
+++ b/src/seq/mod.rs
@@ -1252,11 +1252,10 @@ mod test {
// Case 2: All of the weights are 0
let choices = [('a', 0), ('b', 0), ('c', 0)];
- let result = choices
+
+ assert_eq!(choices
.choose_multiple_weighted(&mut rng, 2, |item| item.1)
- .unwrap()
- .collect::<Vec<_>>();
- assert_eq!(result.len(), 2);
+ .unwrap().count(), 2);
// Case 3: Negative weights
let choices = [('a', -1), ('b', 1), ('c', 1)];
@@ -1269,11 +1268,9 @@ mod test {
// Case 4: Empty list
let choices = [];
- let result = choices
+ assert_eq!(choices
.choose_multiple_weighted(&mut rng, 0, |_: &()| 0)
- .unwrap()
- .collect::<Vec<_>>();
- assert_eq!(result.len(), 0);
+ .unwrap().count(), 0);
// Case 5: NaN weights
let choices = [('a', core::f64::NAN), ('b', 1.0), ('c', 1.0)];