diff --git a/src/main/java/mattrixwv/Algorithms.java b/src/main/java/mattrixwv/Algorithms.java index 7826fb7..3c61ba6 100644 --- a/src/main/java/mattrixwv/Algorithms.java +++ b/src/main/java/mattrixwv/Algorithms.java @@ -1,7 +1,7 @@ //src/main/java/mattrixwv/Algorithms.java //Matthew Ellison // Created: 03-02-19 -//Modified: 06-07-20 +//Modified: 06-15-20 //This class holds many algorithms that I have found it useful to keep around //As such all of the functions in here are static and meant to be used as stand alone functions /* @@ -173,7 +173,7 @@ public class Algorithms{ ArrayList primes = new ArrayList(); //Holds the prime numbers boolean foundFactor = false; //A flag for whether a factor of the current number has been found - //If the numebr is 0 or negative return an empty list + //If the number is 0 or negative return an empty list if(numberOfPrimes <= 1){ return primes; } @@ -182,7 +182,7 @@ public class Algorithms{ primes.add(2); } - //We cna now start at 3 and skipp all even numbers, because they cannot be prime + //We can now start at 3 and skip all even numbers, because they cannot be prime for(int possiblePrime = 3;primes.size() < numberOfPrimes;possiblePrime += 2){ //Check all current primes, up to sqrt(possiblePrime), to see if there is a divisor Double topPossibleFactor = Math.ceil(Math.sqrt(possiblePrime)); @@ -195,7 +195,7 @@ public class Algorithms{ else{ ++primesCnt; } - //Check if the index has gone out of range + //Check if the index has gone out of bounds if(primesCnt >= primes.size()){ break; } @@ -218,7 +218,7 @@ public class Algorithms{ ArrayList primes = new ArrayList(); //Holds the prime numbers boolean foundFactor = false; //A flag for whether a factor of the current number has been found - //If the numebr is 0 or negative return an empty list + //If the number is 0 or negative return an empty list if(numberOfPrimes <= 1){ return primes; } @@ -227,7 +227,7 @@ public class Algorithms{ primes.add(2L); } - //We cna now start at 3 and skipp all even numbers, because they cannot be prime + //We can now start at 3 and skip all even numbers, because they cannot be prime for(long possiblePrime = 3L;primes.size() < numberOfPrimes;possiblePrime += 2L){ //Check all current primes, up to sqrt(possiblePrime), to see if there is a divisor Double topPossibleFactor = Math.ceil(Math.sqrt(possiblePrime)); @@ -240,7 +240,7 @@ public class Algorithms{ else{ ++primesCnt; } - //Check if the index has gone out of range + //Check if the index has gone out of bounds if(primesCnt >= primes.size()){ break; } @@ -263,7 +263,7 @@ public class Algorithms{ ArrayList primes = new ArrayList(); //Holds the prime numbers boolean foundFactor = false; //A flag for whether a factor of the current number has been found - //If the numebr is 0 or negative return an empty list + //If the number is 0 or negative return an empty list if(numberOfPrimes.compareTo(BigInteger.valueOf(1)) <= 0){ return primes; } @@ -272,7 +272,7 @@ public class Algorithms{ primes.add(BigInteger.valueOf(2)); } - //We cna now start at 3 and skipp all even numbers, because they cannot be prime + //We can now start at 3 and skip all even numbers, because they cannot be prime for(BigInteger possiblePrime = BigInteger.valueOf(3);numberOfPrimes.compareTo((BigInteger.valueOf(primes.size()))) > 0;possiblePrime = possiblePrime.add(BigInteger.valueOf(2))){ //Check all current primes, up to sqrt(possiblePrime), to see if there is a divisor BigInteger topPossibleFactor = possiblePrime.sqrt().add(BigInteger.valueOf(1)); @@ -285,7 +285,7 @@ public class Algorithms{ else{ ++primesCnt; } - //Check if the index has gone out of range + //Check if the index has gone out of bounds if(primesCnt >= primes.size()){ break; } diff --git a/src/test/java/mattrixwv/TestAlgorithms.java b/src/test/java/mattrixwv/TestAlgorithms.java index cd03b5f..303d5fb 100644 --- a/src/test/java/mattrixwv/TestAlgorithms.java +++ b/src/test/java/mattrixwv/TestAlgorithms.java @@ -70,8 +70,8 @@ public class TestAlgorithms{ //Test 3 ArrayList bigCorrectAnswer = new ArrayList(Arrays.asList(BigInteger.valueOf(2), BigInteger.valueOf(3), BigInteger.valueOf(5), BigInteger.valueOf(7), BigInteger.valueOf(11), BigInteger.valueOf(13), BigInteger.valueOf(17), BigInteger.valueOf(19), BigInteger.valueOf(23), BigInteger.valueOf(29), BigInteger.valueOf(31), BigInteger.valueOf(37), BigInteger.valueOf(41), BigInteger.valueOf(43), BigInteger.valueOf(47), BigInteger.valueOf(53), BigInteger.valueOf(59), BigInteger.valueOf(61), BigInteger.valueOf(67), BigInteger.valueOf(71), BigInteger.valueOf(73), BigInteger.valueOf(79), BigInteger.valueOf(83), BigInteger.valueOf(89), BigInteger.valueOf(97))); - BigInteger bigTopNum = BigInteger.valueOf(25); - ArrayList bigAnswer = Algorithms.getNumPrimes(bigTopNum); + BigInteger bigNumPrimes = BigInteger.valueOf(25); + ArrayList bigAnswer = Algorithms.getNumPrimes(bigNumPrimes); assertEquals("getNumPrimes BigInteger failed", bigCorrectAnswer, bigAnswer); } @Test