To check if the number is prime, we use the Lucas–Lehmer primality test together with the Miller–Rabin primality test.
If the number is a Mersenne prime, we use the deterministic Lucas–Lehmer primality test. Otherwise, we fall back on using the probabilistic Miller–Rabin primality test.
Minimal requirements:
- Java 1.9+
- Maven 3.3+
To start the application, from the project directory run:
mvn spring-boot:run
This will bootstrap the webapp on http://localhost:8080
.
A rudimentary web interface can be used to interact with the web service.
Alternatively, users can interact with the API directly. Below are a few examples of how the API endpoints work.
- Check if
2
is prime:
curl --request GET "http://127.0.0.1:8080/api/checkprime?input=2"
# {"input":"2", "status":"true"}
- Check if
6
is prime:
curl --request GET "http://127.0.0.1:8080/api/checkprime?input=6"
# {"input":"6", "status":"false"}
- Check if
'wine'
is prime:
curl --request GET "http://127.0.0.1:8080/api/checkprime?input=wine"
# {"input":"wine","status":"input must be a number"}
- Empty argument handling:
curl --request GET "http://127.0.0.1:8080/api/checkprime?input"
# {"input":"null","status":"must not be null"}
To test the web application, run:
mvn test
To generate a coverage report (provided by jacoco), run:
mvn test jacoco:report # creates target/site/jacoco/index.html