-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
split into web and core packages, fleshed out functionality and tests
Signed-off-by: Konstantin Läufer <[email protected]>
- Loading branch information
Showing
7 changed files
with
99 additions
and
27 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
src/main/java/edu/luc/cs/cs371/primechecker/core/PrimeChecker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package edu.luc.cs.cs371.primechecker.core; | ||
|
||
import java.math.BigInteger; | ||
|
||
public enum PrimeChecker {; | ||
|
||
public static boolean isPrimeSlow(final BigInteger i) { | ||
final var compareToTwo = i.compareTo(BigInteger.TWO); | ||
if (compareToTwo < 0) { | ||
return false; | ||
} | ||
if (compareToTwo == 0) { | ||
return true; | ||
} | ||
if (!i.testBit(0)) { | ||
return false; | ||
} | ||
final var sqroot = i.sqrt(); | ||
var k = BigInteger.valueOf(3); | ||
while (k.compareTo(sqroot) <= 0) { | ||
if (i.mod(k).equals(BigInteger.ZERO)) { | ||
return false; | ||
} | ||
k = k.add(BigInteger.TWO); | ||
} | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
src/test/java/edu/luc/cs/cs371/primechecker/core/PrimeCheckerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package edu.luc.cs.cs371.primechecker.core; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
|
||
import java.math.BigInteger; | ||
|
||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.ValueSource; | ||
|
||
public class PrimeCheckerTest { | ||
|
||
@ParameterizedTest | ||
@ValueSource(ints = {-7, -1, 0, 1, 4, 6, 8, 9, 6008, 6033}) | ||
void isPrime_ShouldReturnFalse(int number) { | ||
assertFalse(PrimeChecker.isPrimeSlow(BigInteger.valueOf(number))); | ||
} | ||
|
||
@ParameterizedTest | ||
@ValueSource(ints = {2, 3, 5, 7, 17, 6007}) | ||
void isPrime_ShouldReturnTrue(int number) { | ||
assertTrue(PrimeChecker.isPrimeSlow(BigInteger.valueOf(number))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...primechecker/HttpResponseMessageMock.java → ...echecker/web/HttpResponseMessageMock.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters