Skip to content

Commit 96cf255

Browse files
committed
Update to arbitrary-1 and quickcheck-1
1 parent 60637c5 commit 96cf255

File tree

10 files changed

+49
-34
lines changed

10 files changed

+49
-34
lines changed

.github/workflows/ci.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ jobs:
1414
matrix:
1515
rust: [
1616
1.31.0, # 2018!
17-
1.34.0, # quickcheck, has_try_from
17+
1.34.0, # has_try_from
1818
1.36.0, # alloc, rand
19+
1.40.0, # arbitrary
20+
1.46.0, # quickcheck
1921
stable,
2022
beta,
2123
nightly

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,12 @@ default-features = false
6262

6363
[dependencies.quickcheck]
6464
optional = true
65-
version = "0.9"
65+
version = "1"
6666
default-features = false
6767

6868
[dependencies.arbitrary]
6969
optional = true
70-
version = "0.4"
70+
version = "1"
7171
default-features = false
7272

7373
[build-dependencies]

bors.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ status = [
22
"Test (1.31.0)",
33
"Test (1.34.0)",
44
"Test (1.36.0)",
5+
"Test (1.40.0)",
6+
"Test (1.46.0)",
57
"Test (stable)",
68
"Test (beta)",
79
"Test (nightly)",

ci/big_quickcheck/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ edition = "2018"
77
[dependencies]
88
num-integer = "0.1.42"
99
num-traits = "0.2.11"
10-
quickcheck_macros = "0.9"
10+
quickcheck_macros = "1"
1111

1212
[dependencies.quickcheck]
13-
version = "0.9"
13+
version = "1"
1414
default-features = false
1515

1616
[dependencies.num-bigint]

ci/big_quickcheck/src/lib.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
use num_bigint::{BigInt, BigUint};
1010
use num_integer::Integer;
1111
use num_traits::{Num, One, Signed, Zero};
12-
use quickcheck::{QuickCheck, StdThreadGen, TestResult};
12+
use quickcheck::{Gen, QuickCheck, TestResult};
1313
use quickcheck_macros::quickcheck;
1414

1515
#[quickcheck]
@@ -42,8 +42,8 @@ fn quickcheck_signed_eq_symmetric(a: BigInt, b: BigInt) -> bool {
4242

4343
#[test]
4444
fn quickcheck_arith_primitive() {
45-
let gen = StdThreadGen::new(usize::max_value());
46-
let mut qc = QuickCheck::with_gen(gen);
45+
let gen = Gen::new(usize::max_value());
46+
let mut qc = QuickCheck::new().gen(gen);
4747

4848
fn test_unsigned_add_primitive(a: usize, b: usize) -> TestResult {
4949
let actual = BigUint::from(a) + BigUint::from(b);
@@ -79,11 +79,11 @@ fn quickcheck_arith_primitive() {
7979
}
8080
}
8181

82-
fn test_signed_sub_primitive(a: i128, b: i128) -> bool {
83-
if b < a {
84-
BigInt::from(a - b) == BigInt::from(a) - BigInt::from(b)
85-
} else {
86-
BigInt::from(b - a) == BigInt::from(b) - BigInt::from(a)
82+
fn test_signed_sub_primitive(a: i128, b: i128) -> TestResult {
83+
let actual = BigInt::from(a) - BigInt::from(b);
84+
match a.checked_sub(b) {
85+
None => TestResult::discard(),
86+
Some(expected) => TestResult::from_bool(BigInt::from(expected) == actual),
8787
}
8888
}
8989

@@ -96,7 +96,7 @@ fn quickcheck_arith_primitive() {
9696
}
9797

9898
fn test_signed_div_primitive(a: i128, b: i128) -> TestResult {
99-
if b == 0 {
99+
if b == 0 || (a == i128::MIN && b == -1) {
100100
TestResult::discard()
101101
} else {
102102
TestResult::from_bool(BigInt::from(a / b) == BigInt::from(a) / BigInt::from(b))
@@ -108,7 +108,7 @@ fn quickcheck_arith_primitive() {
108108
qc.quickcheck(test_unsigned_mul_primitive as fn(u64, u64) -> bool);
109109
qc.quickcheck(test_signed_mul_primitive as fn(i64, i64) -> bool);
110110
qc.quickcheck(test_unsigned_sub_primitive as fn(u128, u128) -> bool);
111-
qc.quickcheck(test_signed_sub_primitive as fn(i128, i128) -> bool);
111+
qc.quickcheck(test_signed_sub_primitive as fn(i128, i128) -> TestResult);
112112
qc.quickcheck(test_unsigned_div_primitive as fn(u128, u128) -> TestResult);
113113
qc.quickcheck(test_signed_div_primitive as fn(i128, i128) -> TestResult);
114114
}
@@ -280,8 +280,8 @@ fn quickcheck_signed_conversion(a: BigInt, radix: u8) -> TestResult {
280280

281281
#[test]
282282
fn quicktest_shift() {
283-
let gen = StdThreadGen::new(usize::max_value());
284-
let mut qc = QuickCheck::with_gen(gen);
283+
let gen = Gen::new(usize::max_value());
284+
let mut qc = QuickCheck::new().gen(gen);
285285

286286
fn test_shr_unsigned(a: u64, shift: u8) -> TestResult {
287287
let shift = (shift % 64) as usize; //shift at most 64 bits
@@ -317,8 +317,8 @@ fn quicktest_shift() {
317317

318318
#[test]
319319
fn quickcheck_modpow() {
320-
let gen = StdThreadGen::new(usize::max_value());
321-
let mut qc = QuickCheck::with_gen(gen);
320+
let gen = Gen::new(usize::max_value());
321+
let mut qc = QuickCheck::new().gen(gen);
322322

323323
fn simple_modpow(base: &BigInt, exponent: &BigInt, modulus: &BigInt) -> BigInt {
324324
assert!(!exponent.is_negative());

ci/rustup.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
set -ex
66

77
ci=$(dirname $0)
8-
for version in 1.31.0 1.34.0 1.36.0 stable beta nightly; do
8+
for version in 1.31.0 1.34.0 1.36.0 1.40.0 1.46.0 stable beta nightly; do
99
rustup run "$version" "$ci/test_full.sh"
1010
done

ci/test_full.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ if ! check_version $MSRV ; then
2828
fi
2929

3030
STD_FEATURES=(serde)
31-
check_version 1.34 && STD_FEATURES+=(quickcheck)
3231
check_version 1.36 && STD_FEATURES+=(rand)
3332
check_version 1.36 && NO_STD_FEATURES=(serde rand)
3433
check_version 1.40 && STD_FEATURES+=(arbitrary)
34+
check_version 1.46 && STD_FEATURES+=(quickcheck)
3535
echo "Testing supported features: ${STD_FEATURES[*]}"
3636
if [ -n "${NO_STD_FEATURES[*]}" ]; then
3737
echo " no_std supported features: ${NO_STD_FEATURES[*]}"

src/bigint/arbitrary.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
use super::{BigInt, Sign};
22

3+
#[cfg(feature = "quickcheck")]
34
use crate::std_alloc::Box;
45
use crate::BigUint;
56

67
#[cfg(feature = "quickcheck")]
78
impl quickcheck::Arbitrary for BigInt {
8-
fn arbitrary<G: quickcheck::Gen>(g: &mut G) -> Self {
9+
fn arbitrary(g: &mut quickcheck::Gen) -> Self {
910
let positive = bool::arbitrary(g);
1011
let sign = if positive { Sign::Plus } else { Sign::Minus };
1112
Self::from_biguint(sign, BigUint::arbitrary(g))
@@ -19,16 +20,20 @@ impl quickcheck::Arbitrary for BigInt {
1920
}
2021

2122
#[cfg(feature = "arbitrary")]
22-
impl arbitrary::Arbitrary for BigInt {
23+
impl arbitrary::Arbitrary<'_> for BigInt {
2324
fn arbitrary(u: &mut arbitrary::Unstructured<'_>) -> arbitrary::Result<Self> {
2425
let positive = bool::arbitrary(u)?;
2526
let sign = if positive { Sign::Plus } else { Sign::Minus };
2627
Ok(Self::from_biguint(sign, BigUint::arbitrary(u)?))
2728
}
2829

29-
fn shrink(&self) -> Box<dyn Iterator<Item = Self>> {
30-
let sign = self.sign();
31-
let unsigned_shrink = self.data.shrink();
32-
Box::new(unsigned_shrink.map(move |x| BigInt::from_biguint(sign, x)))
30+
fn arbitrary_take_rest(mut u: arbitrary::Unstructured<'_>) -> arbitrary::Result<Self> {
31+
let positive = bool::arbitrary(&mut u)?;
32+
let sign = if positive { Sign::Plus } else { Sign::Minus };
33+
Ok(Self::from_biguint(sign, BigUint::arbitrary_take_rest(u)?))
34+
}
35+
36+
fn size_hint(depth: usize) -> (usize, Option<usize>) {
37+
arbitrary::size_hint::and(bool::size_hint(depth), BigUint::size_hint(depth))
3338
}
3439
}

src/biguint/arbitrary.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
use super::{biguint_from_vec, BigUint};
22

33
use crate::big_digit::BigDigit;
4-
use crate::std_alloc::{Box, Vec};
4+
#[cfg(feature = "quickcheck")]
5+
use crate::std_alloc::Box;
6+
use crate::std_alloc::Vec;
57

68
#[cfg(feature = "quickcheck")]
79
impl quickcheck::Arbitrary for BigUint {
8-
fn arbitrary<G: quickcheck::Gen>(g: &mut G) -> Self {
10+
fn arbitrary(g: &mut quickcheck::Gen) -> Self {
911
// Use arbitrary from Vec
1012
biguint_from_vec(Vec::<BigDigit>::arbitrary(g))
1113
}
@@ -17,12 +19,16 @@ impl quickcheck::Arbitrary for BigUint {
1719
}
1820

1921
#[cfg(feature = "arbitrary")]
20-
impl arbitrary::Arbitrary for BigUint {
22+
impl arbitrary::Arbitrary<'_> for BigUint {
2123
fn arbitrary(u: &mut arbitrary::Unstructured<'_>) -> arbitrary::Result<Self> {
2224
Ok(biguint_from_vec(Vec::<BigDigit>::arbitrary(u)?))
2325
}
2426

25-
fn shrink(&self) -> Box<dyn Iterator<Item = Self>> {
26-
Box::new(self.data.shrink().map(biguint_from_vec))
27+
fn arbitrary_take_rest(u: arbitrary::Unstructured<'_>) -> arbitrary::Result<Self> {
28+
Ok(biguint_from_vec(Vec::<BigDigit>::arbitrary_take_rest(u)?))
29+
}
30+
31+
fn size_hint(depth: usize) -> (usize, Option<usize>) {
32+
Vec::<BigDigit>::size_hint(depth)
2733
}
2834
}

src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ extern crate std;
9494
#[cfg(feature = "std")]
9595
mod std_alloc {
9696
pub(crate) use std::borrow::Cow;
97-
#[cfg(any(feature = "quickcheck", feature = "arbitrary"))]
97+
#[cfg(any(feature = "quickcheck"))]
9898
pub(crate) use std::boxed::Box;
9999
pub(crate) use std::string::String;
100100
pub(crate) use std::vec::Vec;
@@ -107,7 +107,7 @@ extern crate alloc;
107107
#[cfg(not(feature = "std"))]
108108
mod std_alloc {
109109
pub(crate) use alloc::borrow::Cow;
110-
#[cfg(any(feature = "quickcheck", feature = "arbitrary"))]
110+
#[cfg(any(feature = "quickcheck"))]
111111
pub(crate) use alloc::boxed::Box;
112112
pub(crate) use alloc::string::String;
113113
pub(crate) use alloc::vec::Vec;

0 commit comments

Comments
 (0)