Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump to quickcheck 1.0 #10

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 46 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ serde_ = { version = "1.0.114", default-features = false, optional = true, packa
[dev-dependencies]
lazy_static = "1.2"
rand = { version = "0.7.3", features = ["small_rng"] }
quickcheck = { version = "0.9", default-features = false }
quickcheck = { version = "1.0", default-features = false }
rayon_ = { version = "1.2.0", package = "rayon" }
serde_test = "1.0.114"
serde_json = "1.0.56"
Expand Down
33 changes: 18 additions & 15 deletions tests/quick.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ use atone::Vc;

use quickcheck::Arbitrary;
use quickcheck::Gen;

use rand::Rng;
use quickcheck::TestResult;

use std::cmp::min;
use std::collections::HashSet;
Expand Down Expand Up @@ -82,10 +81,14 @@ quickcheck! {
elements.iter().all(|v| vs.contains(v)) && vs.iter().all(|v| elements.contains(&v))
}

fn with_cap(cap: usize) -> bool {
fn with_cap(cap: usize) -> TestResult {
// Once https://github.com/BurntSushi/quickcheck/issues/267 is resolved: generate a number in range
if cap > 100 {
return TestResult::discard();
}
let vs: Vc<u8> = Vc::with_capacity(cap);
println!("wish: {}, got: {} (diff: {})", cap, vs.capacity(), vs.capacity() as isize - cap as isize);
vs.capacity() >= cap
TestResult::from_bool(vs.capacity() >= cap)
}
}

Expand All @@ -106,15 +109,15 @@ impl<T> Arbitrary for Op<T>
where
T: Arbitrary,
{
fn arbitrary<G: Gen>(g: &mut G) -> Self {
match g.gen::<u32>() % 9 {
fn arbitrary(g: &mut Gen) -> Self {
match u32::arbitrary(g) % 9 {
0 | 1 => Push(T::arbitrary(g)),
2 => Pop,
3 => PopFront,
4 => SwapRemove(g.gen::<u16>()),
5 => Insert(g.gen::<u16>(), T::arbitrary(g)),
6 => Truncate(g.gen::<u8>()),
7 => Reserve(g.gen::<u8>()),
4 => SwapRemove(u16::arbitrary(g)),
5 => Insert(u16::arbitrary(g), T::arbitrary(g)),
6 => Truncate(u8::arbitrary(g)),
7 => Reserve(u8::arbitrary(g)),
8 => CheckEnds,
_ => unreachable!(),
}
Expand Down Expand Up @@ -221,12 +224,12 @@ impl Deref for Alpha {
const ALPHABET: &[u8] = b"abcdefghijklmnopqrstuvwxyz";

impl Arbitrary for Alpha {
fn arbitrary<G: Gen>(g: &mut G) -> Self {
let len = g.next_u32() % g.size() as u32;
fn arbitrary(g: &mut Gen) -> Self {
let len = u32::arbitrary(g) % g.size() as u32;
let len = min(len, 16);
Alpha(
(0..len)
.map(|_| ALPHABET[g.next_u32() as usize % ALPHABET.len()] as char)
.map(|_| ALPHABET[u32::arbitrary(g) as usize % ALPHABET.len()] as char)
.collect(),
)
}
Expand All @@ -251,8 +254,8 @@ impl<T> Arbitrary for Large<Vec<T>>
where
T: Arbitrary,
{
fn arbitrary<G: Gen>(g: &mut G) -> Self {
let len = g.next_u32() % (g.size() * 10) as u32;
fn arbitrary(g: &mut Gen) -> Self {
let len = u32::arbitrary(g) % (g.size() * 10) as u32;
Large((0..len).map(|_| T::arbitrary(g)).collect())
}

Expand Down