mirror of
https://bitbucket.org/Mattrixwv/javaclasses.git
synced 2025-12-06 23:13:57 -05:00
Upgraded to junit 5
This commit is contained in:
@@ -34,10 +34,8 @@ import mattrixwv.exceptions.InvalidResult;
|
||||
|
||||
public class NumberAlgorithms{
|
||||
private NumberAlgorithms(){}
|
||||
//?This is here just to prove that templates exist and for a possible rewrite at a later time
|
||||
public static <T> T getNum(T num1){
|
||||
return num1;
|
||||
}
|
||||
|
||||
public static final String FACTORIAL_NEGATIVE_MESSAGE = "n! cannot be negative";
|
||||
|
||||
//This function returns a list with all the prime numbers <= goalNumber
|
||||
public static List<Integer> getPrimes(int goalNumber){
|
||||
@@ -130,7 +128,7 @@ public class NumberAlgorithms{
|
||||
boolean foundFactor = false; //A flag for whether a factor of the current number has been found
|
||||
|
||||
//If the number is 0 or negative return an empty list
|
||||
if(numberOfPrimes <= 1){
|
||||
if(numberOfPrimes < 1){
|
||||
return primes;
|
||||
}
|
||||
//Otherwise the number is at least 2, so 2 should be added to the list
|
||||
@@ -168,7 +166,7 @@ public class NumberAlgorithms{
|
||||
boolean foundFactor = false; //A flag for whether a factor of the current number has been found
|
||||
|
||||
//If the number is 0 or negative return an empty list
|
||||
if(numberOfPrimes.compareTo(BigInteger.valueOf(1)) <= 0){
|
||||
if(numberOfPrimes.compareTo(BigInteger.valueOf(1)) < 0){
|
||||
return primes;
|
||||
}
|
||||
//Otherwise the number is at least 2, so 2 should be added to the list
|
||||
@@ -468,7 +466,7 @@ public class NumberAlgorithms{
|
||||
|
||||
//If the number passed in is < 0 throw an exception
|
||||
if(num < 0){
|
||||
throw new InvalidParameterException("n! cannot be negative");
|
||||
throw new InvalidParameterException(FACTORIAL_NEGATIVE_MESSAGE);
|
||||
}
|
||||
//Loop through every number up to and including num and add the product to the factorial
|
||||
for(long cnt = 2L;cnt <= num;++cnt){
|
||||
@@ -482,7 +480,7 @@ public class NumberAlgorithms{
|
||||
|
||||
//If the number passed in is < 0 throw an exception
|
||||
if(num.compareTo(BigInteger.ZERO) < 0){
|
||||
throw new InvalidParameterException("n! cannot be negative");
|
||||
throw new InvalidParameterException(FACTORIAL_NEGATIVE_MESSAGE);
|
||||
}
|
||||
//Loop through every number up to and including num and add the product to the factorial
|
||||
for(BigInteger cnt = BigInteger.TWO;cnt.compareTo(num) <= 0;cnt = cnt.add(BigInteger.ONE)){
|
||||
|
||||
Reference in New Issue
Block a user