99use num_bigint:: { BigInt , BigUint } ;
1010use num_integer:: Integer ;
1111use num_traits:: { Num , One , Signed , Zero } ;
12- use quickcheck:: { QuickCheck , StdThreadGen , TestResult } ;
12+ use quickcheck:: { Gen , QuickCheck , TestResult } ;
1313use quickcheck_macros:: quickcheck;
1414
1515#[ quickcheck]
@@ -42,8 +42,8 @@ fn quickcheck_signed_eq_symmetric(a: BigInt, b: BigInt) -> bool {
4242
4343#[ test]
4444fn 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]
282282fn 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]
319319fn 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( ) ) ;
0 commit comments