Skip to content

Commit 329e442

Browse files
committed
clang-formatted code for Miller Rabin primality test
1 parent 7261959 commit 329e442

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

src/main/java/com/thealgorithms/randomized/MillerRabinPrimality.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,15 @@ private MillerRabinPrimality() {
4444
*/
4545
public static boolean millerRabin(BigInteger n, int iter) {
4646
if (n.compareTo(ONE) <= 0 || n.equals(FOUR)) return false;
47-
if (n.equals(THREE)||n.equals(TWO)) return true;
47+
if (n.equals(THREE) || n.equals(TWO)) return true;
4848
long deg = 0;
4949
BigInteger oddPart = n.subtract(ONE);
50-
while(oddPart.mod(TWO).equals(ZERO)) {
50+
while (oddPart.mod(TWO).equals(ZERO)) {
5151
oddPart = oddPart.divide(TWO);
5252
deg++;
5353
}
5454

55-
while(iter-- > 0) {
55+
while (iter-- > 0) {
5656
if (checkComposite(n, oddPart, deg)) {
5757
return false;
5858
}

src/test/java/com/thealgorithms/randomized/MillerRabinPrimalityTest.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
11
package com.thealgorithms.randomized;
2-
import static org.junit.jupiter.api.Assertions.assertTrue;
32
import static org.junit.jupiter.api.Assertions.assertFalse;
3+
import static org.junit.jupiter.api.Assertions.assertTrue;
44

55
import java.math.BigInteger;
66
import org.junit.jupiter.api.Test;
77

88
/*
9-
* Tests for MillerRabinPrimality
10-
* @author DomTr (https://github.com/DomTr)
11-
*/
9+
* Tests for MillerRabinPrimality
10+
* @author DomTr (https://github.com/DomTr)
11+
*/
1212

1313
public class MillerRabinPrimalityTest {
1414
static final int iter = 10;
1515

1616
@Test
1717
public void testComposites() {
18-
long[] values = {1, 25, 2932021007403L, 4501680375506332L, 6910906992394051L,
19-
4887521073398877L, 5577943644815725L, 6085993686552764L};
18+
long[] values = {1, 25, 2932021007403L, 4501680375506332L, 6910906992394051L, 4887521073398877L, 5577943644815725L, 6085993686552764L};
2019

2120
for (long v : values) {
2221
BigInteger val = BigInteger.valueOf(v);
@@ -58,7 +57,6 @@ public void testBigComposites() {
5857
BigInteger p3 = new BigInteger("924286031819653");
5958
BigInteger p4 = new BigInteger("408464000499539");
6059

61-
6260
assertFalse(MillerRabinPrimality.millerRabin(p1.multiply(p1), iter));
6361
assertFalse(MillerRabinPrimality.millerRabin(p1.multiply(p2), iter));
6462
assertFalse(MillerRabinPrimality.millerRabin(p1.multiply(p3), iter));

0 commit comments

Comments
 (0)