@@ -20,7 +20,7 @@ use std::hash::{BuildHasher, Hasher, Hash};
20
20
use std:: collections:: hash_map:: RandomState ;
21
21
22
22
use num_integer:: Integer ;
23
- use num_traits:: { Zero , One , Signed , ToPrimitive , FromPrimitive , Num , Float } ;
23
+ use num_traits:: { Zero , One , Signed , ToPrimitive , FromPrimitive , Num , Float , Pow } ;
24
24
25
25
mod consts;
26
26
use consts:: * ;
@@ -1092,3 +1092,30 @@ fn test_iter_product_generic() {
1092
1092
assert_eq ! ( result, data. iter( ) . product( ) ) ;
1093
1093
assert_eq ! ( result, data. into_iter( ) . product( ) ) ;
1094
1094
}
1095
+
1096
+ #[ test]
1097
+ fn test_pow ( ) {
1098
+ let one = BigInt :: from ( 1i32 ) ;
1099
+ let two = BigInt :: from ( 2i32 ) ;
1100
+ let four = BigInt :: from ( 4i32 ) ;
1101
+ let eight = BigInt :: from ( 8i32 ) ;
1102
+ let minus_two = BigInt :: from ( -2i32 ) ;
1103
+ macro_rules! check {
1104
+ ( $t: ty) => {
1105
+ assert_eq!( two. pow( 0 as $t) , one) ;
1106
+ assert_eq!( two. pow( 1 as $t) , two) ;
1107
+ assert_eq!( two. pow( 2 as $t) , four) ;
1108
+ assert_eq!( two. pow( 3 as $t) , eight) ;
1109
+ assert_eq!( two. pow( & ( 3 as $t) ) , eight) ;
1110
+ assert_eq!( minus_two. pow( 0 as $t) , one, "-2^0" ) ;
1111
+ assert_eq!( minus_two. pow( 1 as $t) , minus_two, "-2^1" ) ;
1112
+ assert_eq!( minus_two. pow( 2 as $t) , four, "-2^2" ) ;
1113
+ assert_eq!( minus_two. pow( 3 as $t) , -& eight, "-2^3" ) ;
1114
+ }
1115
+ }
1116
+ check ! ( u8 ) ;
1117
+ check ! ( u16 ) ;
1118
+ check ! ( u32 ) ;
1119
+ check ! ( u64 ) ;
1120
+ check ! ( usize ) ;
1121
+ }
0 commit comments