@@ -683,5 +683,31 @@ macro_rules! int_module {
683683 assert_eq_const_safe!( $T: <$T>:: unbounded_shr( 17 , SHIFT_AMOUNT_OVERFLOW3 ) , 0 ) ;
684684 }
685685 }
686+
687+ const EXACT_DIV_SUCCESS_DIVIDEND1 : $T = 42 ;
688+ const EXACT_DIV_SUCCESS_DIVISOR1 : $T = 6 ;
689+ const EXACT_DIV_SUCCESS_QUOTIENT1 : $T = 7 ;
690+ const EXACT_DIV_SUCCESS_DIVIDEND2 : $T = 18 ;
691+ const EXACT_DIV_SUCCESS_DIVISOR2 : $T = 3 ;
692+ const EXACT_DIV_SUCCESS_QUOTIENT2 : $T = 6 ;
693+
694+ test_runtime_and_compiletime! {
695+ fn test_exact_div( ) {
696+ // 42 / 6
697+ assert_eq_const_safe!( Option <$T>: <$T>:: checked_exact_div( EXACT_DIV_SUCCESS_DIVIDEND1 , EXACT_DIV_SUCCESS_DIVISOR1 ) , Some ( EXACT_DIV_SUCCESS_QUOTIENT1 ) ) ;
698+ assert_eq_const_safe!( $T: <$T>:: exact_div( EXACT_DIV_SUCCESS_DIVIDEND1 , EXACT_DIV_SUCCESS_DIVISOR1 ) , EXACT_DIV_SUCCESS_QUOTIENT1 ) ;
699+ assert_eq_const_safe!( $T: unsafe { <$T>:: unchecked_exact_div( EXACT_DIV_SUCCESS_DIVIDEND1 , EXACT_DIV_SUCCESS_DIVISOR1 ) } , EXACT_DIV_SUCCESS_QUOTIENT1 ) ;
700+
701+ // 18 / 3
702+ assert_eq_const_safe!( Option <$T>: <$T>:: checked_exact_div( EXACT_DIV_SUCCESS_DIVIDEND2 , EXACT_DIV_SUCCESS_DIVISOR2 ) , Some ( EXACT_DIV_SUCCESS_QUOTIENT2 ) ) ;
703+ assert_eq_const_safe!( $T: <$T>:: exact_div( EXACT_DIV_SUCCESS_DIVIDEND2 , EXACT_DIV_SUCCESS_DIVISOR2 ) , EXACT_DIV_SUCCESS_QUOTIENT2 ) ;
704+ assert_eq_const_safe!( $T: unsafe { <$T>:: unchecked_exact_div( EXACT_DIV_SUCCESS_DIVIDEND2 , EXACT_DIV_SUCCESS_DIVISOR2 ) } , EXACT_DIV_SUCCESS_QUOTIENT2 ) ;
705+
706+ // failures
707+ assert_eq_const_safe!( Option <$T>: <$T>:: checked_exact_div( 1 , 2 ) , None ) ;
708+ assert_eq_const_safe!( Option <$T>: <$T>:: checked_exact_div( <$T>:: MIN , -1 ) , None ) ;
709+ assert_eq_const_safe!( Option <$T>: <$T>:: checked_exact_div( 0 , 0 ) , None ) ;
710+ }
711+ }
686712 } ;
687713}
0 commit comments