@@ -1775,3 +1775,34 @@ fn test_pow() {
17751775 check ! ( u128 ) ;
17761776 check ! ( usize ) ;
17771777}
1778+
1779+ #[ test]
1780+ fn test_trailing_zeros ( ) {
1781+ assert ! ( BigUint :: from( 0u8 ) . trailing_zeros( ) . is_none( ) ) ;
1782+ assert_eq ! ( BigUint :: from( 1u8 ) . trailing_zeros( ) . unwrap( ) , 0 ) ;
1783+ assert_eq ! ( BigUint :: from( 2u8 ) . trailing_zeros( ) . unwrap( ) , 1 ) ;
1784+ let x: BigUint = BigUint :: one ( ) << 128 ;
1785+ assert_eq ! ( x. trailing_zeros( ) . unwrap( ) , 128 ) ;
1786+ }
1787+
1788+ #[ test]
1789+ fn test_trailing_ones ( ) {
1790+ assert_eq ! ( BigUint :: from( 0u8 ) . trailing_ones( ) , 0 ) ;
1791+ assert_eq ! ( BigUint :: from( 1u8 ) . trailing_ones( ) , 1 ) ;
1792+ assert_eq ! ( BigUint :: from( 2u8 ) . trailing_ones( ) , 0 ) ;
1793+ assert_eq ! ( BigUint :: from( 3u8 ) . trailing_ones( ) , 2 ) ;
1794+ let x: BigUint = ( BigUint :: from ( 3u8 ) << 128 ) | BigUint :: from ( 3u8 ) ;
1795+ assert_eq ! ( x. trailing_ones( ) , 2 ) ;
1796+ let x: BigUint = ( BigUint :: one ( ) << 128 ) - BigUint :: one ( ) ;
1797+ assert_eq ! ( x. trailing_ones( ) , 128 ) ;
1798+ }
1799+
1800+ #[ test]
1801+ fn test_count_ones ( ) {
1802+ assert_eq ! ( BigUint :: from( 0u8 ) . count_ones( ) , 0 ) ;
1803+ assert_eq ! ( BigUint :: from( 1u8 ) . count_ones( ) , 1 ) ;
1804+ assert_eq ! ( BigUint :: from( 2u8 ) . count_ones( ) , 1 ) ;
1805+ assert_eq ! ( BigUint :: from( 3u8 ) . count_ones( ) , 2 ) ;
1806+ let x: BigUint = ( BigUint :: from ( 3u8 ) << 128 ) | BigUint :: from ( 3u8 ) ;
1807+ assert_eq ! ( x. count_ones( ) , 4 ) ;
1808+ }
0 commit comments