1
+ package src .main .java .com .Others ;
2
+
3
+ import org .junit .*;
4
+
5
+ import java .math .BigInteger ;
6
+
7
+ import static org .junit .Assert .*;
8
+
9
+ public class FastPowerTest {
10
+
11
+ @ Test
12
+ public void test () {
13
+ System .out .println ("Long Type:" );
14
+ long result ;
15
+ result = FastPower .calculate (2 , 2 , 10 );
16
+ assertEquals (result , 4 );
17
+ System .out .println ("The result of power(2,2) mod 10 is " + result );
18
+
19
+ result = FastPower .calculate (100 , 1000 , 20 );
20
+ assertEquals (result , 0 );
21
+ System .out .println ("The result of power(100, 1000) mod 20 is " + result );
22
+
23
+ result = FastPower .calculate (123456 , 123456789 , 234 );
24
+ System .out .println ("The result of power(123456, 123456789) mod 234 is " + result );
25
+
26
+
27
+ System .out .println ("BigInteger Type:" );
28
+ BigInteger bigResult ;
29
+ bigResult = FastPower .calculate (BigInteger .TEN , BigInteger .TEN , new BigInteger ("4" ));
30
+ assertEquals (bigResult , BigInteger .ZERO );
31
+ System .out .println ("The bigResult of power(10, 10) mod 4 is " + bigResult );
32
+
33
+ bigResult = FastPower .calculate (new BigInteger ("123456" ), new BigInteger ("123456789" ), new BigInteger ("234" ));
34
+ System .out .println ("The bigResult of power(123456, 123456789) mod 234 is " + bigResult );
35
+
36
+ bigResult = FastPower .calculate (new BigInteger ("123456789101112" ), new BigInteger ("12345678910111213" ), new BigInteger ("567890" ));
37
+ System .out .println ("The bigResult of power(123456789101112, 12345678910111213) mod 567890 is " + bigResult );
38
+
39
+ }
40
+ }
0 commit comments