Updated libraries and increased test coverage
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
//JavaClasses/src/main/java/mattrixwv/NumberAlgorithms.java
|
||||
//Matthew Ellison
|
||||
// Created: 07-03-21
|
||||
//Modified: 06-25-22
|
||||
//Modified: 04-13-23
|
||||
//This class contains algorithms for numbers that I've found it useful to keep around
|
||||
/*
|
||||
Copyright (C) 2022 Matthew Ellison
|
||||
Copyright (C) 2023 Matthew Ellison
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
@@ -277,7 +277,7 @@ public class NumberAlgorithms{
|
||||
}
|
||||
public static List<BigInteger> getFactors(BigInteger goalNumber) throws InvalidResult{
|
||||
//You need to get all the primes that could be factors of this number so you can test them
|
||||
BigInteger topPossiblePrime = goalNumber.divide(BigInteger.TWO);
|
||||
BigInteger topPossiblePrime = goalNumber.sqrt().add(BigInteger.ONE);
|
||||
List<BigInteger> primes = getPrimes(topPossiblePrime);
|
||||
ArrayList<BigInteger> factors = new ArrayList<>();
|
||||
|
||||
@@ -303,7 +303,12 @@ public class NumberAlgorithms{
|
||||
|
||||
//If for some reason the goalNumber is not 1 throw an error
|
||||
if(!goalNumber.equals(BigInteger.ONE)){
|
||||
throw new InvalidResult("The factor was not 1: " + goalNumber);
|
||||
if(isPrime(goalNumber)){
|
||||
factors.add(goalNumber);
|
||||
}
|
||||
else{
|
||||
throw new InvalidResult("The factor was not 1: " + goalNumber);
|
||||
}
|
||||
}
|
||||
|
||||
//Return the list of factors
|
||||
|
||||
Reference in New Issue
Block a user