@@ -28,12 +28,15 @@ const LAZY_TESTS: bool = {
2828 }
2929} ;
3030
31+ const TESTS_NUM : usize = if LAZY_TESTS { 10 } else { 1000 } ;
32+
3133#[ test]
3234fn test_64_and_254_bit_add ( ) {
3335 print_script_size ( "254_bit_add" , U254 :: OP_ADD ( 1 , 0 ) ) ;
3436
3537 let mut prng = ChaCha20Rng :: seed_from_u64 ( 0 ) ;
36- for _ in 0 ..100 {
38+
39+ for _ in 0 ..TESTS_NUM {
3740 let a: BigUint = prng. sample ( RandomBits :: new ( 254 ) ) ;
3841 let b: BigUint = prng. sample ( RandomBits :: new ( 254 ) ) ;
3942 let c: BigUint = ( a. clone ( ) + b. clone ( ) ) . rem ( BigUint :: one ( ) . shl ( 254 ) ) ;
@@ -51,7 +54,7 @@ fn test_64_and_254_bit_add() {
5154 assert ! ( exec_result. success) ;
5255 }
5356
54- for _ in 0 ..100 {
57+ for _ in 0 ..TESTS_NUM {
5558 let a: u64 = prng. gen ( ) ;
5659 let b: u64 = prng. gen ( ) ;
5760 let c = a. wrapping_add ( b) ;
@@ -73,11 +76,10 @@ fn test_64_and_254_bit_add() {
7376#[ test]
7477fn test_508_bit_add ( ) {
7578 #[ allow( non_snake_case) ]
76- let TESTS_NUM : usize = if LAZY_TESTS { 100 } else { 1000 } ;
77-
7879 print_script_size ( "508_bit_add" , U508 :: OP_ADD ( 1 , 0 ) ) ;
7980
8081 let mut prng = ChaCha20Rng :: seed_from_u64 ( 0 ) ;
82+
8183 for _ in 0 ..TESTS_NUM {
8284 let a: BigUint = prng. sample ( RandomBits :: new ( 507 ) ) ;
8385 let b: BigUint = prng. sample ( RandomBits :: new ( 507 ) ) ;
@@ -100,11 +102,10 @@ fn test_508_bit_add() {
100102#[ test]
101103fn test_508_bit_add_no_overflow ( ) {
102104 #[ allow( non_snake_case) ]
103- let TESTS_NUM : usize = if LAZY_TESTS { 100 } else { 1000 } ;
104-
105105 print_script_size ( "508_bit_add_no_overflow" , U508 :: OP_ADD_NOOVERFLOW ( 1 , 0 ) ) ;
106106
107107 let mut prng = ChaCha20Rng :: seed_from_u64 ( 0 ) ;
108+
108109 for _ in 0 ..TESTS_NUM {
109110 let a: BigUint = prng. sample ( RandomBits :: new ( 507 ) ) ;
110111 let b: BigUint = prng. sample ( RandomBits :: new ( 507 ) ) ;
@@ -129,7 +130,8 @@ fn test_254_bit_sub() {
129130 print_script_size ( "254_bit_sub" , U254 :: OP_SUB ( 1 , 0 ) ) ;
130131
131132 let mut prng = ChaCha20Rng :: seed_from_u64 ( 0 ) ;
132- for _ in 0 ..100 {
133+
134+ for _ in 0 ..TESTS_NUM {
133135 let mut a: BigUint = prng. sample ( RandomBits :: new ( 254 ) ) ;
134136 let mut b: BigUint = prng. sample ( RandomBits :: new ( 254 ) ) ;
135137 if b > a {
@@ -156,7 +158,8 @@ fn test_64_and_254_bit_double() {
156158 print_script_size ( "u254_double" , U254 :: OP_2MUL ( 0 ) ) ;
157159
158160 let mut prng = ChaCha20Rng :: seed_from_u64 ( 0 ) ;
159- for _ in 0 ..100 {
161+
162+ for _ in 0 ..TESTS_NUM {
160163 let a: BigUint = prng. sample ( RandomBits :: new ( 254 ) ) ;
161164 let c: BigUint = ( a. clone ( ) + a. clone ( ) ) . rem ( BigUint :: one ( ) . shl ( 254 ) ) ;
162165
@@ -171,7 +174,7 @@ fn test_64_and_254_bit_double() {
171174 assert ! ( exec_result. success) ;
172175 }
173176
174- for _ in 0 ..100 {
177+ for _ in 0 ..TESTS_NUM {
175178 let a: u64 = prng. gen ( ) ;
176179 let c = a. wrapping_add ( a) ;
177180
@@ -190,14 +193,13 @@ fn test_64_and_254_bit_double() {
190193#[ test]
191194fn test_254_bit_double_no_overflow ( ) {
192195 #[ allow( non_snake_case) ]
193- let TESTS_NUM : usize = if LAZY_TESTS { 100 } else { 1000 } ;
194-
195196 print_script_size (
196197 "u254_double_no_overflow" ,
197198 U254 :: handle_OP_2MUL_NOOVERFLOW ( 0 ) ,
198199 ) ;
199200
200201 let mut prng = ChaCha20Rng :: seed_from_u64 ( 0 ) ;
202+
201203 for _ in 0 ..TESTS_NUM {
202204 let a: BigUint = prng. sample ( RandomBits :: new ( 253 ) ) ;
203205 let c: BigUint = a. clone ( ) + a. clone ( ) ;
@@ -217,7 +219,8 @@ fn test_254_bit_double_no_overflow() {
217219#[ test]
218220fn test_16_mul ( ) {
219221 let mut prng = ChaCha20Rng :: seed_from_u64 ( 0 ) ;
220- for _ in 0 ..100 {
222+
223+ for _ in 0 ..TESTS_NUM {
221224 let a: BigUint = prng. sample ( RandomBits :: new ( 254 ) ) ;
222225 let c: BigUint = ( 16 . to_biguint ( ) . unwrap ( ) * a. clone ( ) ) . rem ( BigUint :: one ( ) . shl ( 254 ) ) ;
223226
@@ -235,7 +238,7 @@ fn test_16_mul() {
235238 assert ! ( exec_result. success) ;
236239 }
237240
238- for _ in 0 ..100 {
241+ for _ in 0 ..TESTS_NUM {
239242 let a: u64 = prng. gen ( ) ;
240243 let c = a. wrapping_add ( a) ;
241244
@@ -254,7 +257,8 @@ fn test_16_mul() {
254257#[ test]
255258fn test_64_and_256_bit_2mul ( ) {
256259 let mut prng = ChaCha20Rng :: seed_from_u64 ( 0 ) ;
257- for _ in 0 ..100 {
260+
261+ for _ in 0 ..TESTS_NUM {
258262 let a: BigUint = prng. sample ( RandomBits :: new ( 254 ) ) ;
259263 let c: BigUint = ( 256 . to_biguint ( ) . unwrap ( ) * a. clone ( ) ) . rem ( BigUint :: one ( ) . shl ( 254 ) ) ;
260264
@@ -271,7 +275,7 @@ fn test_64_and_256_bit_2mul() {
271275 assert ! ( exec_result. success) ;
272276 }
273277
274- for _ in 0 ..100 {
278+ for _ in 0 ..TESTS_NUM {
275279 let a: u64 = prng. gen ( ) ;
276280 let c = a. wrapping_add ( a) ;
277281
@@ -294,10 +298,9 @@ fn test_64_and_256_bit_2mul() {
294298#[ test]
295299fn test_limb_add_carry ( ) {
296300 const BASE : u32 = 1 << 30 ;
297- #[ allow( non_snake_case) ]
298- let TESTS_NUM : usize = if LAZY_TESTS { 50 } else { 500 } ;
299301
300302 let mut prng = ChaCha20Rng :: seed_from_u64 ( 0 ) ;
303+
301304 for _ in 0 ..TESTS_NUM {
302305 // Generate two limbs
303306 let limb_1: u32 = prng. gen_range ( 0 ..1 << 30 ) ;
@@ -331,10 +334,9 @@ fn test_limb_add_carry() {
331334#[ test]
332335fn test_limb_doubling_initial_carry ( ) {
333336 const BASE : u32 = 1 << 30 ;
334- #[ allow( non_snake_case) ]
335- let TESTS_NUM : usize = if LAZY_TESTS { 50 } else { 500 } ;
336337
337338 let mut prng = ChaCha20Rng :: seed_from_u64 ( 0 ) ;
339+
338340 for _ in 0 ..TESTS_NUM {
339341 // Generate two limbs
340342 let limb: u32 = prng. gen_range ( 0 ..1 << 30 ) ;
@@ -366,10 +368,9 @@ fn test_limb_doubling_initial_carry() {
366368#[ test]
367369fn test_limb_sub_carry ( ) {
368370 const BASE : i32 = 1 << 30 ;
369- #[ allow( non_snake_case) ]
370- let TESTS_NUM : usize = if LAZY_TESTS { 50 } else { 500 } ;
371371
372372 let mut prng = ChaCha20Rng :: seed_from_u64 ( 0 ) ;
373+
373374 for _ in 0 ..TESTS_NUM {
374375 // Generate two limbs
375376 let limb_1: i32 = prng. gen_range ( 0 ..1 << 30 ) ;
@@ -399,7 +400,8 @@ fn test_limb_sub_carry() {
399400#[ test]
400401fn test_64_and_254_bit_increment ( ) {
401402 let mut prng = ChaCha20Rng :: seed_from_u64 ( 0 ) ;
402- for _ in 0 ..100 {
403+
404+ for _ in 0 ..TESTS_NUM {
403405 let a: BigUint = prng. sample ( RandomBits :: new ( 254 ) ) ;
404406 let c: BigUint = ( a. clone ( ) . add ( BigUint :: one ( ) ) ) . rem ( BigUint :: one ( ) . shl ( 254 ) ) ;
405407
@@ -414,7 +416,7 @@ fn test_64_and_254_bit_increment() {
414416 assert ! ( exec_result. success) ;
415417 }
416418
417- for _ in 0 ..100 {
419+ for _ in 0 ..TESTS_NUM {
418420 let a: u64 = prng. gen ( ) ;
419421 let c = a. wrapping_add ( 1u64 ) ;
420422
@@ -436,7 +438,8 @@ fn test_64_and_254_bit_narrow_mul() {
436438 print_script_size ( "254-bit narrow naive mul" , U254 :: OP_MUL ( ) ) ;
437439
438440 let mut prng = ChaCha20Rng :: seed_from_u64 ( 0 ) ;
439- for _ in 0 ..3 {
441+
442+ for _ in 0 ..TESTS_NUM {
440443 let a: BigUint = prng. sample ( RandomBits :: new ( 254 ) ) ;
441444 let b: BigUint = prng. sample ( RandomBits :: new ( 254 ) ) ;
442445 let c: BigUint = a. clone ( ) . mul ( b. clone ( ) ) . rem ( BigUint :: one ( ) . shl ( 254 ) ) ;
@@ -454,7 +457,7 @@ fn test_64_and_254_bit_narrow_mul() {
454457 assert ! ( exec_result. success) ;
455458 }
456459
457- for _ in 0 ..3 {
460+ for _ in 0 ..TESTS_NUM {
458461 let a: BigUint = prng. sample ( RandomBits :: new ( 64 ) ) ;
459462 let b: BigUint = prng. sample ( RandomBits :: new ( 64 ) ) ;
460463 let c: BigUint = ( a. clone ( ) . mul ( b. clone ( ) ) ) . rem ( BigUint :: one ( ) . shl ( 64 ) ) ;
@@ -481,10 +484,9 @@ fn test_254_bit_naive_widening_mul() {
481484 U254 :: handle_OP_WIDENINGMUL :: < U508 > ( ) ,
482485 ) ;
483486
484- const TESTS_NUMBER : usize = if LAZY_TESTS { 10 } else { 1000 } ;
485-
486487 let mut prng = ChaCha20Rng :: seed_from_u64 ( 0 ) ;
487- for _ in 0 ..TESTS_NUMBER {
488+
489+ for _ in 0 ..TESTS_NUM {
488490 let a: BigUint = prng. sample ( RandomBits :: new ( 254 ) ) ;
489491 let b: BigUint = prng. sample ( RandomBits :: new ( 254 ) ) ;
490492 let c: BigUint = a. clone ( ) * b. clone ( ) ;
@@ -512,10 +514,9 @@ fn test_254_bit_narrow_mul_w_width() {
512514
513515 print_script_size ( "254-bit w-width narrow mul" , U254Windowed :: OP_MUL ( ) ) ;
514516
515- const TESTS_NUMBER : usize = if LAZY_TESTS { 10 } else { 1000 } ;
516-
517517 let mut prng = ChaCha20Rng :: seed_from_u64 ( 0 ) ;
518- for _ in 0 ..TESTS_NUMBER {
518+
519+ for _ in 0 ..TESTS_NUM {
519520 let a: BigUint = prng. sample ( RandomBits :: new ( 254 ) ) ;
520521 let b: BigUint = prng. sample ( RandomBits :: new ( 254 ) ) ;
521522 let c: BigUint = a. clone ( ) . mul ( b. clone ( ) ) . rem ( BigUint :: one ( ) . shl ( 254 ) ) ;
@@ -542,10 +543,9 @@ fn test_254_bit_windowed_lazy_widening_mul() {
542543 U254Windowed :: handle_lazy_OP_WIDENINGMUL :: < U508 > ( ) ,
543544 ) ;
544545
545- const TESTS_NUMBER : usize = if LAZY_TESTS { 10 } else { 1000 } ;
546-
547546 let mut prng = ChaCha20Rng :: seed_from_u64 ( 0 ) ;
548- for _ in 0 ..TESTS_NUMBER {
547+
548+ for _ in 0 ..TESTS_NUM {
549549 let a: BigUint = prng. sample ( RandomBits :: new ( 100 ) ) ;
550550 let b: BigUint = prng. sample ( RandomBits :: new ( 100 ) ) ;
551551 let c: BigUint = a. clone ( ) * b. clone ( ) ;
@@ -569,10 +569,10 @@ fn test_254_bit_windowed_lazy_widening_mul() {
569569#[ test]
570570fn test_op_pick_stack_and_add_different_bits ( ) {
571571 type U456 = NonNativeBigIntImpl < 456 , 30 > ;
572- const TESTS_NUMBER : usize = if LAZY_TESTS { 10 } else { 1000 } ;
573572
574573 let mut prng = ChaCha20Rng :: seed_from_u64 ( 0 ) ;
575- for _ in 0 ..TESTS_NUMBER {
574+
575+ for _ in 0 ..TESTS_NUM {
576576 // Generating 4 254-bit numbers and put 456-bit number in the front
577577 let a1: BigUint = prng. sample ( RandomBits :: new ( 254 ) ) ;
578578 let a2: BigUint = prng. sample ( RandomBits :: new ( 254 ) ) ;
@@ -622,10 +622,9 @@ fn test_optimized_multiplication_step() {
622622 // additional space before conducting operations
623623 type U272 = NonNativeBigIntImpl < 272 , 30 > ;
624624
625- const TESTS_NUMBER : usize = if LAZY_TESTS { 10 } else { 1000 } ;
626-
627625 let mut prng = ChaCha20Rng :: seed_from_u64 ( 0 ) ;
628- for _ in 0 ..TESTS_NUMBER {
626+
627+ for _ in 0 ..TESTS_NUM {
629628 // On each step we want to get 16*a + b, where a is initially
630629 // 268 bits and later extended to 272 bits, and b is 256 bits.
631630 let a: BigUint = prng. sample ( RandomBits :: new ( 268 ) ) ;
@@ -666,10 +665,9 @@ fn test_254_bit_windowed_widening_optimized_mul() {
666665 U254Windowed :: OP_WIDENINGMUL :: < U508 > ( ) ,
667666 ) ;
668667
669- const TESTS_NUMBER : usize = if LAZY_TESTS { 10 } else { 1000 } ;
670-
671668 let mut prng = ChaCha20Rng :: seed_from_u64 ( 0 ) ;
672- for _ in 0 ..TESTS_NUMBER {
669+
670+ for _ in 0 ..TESTS_NUM {
673671 let a: BigUint = prng. sample ( RandomBits :: new ( 254 ) ) ;
674672 let b: BigUint = prng. sample ( RandomBits :: new ( 254 ) ) ;
675673 let c: BigUint = a. clone ( ) * b. clone ( ) ;
@@ -698,10 +696,9 @@ fn test_254_bit_29_windowed_widening_optimized_mul() {
698696 U254_29x9Windowed :: handle_optimized_OP_WIDENINGMUL ( ) ,
699697 ) ;
700698
701- const TESTS_NUMBER : usize = if LAZY_TESTS { 10 } else { 1000 } ;
702-
703699 let mut prng = ChaCha20Rng :: seed_from_u64 ( 0 ) ;
704- for _ in 0 ..TESTS_NUMBER {
700+
701+ for _ in 0 ..TESTS_NUM {
705702 let a: BigUint = prng. sample ( RandomBits :: new ( 254 ) ) ;
706703 let b: BigUint = prng. sample ( RandomBits :: new ( 254 ) ) ;
707704 let c: BigUint = a. clone ( ) * b. clone ( ) ;
0 commit comments