refactor: update FastPower
This commit is contained in:
parent
64bd1a147e
commit
fbffeb658c
9
src/test/java/com/others/FastPowerTest.java
Normal file
9
src/test/java/com/others/FastPowerTest.java
Normal file
@ -0,0 +1,9 @@
|
||||
package src.test.java.com.others;
|
||||
|
||||
/**
|
||||
* @author bingo
|
||||
* @since 2019/5/10
|
||||
*/
|
||||
|
||||
public class FastPowerTest {
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
package src.main.java.com.Others;
|
||||
package src.test.java.com.others;
|
||||
|
||||
import org.junit.*;
|
||||
import org.junit.Test;
|
||||
import src.main.java.com.others.FastPower;
|
||||
|
||||
import java.math.BigInteger;
|
||||
|
||||
@ -8,23 +9,25 @@ import static org.junit.Assert.*;
|
||||
|
||||
public class FastPowerTest {
|
||||
|
||||
void testLong(long n, long k, long m){
|
||||
long result = FastPower.calculate(n,k,m);
|
||||
@Test
|
||||
void testLong(long n, long k, long m) {
|
||||
long result = FastPower.calculate(n, k, m);
|
||||
assertEquals(result, BigInteger.valueOf(n).modPow(BigInteger.valueOf(k), BigInteger.valueOf(m)).longValue());
|
||||
}
|
||||
|
||||
void testBigInteger(BigInteger n, BigInteger k, BigInteger m){
|
||||
BigInteger result = FastPower.calculate(n,k,m);
|
||||
assertEquals(result, n.modPow(k,m));
|
||||
@Test
|
||||
void testBigInteger(BigInteger n, BigInteger k, BigInteger m) {
|
||||
BigInteger result = FastPower.calculate(n, k, m);
|
||||
assertEquals(result, n.modPow(k, m));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
testLong(2,2,10);
|
||||
testLong(100,1000,20);
|
||||
testLong(123456,123456789,234);
|
||||
testLong(2, 2, 10);
|
||||
testLong(100, 1000, 20);
|
||||
testLong(123456, 123456789, 234);
|
||||
|
||||
testBigInteger(BigInteger.TEN,BigInteger.TEN, BigInteger.valueOf(4));
|
||||
testBigInteger(BigInteger.TEN, BigInteger.TEN, BigInteger.valueOf(4));
|
||||
testBigInteger(new BigInteger("123456"), new BigInteger("123456789"), new BigInteger("234"));
|
||||
testBigInteger(new BigInteger("123456789101112"), new BigInteger("12345678910111213"), new BigInteger("567890"));
|
||||
|
Loading…
Reference in New Issue
Block a user