Skip to content

Commit

Permalink
deps: upgrade rand to 0.8
Browse files Browse the repository at this point in the history
This upgrades to the latest version of rand.

Closes #264
  • Loading branch information
BurntSushi committed Dec 27, 2020
1 parent d286e4d commit 319145d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 23 deletions.
3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,4 @@ name = "quickcheck"
[dependencies]
env_logger = { version = "0.7.0", default-features = false, optional = true }
log = { version = "0.4", optional = true }
rand = { version = "0.7", features = ["small_rng"] }
rand_core = "0.5"
rand = { version = "0.8", default-features = false, features = ["small_rng", "std"] }
37 changes: 18 additions & 19 deletions src/arbitrary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,12 @@ impl Gen {
self.rng.gen()
}

fn gen_range<T, B1, B2>(&mut self, low: B1, high: B2) -> T
fn gen_range<T, R>(&mut self, range: R) -> T
where
T: rand::distributions::uniform::SampleUniform,
B1: rand::distributions::uniform::SampleBorrow<T> + Sized,
B2: rand::distributions::uniform::SampleBorrow<T> + Sized,
R: rand::distributions::uniform::SampleRange<T>,
{
self.rng.gen_range(low, high)
self.rng.gen_range(range)
}
}

Expand Down Expand Up @@ -253,7 +252,7 @@ impl<A: Arbitrary> Arbitrary for Vec<A> {
fn arbitrary(g: &mut Gen) -> Vec<A> {
let size = {
let s = g.size();
g.gen_range(0, s)
g.gen_range(0..s)
};
(0..size).map(|_| A::arbitrary(g)).collect()
}
Expand Down Expand Up @@ -576,7 +575,7 @@ impl Arbitrary for String {
fn arbitrary(g: &mut Gen) -> String {
let size = {
let s = g.size();
g.gen_range(0, s)
g.gen_range(0..s)
};
(0..size).map(|_| char::arbitrary(g)).collect()
}
Expand All @@ -592,7 +591,7 @@ impl Arbitrary for CString {
fn arbitrary(g: &mut Gen) -> Self {
let size = {
let s = g.size();
g.gen_range(0, s)
g.gen_range(0..s)
};
// Use either random bytes or random UTF-8 encoded codepoints.
let utf8: bool = g.gen();
Expand Down Expand Up @@ -630,16 +629,16 @@ impl Arbitrary for CString {

impl Arbitrary for char {
fn arbitrary(g: &mut Gen) -> char {
let mode = g.gen_range(0, 100);
let mode = g.gen_range(0..100);
match mode {
0..=49 => {
// ASCII + some control characters
g.gen_range(0, 0xB0) as u8 as char
g.gen_range(0..0xB0) as u8 as char
}
50..=59 => {
// Unicode BMP characters
loop {
if let Some(x) = char::from_u32(g.gen_range(0, 0x10000)) {
if let Some(x) = char::from_u32(g.gen_range(0..0x10000)) {
return x;
}
// ignore surrogate pairs
Expand Down Expand Up @@ -715,7 +714,7 @@ impl Arbitrary for char {
}
90..=94 => {
// Tricky unicode, part 2
char::from_u32(g.gen_range(0x2000, 0x2070)).unwrap()
char::from_u32(g.gen_range(0x2000..0x2070)).unwrap()
}
95..=99 => {
// Completely arbitrary characters
Expand Down Expand Up @@ -779,7 +778,7 @@ macro_rules! unsigned_arbitrary {
$(
impl Arbitrary for $ty {
fn arbitrary(g: &mut Gen) -> $ty {
match g.gen_range(0, 10) {
match g.gen_range(0..10) {
0 => {
*g.choose(unsigned_problem_values!($ty)).unwrap()
},
Expand Down Expand Up @@ -849,7 +848,7 @@ macro_rules! signed_arbitrary {
$(
impl Arbitrary for $ty {
fn arbitrary(g: &mut Gen) -> $ty {
match g.gen_range(0, 10) {
match g.gen_range(0..10) {
0 => {
*g.choose(signed_problem_values!($ty)).unwrap()
},
Expand Down Expand Up @@ -881,12 +880,12 @@ macro_rules! float_arbitrary {
($($t:ty, $path:path, $shrinkable:ty),+) => {$(
impl Arbitrary for $t {
fn arbitrary(g: &mut Gen) -> $t {
match g.gen_range(0, 10) {
match g.gen_range(0..10) {
0 => *g.choose(float_problem_values!($path)).unwrap(),
_ => {
use $path as p;
let exp = g.gen_range(0., p::MAX_EXP as i16 as $t);
let mantissa = g.gen_range(1., 2.);
let exp = g.gen_range((0.)..p::MAX_EXP as i16 as $t);
let mantissa = g.gen_range((1.)..2.);
let sign = *g.choose(&[-1., 1.]).unwrap();
sign * mantissa * exp.exp2()
}
Expand Down Expand Up @@ -987,7 +986,7 @@ impl<T: Arbitrary> Arbitrary for Wrapping<T> {

impl<T: Arbitrary> Arbitrary for Bound<T> {
fn arbitrary(g: &mut Gen) -> Bound<T> {
match g.gen_range(0, 3) {
match g.gen_range(0..3) {
0 => Bound::Included(T::arbitrary(g)),
1 => Bound::Excluded(T::arbitrary(g)),
_ => Bound::Unbounded,
Expand Down Expand Up @@ -1065,8 +1064,8 @@ impl Arbitrary for RangeFull {

impl Arbitrary for Duration {
fn arbitrary(gen: &mut Gen) -> Self {
let seconds = gen.gen_range(0, gen.size() as u64);
let nanoseconds = gen.gen_range(0, 1_000_000);
let seconds = gen.gen_range(0..gen.size() as u64);
let nanoseconds = gen.gen_range(0..1_000_000);
Duration::new(seconds, nanoseconds)
}

Expand Down
2 changes: 0 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ extern crate env_logger;
#[cfg(feature = "use_logging")]
#[macro_use]
extern crate log;
extern crate rand;
extern crate rand_core;

pub use crate::arbitrary::{empty_shrinker, single_shrinker, Arbitrary, Gen};
pub use crate::tester::{quickcheck, QuickCheck, TestResult, Testable};
Expand Down

0 comments on commit 319145d

Please sign in to comment.