Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitada660a

Browse files
authored
refactor: update FastPower
1 parentcac1b0b commitada660a

File tree

1 file changed

+30
-4
lines changed

1 file changed

+30
-4
lines changed
Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,35 @@
11
packagesrc.test.java.com.others;
22

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.*;
79

810
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+
}
935
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp