|
1 | 1 | packagesrc.test.java.com.others;
|
2 | 2 |
|
3 |
| -/** |
4 |
| - * @author bingo |
5 |
| - * @since 2019/5/10 |
6 |
| - */ |
| 3 | +importorg.junit.Test; |
| 4 | +importsrc.main.java.com.others.FastPower; |
| 5 | + |
| 6 | +importjava.math.BigInteger; |
| 7 | + |
| 8 | +importstaticorg.junit.Assert.*; |
7 | 9 |
|
8 | 10 | publicclassFastPowerTest {
|
| 11 | + |
| 12 | +@Test |
| 13 | +voidtestLong(longn,longk,longm) { |
| 14 | +longresult =FastPower.calculate(n,k,m); |
| 15 | +assertEquals(result,BigInteger.valueOf(n).modPow(BigInteger.valueOf(k),BigInteger.valueOf(m)).longValue()); |
| 16 | + } |
| 17 | + |
| 18 | +@Test |
| 19 | +voidtestBigInteger(BigIntegern,BigIntegerk,BigIntegerm) { |
| 20 | +BigIntegerresult =FastPower.calculate(n,k,m); |
| 21 | +assertEquals(result,n.modPow(k,m)); |
| 22 | + } |
| 23 | + |
| 24 | +@Test |
| 25 | +publicvoidtest() { |
| 26 | +testLong(2,2,10); |
| 27 | +testLong(100,1000,20); |
| 28 | +testLong(123456,123456789,234); |
| 29 | + |
| 30 | +testBigInteger(BigInteger.TEN,BigInteger.TEN,BigInteger.valueOf(4)); |
| 31 | +testBigInteger(newBigInteger("123456"),newBigInteger("123456789"),newBigInteger("234")); |
| 32 | +testBigInteger(newBigInteger("123456789101112"),newBigInteger("12345678910111213"),newBigInteger("567890")); |
| 33 | + |
| 34 | + } |
9 | 35 | }
|