@@ -613,13 +613,12 @@ mod tests {
613
613
use assert_matches:: assert_matches;
614
614
615
615
use num_traits:: Num ;
616
- use rand:: Rng ;
617
616
618
617
#[ cfg( feature = "std" ) ]
619
618
use num_prime:: RandPrime ;
620
619
621
620
#[ cfg( feature = "std" ) ]
622
- use proptest:: prelude:: * ;
621
+ use proptest:: { array :: uniform4 , prelude:: * } ;
623
622
624
623
// Only used in proptest for now
625
624
#[ cfg( feature = "std" ) ]
@@ -1286,56 +1285,6 @@ mod tests {
1286
1285
assert_eq ! ( qm31_packed_reduced_mul( x, res) , Ok ( Felt252 :: from( 1 ) ) ) ;
1287
1286
}
1288
1287
1289
- // TODO: Refactor using proptest and separating particular cases
1290
- #[ test]
1291
- #[ cfg_attr( target_arch = "wasm32" , wasm_bindgen_test) ]
1292
- fn test_qm31_packed_reduced_inv_extensive ( ) {
1293
- let mut rng = SmallRng :: seed_from_u64 ( 11480028852697973135 ) ;
1294
- #[ derive( Clone , Copy ) ]
1295
- enum Configuration {
1296
- Zero ,
1297
- One ,
1298
- MinusOne ,
1299
- Random ,
1300
- }
1301
- let configurations = [
1302
- Configuration :: Zero ,
1303
- Configuration :: One ,
1304
- Configuration :: MinusOne ,
1305
- Configuration :: Random ,
1306
- ] ;
1307
- let mut cartesian_product = vec ! [ ] ;
1308
- for & a in & configurations {
1309
- for & b in & configurations {
1310
- for & c in & configurations {
1311
- for & d in & configurations {
1312
- cartesian_product. push ( [ a, b, c, d] ) ;
1313
- }
1314
- }
1315
- }
1316
- }
1317
-
1318
- for test_case in cartesian_product {
1319
- let x_coordinates: [ u64 ; 4 ] = test_case
1320
- . iter ( )
1321
- . map ( |& x| match x {
1322
- Configuration :: Zero => 0 ,
1323
- Configuration :: One => 1 ,
1324
- Configuration :: MinusOne => STWO_PRIME - 1 ,
1325
- Configuration :: Random => rng. gen_range ( 0 ..STWO_PRIME ) ,
1326
- } )
1327
- . collect :: < Vec < u64 > > ( )
1328
- . try_into ( )
1329
- . unwrap ( ) ;
1330
- if x_coordinates == [ 0 , 0 , 0 , 0 ] {
1331
- continue ;
1332
- }
1333
- let x = qm31_coordinates_to_packed_reduced ( x_coordinates) ;
1334
- let res = qm31_packed_reduced_inv ( x) . unwrap ( ) ;
1335
- assert_eq ! ( qm31_packed_reduced_mul( x, res) , Ok ( Felt252 :: from( 1 ) ) ) ;
1336
- }
1337
- }
1338
-
1339
1288
#[ test]
1340
1289
#[ cfg_attr( target_arch = "wasm32" , wasm_bindgen_test) ]
1341
1290
fn test_qm31_packed_reduced_div ( ) {
@@ -1353,8 +1302,38 @@ mod tests {
1353
1302
assert_eq ! ( res, y) ;
1354
1303
}
1355
1304
1305
+ /// Necessary strat to use proptest on the QM31 test
1306
+ #[ cfg( feature = "std" ) ]
1307
+ fn configuration_strat ( ) -> BoxedStrategy < u64 > {
1308
+ prop_oneof ! [ Just ( 0 ) , Just ( 1 ) , Just ( STWO_PRIME - 1 ) , 0 ..STWO_PRIME ] . boxed ( )
1309
+ }
1310
+
1356
1311
#[ cfg( feature = "std" ) ]
1357
1312
proptest ! {
1313
+
1314
+ #[ test]
1315
+ #[ cfg_attr( target_arch = "wasm32" , wasm_bindgen_test) ]
1316
+ fn qm31_packed_reduced_inv_random( x_coordinates in uniform4( 0u64 ..STWO_PRIME )
1317
+ . prop_filter( "All configs cant be 0" ,
1318
+ |arr| !arr. iter( ) . all( |x| * x == 0 ) )
1319
+ ) {
1320
+ let x = qm31_coordinates_to_packed_reduced( x_coordinates) ;
1321
+ let res = qm31_packed_reduced_inv( x) . unwrap( ) ;
1322
+ assert_eq!( qm31_packed_reduced_mul( x, res) , Ok ( Felt252 :: from( 1 ) ) ) ;
1323
+ }
1324
+
1325
+ #[ test]
1326
+ #[ cfg_attr( target_arch = "wasm32" , wasm_bindgen_test) ]
1327
+ fn qm31_packed_reduced_inv_extensive( x_coordinates in uniform4( configuration_strat( ) )
1328
+ . prop_filter( "All configs cant be 0" ,
1329
+ |arr| !arr. iter( ) . all( |x| * x == 0 ) )
1330
+ . no_shrink( )
1331
+ ) {
1332
+ let x = qm31_coordinates_to_packed_reduced( x_coordinates) ;
1333
+ let res = qm31_packed_reduced_inv( x) . unwrap( ) ;
1334
+ assert_eq!( qm31_packed_reduced_mul( x, res) , Ok ( Felt252 :: from( 1 ) ) ) ;
1335
+ }
1336
+
1358
1337
#[ test]
1359
1338
fn pow2_const_in_range_returns_power_of_2( x in 0 ..=251u32 ) {
1360
1339
prop_assert_eq!( pow2_const( x) , Felt252 :: TWO . pow( x) ) ;
0 commit comments