Skip to content

Commit 4f31683

Browse files
committed
Fix!: Update dependency 'rand' loosing isize generator.
Updating dependencies `rand` and `rand_chacha` to the latest version. BREAKING CHANGE: Monkey Test is loosing built in generators for type `isize`, since supported is removed in underlying lib rand. For details, see https://rust-random.github.io/book/update-0.9.html
1 parent 4625c37 commit 4f31683

File tree

10 files changed

+39
-33
lines changed

10 files changed

+39
-33
lines changed

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ maintenance = { status = "actively-developed" }
1818

1919
[dependencies]
2020
num-traits = "0.2"
21-
rand = "0.8.5"
22-
rand_chacha = "0.3.1"
21+
rand = "0.9.2"
22+
rand_chacha = "0.9.0"
2323
panic-message = "0.3.0"
2424

2525
[dev-dependencies]

DOCUMENTATION.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ struct DiceGen {
185185
impl Gen<u32> for DiceGen {
186186
fn examples(&self, seed: u64) -> BoxIter<u32> {
187187
let distr =
188-
rand::distributions::Uniform::new_inclusive(1, self.side_count);
188+
rand::distr::Uniform::new_inclusive(1, self.side_count).unwrap();
189189
let iter =
190190
rand_chacha::ChaCha8Rng::seed_from_u64(seed).sample_iter(distr);
191191
Box::new(iter)
@@ -212,7 +212,7 @@ use rand::SeedableRng;
212212

213213
fn dice_throw_generator_from_fn(side_count: u32) -> BoxGen<u32> {
214214
gens::from_fn(move |seed| {
215-
let distr = rand::distributions::Uniform::new_inclusive(1, side_count);
215+
let distr = rand::distr::Uniform::new_inclusive(1, side_count).unwrap();
216216
rand_chacha::ChaCha8Rng::seed_from_u64(seed).sample_iter(distr)
217217
})
218218
.with_shrinker(shrinks::int())

src/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ impl Conf {
6767

6868
/// The standard source to get randimization seed from.
6969
pub fn seed_to_use() -> u64 {
70-
rand_chacha::ChaCha8Rng::from_entropy().next_u64()
70+
rand_chacha::ChaCha8Rng::from_os_rng().next_u64()
7171
}
7272

7373
impl Default for Conf {

src/gens.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,9 @@ integer_module!(i16);
7777
integer_module!(i32);
7878
integer_module!(i64);
7979
integer_module!(i128);
80-
integer_module!(isize);
80+
// Macro is not used for type isize, since not supported in underlying lib rand.
81+
// For details, see https://rust-random.github.io/book/update-0.9.html
82+
8183
integer_module!(u8);
8284
integer_module!(u16);
8385
integer_module!(u32);

src/gens/float.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::gens;
77
use crate::BoxGen;
88
use crate::MapWithGen;
99
use num_traits::Float;
10-
use rand::distributions::uniform::SampleUniform;
10+
use rand::distr::uniform::SampleUniform;
1111
use rand::Rng;
1212
use rand::SeedableRng;
1313
use std::fmt::Debug;
@@ -146,10 +146,8 @@ where
146146
// Generate two's complement bits signed integer representation of finite
147147
// floats
148148
gens::from_fn(move |seed| {
149-
//let distr = rand::distributions::Uniform::new_inclusive(min, max);
150149
let mut x = rand_chacha::ChaCha8Rng::seed_from_u64(seed);
151-
152-
std::iter::from_fn(move || Some(x.gen_range(min..=max)))
150+
std::iter::from_fn(move || Some(x.random_range(min..=max)))
153151
})
154152
// Map to actual floats from two's complement bits
155153
.map(

src/gens/integer.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use crate::BoxGen;
44
use num_traits::PrimInt;
5-
use rand::distributions::uniform::SampleUniform;
5+
use rand::distr::uniform::SampleUniform;
66
use rand::Rng;
77
use rand::SeedableRng;
88
use std::ops::Bound;
@@ -41,7 +41,8 @@ where
4141
let max = end(&bounds);
4242

4343
crate::gens::from_fn(move |seed| {
44-
let distr = rand::distributions::Uniform::new_inclusive(min, max);
44+
let distr = rand::distr::Uniform::new_inclusive(min, max)
45+
.expect("distribution from bounds");
4546
rand_chacha::ChaCha8Rng::seed_from_u64(seed).sample_iter(distr)
4647
})
4748
.with_shrinker(crate::shrinks::int_in_range(min, max))

src/gens/mix.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ where
6666
{
6767
crate::gens::from_fn(move |seed| {
6868
let high = sample_target.sample_domain_max();
69-
let distr = rand::distributions::Uniform::new_inclusive(1usize, high);
69+
let distr = rand::distr::Uniform::new_inclusive(1usize, high).unwrap();
7070
let rng = rand_chacha::ChaCha8Rng::seed_from_u64(seed);
7171

7272
let mut sample_iterators =
@@ -177,7 +177,7 @@ mod test {
177177
(1, '4'),
178178
]);
179179

180-
assert_generator_has_distribution_within_percent(mixer, expected, 1.0)
180+
assert_generator_has_distribution_within_percent(mixer, expected, 1.5)
181181
}
182182

183183
#[test]

src/gens/pick.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ where
3737
{
3838
crate::gens::from_fn(move |seed| {
3939
let high = sample_target.sample_domain_max();
40-
let distr = rand::distributions::Uniform::new_inclusive(1usize, high);
40+
let distr = rand::distr::Uniform::new_inclusive(1usize, high).unwrap();
4141
let rng = rand_chacha::ChaCha8Rng::seed_from_u64(seed);
4242
let sample_target = sample_target.clone();
4343

src/gens/sized.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::cmp::min;
55

66
use crate::BoxGen;
77
use crate::BoxIter;
8-
use rand::distributions::Uniform;
8+
use rand::distr::Uniform;
99
use rand::Rng;
1010
use rand::SeedableRng;
1111

@@ -43,8 +43,9 @@ pub fn progressively_increasing(
4343
crate::gens::from_fn(move |seed| {
4444
let mut rng = rand_chacha::ChaCha8Rng::seed_from_u64(seed);
4545

46-
max_iterator(start_size, percent_increase, max_size)
47-
.map(move |max| rng.sample(Uniform::new_inclusive(0usize, max)))
46+
max_iterator(start_size, percent_increase, max_size).map(move |max| {
47+
rng.sample(Uniform::new_inclusive(0usize, max).unwrap())
48+
})
4849
})
4950
.with_shrinker(crate::shrinks::int_to_zero())
5051
}
@@ -151,7 +152,7 @@ mod test {
151152
.sum::<usize>() as f64;
152153

153154
let expected_sum = n as f64 * n as f64 / 4.0;
154-
let diff = expected_sum * 0.005;
155+
let diff = expected_sum * 0.010; // allow 1% difference
155156

156157
assert_approx_eq!(sum_of_examples, expected_sum, diff);
157158
}

src/gens/vec.rs

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,38 +20,42 @@
2020
//! vec![
2121
//! vec![],
2222
//! vec![9],
23+
//! vec![9],
24+
//! vec![9, 9],
2325
//! vec![9, 9],
24-
//! vec![9, 9, 9],
25-
//! vec![9, 9, 9, 9],
26-
//! vec![9, 9, 9],
27-
//! vec![9, 9, 9, 9, 9, 9],
2826
//! vec![9, 9, 9, 9, 9],
27+
//! vec![9, 9],
2928
//! vec![9, 9, 9, 9, 9, 9],
29+
//! vec![9, 9, 9, 9],
30+
//! vec![9, 9, 9, 9, 9, 9, 9, 9, 9, 9],
3031
//! vec![9, 9, 9],
31-
//! vec![9, 9, 9, 9, 9, 9, 9],
32-
//! vec![9, 9, 9],
33-
//! vec![9],
34-
//! vec![9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9],
35-
//! vec![9],
32+
//! vec![9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9],
3633
//!
37-
//! vec![9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9],
34+
//! vec![9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
35+
//! 9],
3836
//!
3937
//! vec![9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
40-
//! 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,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