@@ -290,16 +290,66 @@ fn test_ctoption() {
290
290
) ) ;
291
291
292
292
// Test (in)equality
293
- assert ! ( CtOption :: new( 1 , Choice :: from( 0 ) ) . ct_eq( & CtOption :: new( 1 , Choice :: from( 1 ) ) ) . unwrap_u8( ) == 0 ) ;
294
- assert ! ( CtOption :: new( 1 , Choice :: from( 1 ) ) . ct_eq( & CtOption :: new( 1 , Choice :: from( 0 ) ) ) . unwrap_u8( ) == 0 ) ;
295
- assert ! ( CtOption :: new( 1 , Choice :: from( 0 ) ) . ct_eq( & CtOption :: new( 2 , Choice :: from( 1 ) ) ) . unwrap_u8( ) == 0 ) ;
296
- assert ! ( CtOption :: new( 1 , Choice :: from( 1 ) ) . ct_eq( & CtOption :: new( 2 , Choice :: from( 0 ) ) ) . unwrap_u8( ) == 0 ) ;
297
- assert ! ( CtOption :: new( 1 , Choice :: from( 0 ) ) . ct_eq( & CtOption :: new( 1 , Choice :: from( 0 ) ) ) . unwrap_u8( ) == 1 ) ;
298
- assert ! ( CtOption :: new( 1 , Choice :: from( 0 ) ) . ct_eq( & CtOption :: new( 2 , Choice :: from( 0 ) ) ) . unwrap_u8( ) == 1 ) ;
299
- assert ! ( CtOption :: new( 1 , Choice :: from( 1 ) ) . ct_eq( & CtOption :: new( 2 , Choice :: from( 1 ) ) ) . unwrap_u8( ) == 0 ) ;
300
- assert ! ( CtOption :: new( 1 , Choice :: from( 1 ) ) . ct_eq( & CtOption :: new( 2 , Choice :: from( 1 ) ) ) . unwrap_u8( ) == 0 ) ;
301
- assert ! ( CtOption :: new( 1 , Choice :: from( 1 ) ) . ct_eq( & CtOption :: new( 1 , Choice :: from( 1 ) ) ) . unwrap_u8( ) == 1 ) ;
302
- assert ! ( CtOption :: new( 1 , Choice :: from( 1 ) ) . ct_eq( & CtOption :: new( 1 , Choice :: from( 1 ) ) ) . unwrap_u8( ) == 1 ) ;
293
+ assert ! (
294
+ CtOption :: new( 1 , Choice :: from( 0 ) )
295
+ . ct_eq( & CtOption :: new( 1 , Choice :: from( 1 ) ) )
296
+ . unwrap_u8( )
297
+ == 0
298
+ ) ;
299
+ assert ! (
300
+ CtOption :: new( 1 , Choice :: from( 1 ) )
301
+ . ct_eq( & CtOption :: new( 1 , Choice :: from( 0 ) ) )
302
+ . unwrap_u8( )
303
+ == 0
304
+ ) ;
305
+ assert ! (
306
+ CtOption :: new( 1 , Choice :: from( 0 ) )
307
+ . ct_eq( & CtOption :: new( 2 , Choice :: from( 1 ) ) )
308
+ . unwrap_u8( )
309
+ == 0
310
+ ) ;
311
+ assert ! (
312
+ CtOption :: new( 1 , Choice :: from( 1 ) )
313
+ . ct_eq( & CtOption :: new( 2 , Choice :: from( 0 ) ) )
314
+ . unwrap_u8( )
315
+ == 0
316
+ ) ;
317
+ assert ! (
318
+ CtOption :: new( 1 , Choice :: from( 0 ) )
319
+ . ct_eq( & CtOption :: new( 1 , Choice :: from( 0 ) ) )
320
+ . unwrap_u8( )
321
+ == 1
322
+ ) ;
323
+ assert ! (
324
+ CtOption :: new( 1 , Choice :: from( 0 ) )
325
+ . ct_eq( & CtOption :: new( 2 , Choice :: from( 0 ) ) )
326
+ . unwrap_u8( )
327
+ == 1
328
+ ) ;
329
+ assert ! (
330
+ CtOption :: new( 1 , Choice :: from( 1 ) )
331
+ . ct_eq( & CtOption :: new( 2 , Choice :: from( 1 ) ) )
332
+ . unwrap_u8( )
333
+ == 0
334
+ ) ;
335
+ assert ! (
336
+ CtOption :: new( 1 , Choice :: from( 1 ) )
337
+ . ct_eq( & CtOption :: new( 2 , Choice :: from( 1 ) ) )
338
+ . unwrap_u8( )
339
+ == 0
340
+ ) ;
341
+ assert ! (
342
+ CtOption :: new( 1 , Choice :: from( 1 ) )
343
+ . ct_eq( & CtOption :: new( 1 , Choice :: from( 1 ) ) )
344
+ . unwrap_u8( )
345
+ == 1
346
+ ) ;
347
+ assert ! (
348
+ CtOption :: new( 1 , Choice :: from( 1 ) )
349
+ . ct_eq( & CtOption :: new( 1 , Choice :: from( 1 ) ) )
350
+ . unwrap_u8( )
351
+ == 1
352
+ ) ;
303
353
}
304
354
305
355
#[ test]
@@ -327,7 +377,7 @@ macro_rules! generate_greater_than_test {
327
377
assert!( z. unwrap_u8( ) == 1 ) ;
328
378
}
329
379
}
330
- }
380
+ } ;
331
381
}
332
382
333
383
#[ test]
@@ -358,16 +408,26 @@ fn greater_than_u128() {
358
408
359
409
#[ test]
360
410
fn greater_than_ordering ( ) {
361
- assert_eq ! ( cmp:: Ordering :: Less . ct_gt( & cmp:: Ordering :: Greater ) . unwrap_u8( ) , 0 ) ;
362
- assert_eq ! ( cmp:: Ordering :: Greater . ct_gt( & cmp:: Ordering :: Less ) . unwrap_u8( ) , 1 ) ;
411
+ assert_eq ! (
412
+ cmp:: Ordering :: Less
413
+ . ct_gt( & cmp:: Ordering :: Greater )
414
+ . unwrap_u8( ) ,
415
+ 0
416
+ ) ;
417
+ assert_eq ! (
418
+ cmp:: Ordering :: Greater
419
+ . ct_gt( & cmp:: Ordering :: Less )
420
+ . unwrap_u8( ) ,
421
+ 1
422
+ ) ;
363
423
}
364
424
365
425
#[ test]
366
426
/// Test that the two's compliment min and max, i.e. 0000...0001 < 1111...1110,
367
427
/// gives the correct result. (This fails using the bit-twiddling algorithm that
368
428
/// go/crypto/subtle uses.)
369
429
fn less_than_twos_compliment_minmax ( ) {
370
- let z = 1u32 . ct_lt ( & ( 2u32 . pow ( 31 ) - 1 ) ) ;
430
+ let z = 1u32 . ct_lt ( & ( 2u32 . pow ( 31 ) - 1 ) ) ;
371
431
372
432
assert ! ( z. unwrap_u8( ) == 1 ) ;
373
433
}
@@ -389,7 +449,7 @@ macro_rules! generate_less_than_test {
389
449
assert!( z. unwrap_u8( ) == 1 ) ;
390
450
}
391
451
}
392
- }
452
+ } ;
393
453
}
394
454
395
455
#[ test]
@@ -420,6 +480,16 @@ fn less_than_u128() {
420
480
421
481
#[ test]
422
482
fn less_than_ordering ( ) {
423
- assert_eq ! ( cmp:: Ordering :: Greater . ct_lt( & cmp:: Ordering :: Less ) . unwrap_u8( ) , 0 ) ;
424
- assert_eq ! ( cmp:: Ordering :: Less . ct_lt( & cmp:: Ordering :: Greater ) . unwrap_u8( ) , 1 ) ;
483
+ assert_eq ! (
484
+ cmp:: Ordering :: Greater
485
+ . ct_lt( & cmp:: Ordering :: Less )
486
+ . unwrap_u8( ) ,
487
+ 0
488
+ ) ;
489
+ assert_eq ! (
490
+ cmp:: Ordering :: Less
491
+ . ct_lt( & cmp:: Ordering :: Greater )
492
+ . unwrap_u8( ) ,
493
+ 1
494
+ ) ;
425
495
}
0 commit comments