mirror of
https://bitbucket.org/Mattrixwv/javaclasses.git
synced 2025-12-06 15:03:58 -05:00
Upgraded to junit 5
This commit is contained in:
15
pom.xml
15
pom.xml
@@ -19,9 +19,9 @@
|
|||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>org.junit.jupiter</groupId>
|
||||||
<artifactId>junit</artifactId>
|
<artifactId>junit-jupiter-api</artifactId>
|
||||||
<version>4.13.2</version>
|
<version>5.8.2</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
@@ -88,6 +88,15 @@
|
|||||||
<artifactId>maven-project-info-reports-plugin</artifactId>
|
<artifactId>maven-project-info-reports-plugin</artifactId>
|
||||||
<version>3.1.1</version>
|
<version>3.1.1</version>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
<!--Versions-->
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.codehaus.mojo</groupId>
|
||||||
|
<artifactId>versions-maven-plugin</artifactId>
|
||||||
|
<version>2.5</version>
|
||||||
|
<configuration>
|
||||||
|
<rulesUri>file://${session.executionRootDirectory}/version-rules.xml</rulesUri>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
<!--Sonar-->
|
<!--Sonar-->
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.sonarsource.scanner.maven</groupId>
|
<groupId>org.sonarsource.scanner.maven</groupId>
|
||||||
|
|||||||
@@ -34,10 +34,8 @@ import mattrixwv.exceptions.InvalidResult;
|
|||||||
|
|
||||||
public class NumberAlgorithms{
|
public class NumberAlgorithms{
|
||||||
private 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){
|
public static final String FACTORIAL_NEGATIVE_MESSAGE = "n! cannot be negative";
|
||||||
return num1;
|
|
||||||
}
|
|
||||||
|
|
||||||
//This function returns a list with all the prime numbers <= goalNumber
|
//This function returns a list with all the prime numbers <= goalNumber
|
||||||
public static List<Integer> getPrimes(int 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
|
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 the number is 0 or negative return an empty list
|
||||||
if(numberOfPrimes <= 1){
|
if(numberOfPrimes < 1){
|
||||||
return primes;
|
return primes;
|
||||||
}
|
}
|
||||||
//Otherwise the number is at least 2, so 2 should be added to the list
|
//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
|
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 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;
|
return primes;
|
||||||
}
|
}
|
||||||
//Otherwise the number is at least 2, so 2 should be added to the list
|
//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 the number passed in is < 0 throw an exception
|
||||||
if(num < 0){
|
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
|
//Loop through every number up to and including num and add the product to the factorial
|
||||||
for(long cnt = 2L;cnt <= num;++cnt){
|
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 the number passed in is < 0 throw an exception
|
||||||
if(num.compareTo(BigInteger.ZERO) < 0){
|
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
|
//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)){
|
for(BigInteger cnt = BigInteger.TWO;cnt.compareTo(num) <= 0;cnt = cnt.add(BigInteger.ONE)){
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
//JavaClasses/src/test/java/mattrixwv/TestArrayAlgorithms.java
|
//JavaClasses/src/test/java/mattrixwv/TestArrayAlgorithms.java
|
||||||
//Matthew Ellison
|
//Matthew Ellison
|
||||||
// Created: 07-03-21
|
// Created: 07-03-21
|
||||||
//Modified: 07-03-21
|
//Modified: 06-26-22
|
||||||
//This class contains tests for my array algorithms
|
//This class contains tests for my array algorithms
|
||||||
/*
|
/*
|
||||||
Copyright (C) 2021 Matthew Ellison
|
Copyright (C) 2022 Matthew Ellison
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
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
|
it under the terms of the GNU Lesser General Public License as published by
|
||||||
@@ -22,93 +22,121 @@
|
|||||||
package mattrixwv;
|
package mattrixwv;
|
||||||
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
|
||||||
public class TestArrayAlgorithms{
|
public class TestArrayAlgorithms{
|
||||||
@Test
|
@Test
|
||||||
public void testGetSum(){
|
public void testGetSum(){
|
||||||
//Test 1
|
//Test 1
|
||||||
Integer correctAnswer = 0;
|
int correctAnswer = 0;
|
||||||
ArrayList<Integer> numbers = new ArrayList<Integer>();
|
List<Integer> numbers = new ArrayList<>();
|
||||||
Integer answer = ArrayAlgorithms.getSum(numbers);
|
int answer = ArrayAlgorithms.getSum(numbers);
|
||||||
assertEquals("getSum Integer 1 failed", correctAnswer, answer);
|
assertEquals(correctAnswer, answer, "getSum int 1 failed");
|
||||||
//Test 2
|
//Test 2
|
||||||
correctAnswer = 118;
|
correctAnswer = 118;
|
||||||
numbers = new ArrayList<Integer>(Arrays.asList(2, 2, 3, 3, 4, 4, 100));
|
numbers = Arrays.asList(2, 2, 3, 3, 4, 4, 100);
|
||||||
answer = ArrayAlgorithms.getSum(numbers);
|
answer = ArrayAlgorithms.getSum(numbers);
|
||||||
assertEquals("getSum Integer 2 failed", correctAnswer, answer);
|
assertEquals(correctAnswer, answer, "getSum int 2 failed");
|
||||||
|
|
||||||
//Test 3
|
//Test 3
|
||||||
Long longCorrectAnswer = 118L;
|
long longCorrectAnswer = 0;
|
||||||
ArrayList<Long> longNumbers = new ArrayList<Long>(Arrays.asList(2L, 2L, 3L, 3L, 4L, 4L, 100L));
|
List<Long> longNumbers = new ArrayList<>();
|
||||||
Long longAnswer = ArrayAlgorithms.getLongSum(longNumbers);
|
long longAnswer = ArrayAlgorithms.getLongSum(longNumbers);
|
||||||
assertEquals("getSum Long failed", longCorrectAnswer, longAnswer);
|
assertEquals(longCorrectAnswer, longAnswer, "getSum long 1 failed");
|
||||||
|
|
||||||
//Test 4
|
//Test 4
|
||||||
BigInteger bigCorrectAnswer = BigInteger.valueOf(118);
|
longCorrectAnswer = 118;
|
||||||
ArrayList<BigInteger> bigNumbers = new ArrayList<BigInteger>(Arrays.asList(BigInteger.valueOf(2), BigInteger.valueOf(2), BigInteger.valueOf(3), BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(4), BigInteger.valueOf(100)));
|
longNumbers = Arrays.asList(2L, 2L, 3L, 3L, 4L, 4L, 100L);
|
||||||
|
longAnswer = ArrayAlgorithms.getLongSum(longNumbers);
|
||||||
|
assertEquals(longCorrectAnswer, longAnswer, "getSum long 2 failed");
|
||||||
|
|
||||||
|
//Test 5
|
||||||
|
BigInteger bigCorrectAnswer = BigInteger.ZERO;
|
||||||
|
List<BigInteger> bigNumbers = new ArrayList<>();
|
||||||
BigInteger bigAnswer = ArrayAlgorithms.getBigSum(bigNumbers);
|
BigInteger bigAnswer = ArrayAlgorithms.getBigSum(bigNumbers);
|
||||||
assertEquals("getSum BigInteger failed", bigCorrectAnswer, bigAnswer);
|
assertEquals(bigCorrectAnswer, bigAnswer, "getSum BigInteger 1 failed");
|
||||||
|
//Test 6
|
||||||
|
bigCorrectAnswer = BigInteger.valueOf(118);
|
||||||
|
bigNumbers = Arrays.asList(BigInteger.valueOf(2), BigInteger.valueOf(2), BigInteger.valueOf(3), BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(4), BigInteger.valueOf(100));
|
||||||
|
bigAnswer = ArrayAlgorithms.getBigSum(bigNumbers);
|
||||||
|
assertEquals(bigCorrectAnswer, bigAnswer, "getSum BigInteger 2 failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetProd(){
|
public void testGetProd(){
|
||||||
//Test 1
|
//Test 1
|
||||||
Integer correctAnswer = 0;
|
int correctAnswer = 0;
|
||||||
ArrayList<Integer> numbers = new ArrayList<Integer>();
|
List<Integer> numbers = new ArrayList<>();
|
||||||
Integer answer = ArrayAlgorithms.getProd(numbers);
|
int answer = ArrayAlgorithms.getProd(numbers);
|
||||||
assertEquals("getProd Integer 1 failed", correctAnswer, answer);
|
assertEquals(correctAnswer, answer, "getProd int 1 failed");
|
||||||
//Test 2
|
//Test 2
|
||||||
correctAnswer = 57600;
|
correctAnswer = 57600;
|
||||||
numbers = new ArrayList<Integer>(Arrays.asList(2, 2, 3, 3, 4, 4, 100));
|
numbers = Arrays.asList(2, 2, 3, 3, 4, 4, 100);
|
||||||
answer = ArrayAlgorithms.getProd(numbers);
|
answer = ArrayAlgorithms.getProd(numbers);
|
||||||
assertEquals("getProd Integer 2 failed", correctAnswer, answer);
|
assertEquals(correctAnswer, answer, "getProd int 2 failed");
|
||||||
|
|
||||||
//Test 3
|
//Test 3
|
||||||
Long longCorrectAnswer = 57600L;
|
long longCorrectAnswer = 0;
|
||||||
ArrayList<Long> longNumbers = new ArrayList<Long>(Arrays.asList(2L, 2L, 3L, 3L, 4L, 4L, 100L));
|
List<Long> longNumbers = new ArrayList<>();
|
||||||
Long longAnswer = ArrayAlgorithms.getLongProd(longNumbers);
|
long longAnswer = ArrayAlgorithms.getLongProd(longNumbers);
|
||||||
assertEquals("getProd Long failed", longCorrectAnswer, longAnswer);
|
assertEquals(longCorrectAnswer, longAnswer, "getProd long 1 failed");
|
||||||
|
|
||||||
//Test 4
|
//Test 4
|
||||||
BigInteger bigCorrectAnswer = BigInteger.valueOf(57600);
|
longCorrectAnswer = 57600L;
|
||||||
ArrayList<BigInteger> bigNumbers = new ArrayList<BigInteger>(Arrays.asList(BigInteger.valueOf(2), BigInteger.valueOf(2), BigInteger.valueOf(3), BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(4), BigInteger.valueOf(100)));
|
longNumbers = Arrays.asList(2L, 2L, 3L, 3L, 4L, 4L, 100L);
|
||||||
|
longAnswer = ArrayAlgorithms.getLongProd(longNumbers);
|
||||||
|
assertEquals(longCorrectAnswer, longAnswer, "getProd long 2 failed");
|
||||||
|
|
||||||
|
//Test 5
|
||||||
|
BigInteger bigCorrectAnswer = BigInteger.ZERO;
|
||||||
|
List<BigInteger> bigNumbers = new ArrayList<BigInteger>();
|
||||||
BigInteger bigAnswer = ArrayAlgorithms.getBigProd(bigNumbers);
|
BigInteger bigAnswer = ArrayAlgorithms.getBigProd(bigNumbers);
|
||||||
assertEquals("getProd BigInteger failed", bigCorrectAnswer, bigAnswer);
|
assertEquals(bigCorrectAnswer, bigAnswer, "getProd BigInteger 1 failed");
|
||||||
|
//Test 6
|
||||||
|
bigCorrectAnswer = BigInteger.valueOf(57600);
|
||||||
|
bigNumbers = Arrays.asList(BigInteger.valueOf(2), BigInteger.valueOf(2), BigInteger.valueOf(3), BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(4), BigInteger.valueOf(100));
|
||||||
|
bigAnswer = ArrayAlgorithms.getBigProd(bigNumbers);
|
||||||
|
assertEquals(bigCorrectAnswer, bigAnswer, "getProd BigInteger 2 failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPrintList(){
|
public void testPrintList(){
|
||||||
//Test 1
|
//Test 1
|
||||||
ArrayList<Integer> nums = new ArrayList<Integer>();
|
List<Integer> nums = new ArrayList<Integer>();
|
||||||
String correctAnswer = "[]";
|
String correctAnswer = "[]";
|
||||||
String answer = ArrayAlgorithms.printList(nums);
|
String answer = ArrayAlgorithms.printList(nums);
|
||||||
assertEquals("printList<Integer> 1 failed", correctAnswer, answer);
|
assertEquals(correctAnswer, answer, "printList<Integer> 1 failed");
|
||||||
//Test 2
|
//Test 2
|
||||||
nums = new ArrayList<Integer>(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10));
|
nums = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
|
||||||
correctAnswer = "[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]";
|
correctAnswer = "[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]";
|
||||||
answer = ArrayAlgorithms.printList(nums);
|
answer = ArrayAlgorithms.printList(nums);
|
||||||
assertEquals("printList<Integer> 2 failed", correctAnswer, answer);
|
assertEquals(correctAnswer, answer, "printList<Integer> 2 failed");
|
||||||
//Test 3
|
//Test 3
|
||||||
nums = new ArrayList<Integer>(Arrays.asList(-3, -2, -1, 0, 1, 2, 3));
|
nums = Arrays.asList(-3, -2, -1, 0, 1, 2, 3);
|
||||||
correctAnswer = "[-3, -2, -1, 0, 1, 2, 3]";
|
correctAnswer = "[-3, -2, -1, 0, 1, 2, 3]";
|
||||||
answer = ArrayAlgorithms.printList(nums);
|
answer = ArrayAlgorithms.printList(nums);
|
||||||
assertEquals("printList<Integer> 3 failed", correctAnswer, answer);
|
assertEquals(correctAnswer, answer, "printList<Integer> 3 failed");
|
||||||
|
|
||||||
//Test 4
|
//Test 4
|
||||||
ArrayList<String> strings = new ArrayList<String>(Arrays.asList("A", "B", "C"));
|
List<String> strings = new ArrayList<String>();
|
||||||
|
correctAnswer = "[]";
|
||||||
|
answer = ArrayAlgorithms.printList(strings);
|
||||||
|
assertEquals(correctAnswer, answer, "printList<String> 1 failed");
|
||||||
|
//Test 5
|
||||||
|
strings = Arrays.asList("A", "B", "C");
|
||||||
correctAnswer = "[A, B, C]";
|
correctAnswer = "[A, B, C]";
|
||||||
answer = ArrayAlgorithms.printList(strings);
|
answer = ArrayAlgorithms.printList(strings);
|
||||||
assertEquals("printList<String> 1 failed", correctAnswer, answer);
|
assertEquals(correctAnswer, answer, "printList<String> 2 failed");
|
||||||
//Test 5
|
//Test 6
|
||||||
strings = new ArrayList<String>(Arrays.asList("abc", "def", "ghi"));
|
strings = new ArrayList<String>(Arrays.asList("abc", "def", "ghi"));
|
||||||
correctAnswer = "[abc, def, ghi]";
|
correctAnswer = "[abc, def, ghi]";
|
||||||
answer = ArrayAlgorithms.printList(strings);
|
answer = ArrayAlgorithms.printList(strings);
|
||||||
assertEquals("printList<String> 2 failed", correctAnswer, answer);
|
assertEquals(correctAnswer, answer, "printList<String> 3 failed");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
//JavaClasses/src/test/java/mattrixwv/TestNumberAlgorithms.java
|
//JavaClasses/src/test/java/mattrixwv/TestNumberAlgorithms.java
|
||||||
//Matthew Ellison
|
//Matthew Ellison
|
||||||
// Created: 07-03-21
|
// Created: 07-03-21
|
||||||
//Modified: 06-25-22
|
//Modified: 06-26-22
|
||||||
//This class contains tests for my number algorithms
|
//This class contains tests for my number algorithms
|
||||||
/*
|
/*
|
||||||
Copyright (C) 2022 Matthew Ellison
|
Copyright (C) 2022 Matthew Ellison
|
||||||
@@ -22,13 +22,16 @@
|
|||||||
package mattrixwv;
|
package mattrixwv;
|
||||||
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
|
import java.security.InvalidParameterException;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import mattrixwv.exceptions.InvalidResult;
|
import mattrixwv.exceptions.InvalidResult;
|
||||||
|
|
||||||
@@ -37,109 +40,169 @@ public class TestNumberAlgorithms{
|
|||||||
@Test
|
@Test
|
||||||
public void testGetPrimes(){
|
public void testGetPrimes(){
|
||||||
//Test 1
|
//Test 1
|
||||||
List<Integer> correctAnswer = Arrays.asList(2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97);
|
List<Integer> correctAnswer = new ArrayList<>();
|
||||||
int topNum = 100;
|
int topNum = 1;
|
||||||
List<Integer> answer = NumberAlgorithms.getPrimes(topNum);
|
List<Integer> answer = NumberAlgorithms.getPrimes(topNum);
|
||||||
assertEquals("getPrimes Integer failed", correctAnswer, answer);
|
assertEquals(correctAnswer, answer, "getPrimes int 1 failed");
|
||||||
|
|
||||||
//Test 2
|
//Test 2
|
||||||
List<Long> longCorrectAnswer = Arrays.asList(2L, 3L, 5L, 7L, 11L, 13L, 17L, 19L, 23L, 29L, 31L, 37L, 41L, 43L, 47L, 53L, 59L, 61L, 67L, 71L, 73L, 79L, 83L, 89L, 97L);
|
correctAnswer = Arrays.asList(2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97);
|
||||||
long longTopNum = 100L;
|
topNum = 100;
|
||||||
List<Long> longAnswer = NumberAlgorithms.getPrimes(longTopNum);
|
answer = NumberAlgorithms.getPrimes(topNum);
|
||||||
assertEquals("getPrimes Long failed", longCorrectAnswer, longAnswer);
|
assertEquals(correctAnswer, answer, "getPrimes int 2 failed");
|
||||||
|
|
||||||
//Test 3
|
//Test 3
|
||||||
List<BigInteger> bigCorrectAnswer = 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));
|
List<Long> longCorrectAnswer = new ArrayList<>();
|
||||||
BigInteger bigTopNum = BigInteger.valueOf(100);
|
long longTopNum = 0;
|
||||||
|
List<Long> longAnswer = NumberAlgorithms.getPrimes(longTopNum);
|
||||||
|
assertEquals(longCorrectAnswer, longAnswer, "getPrimes long 1 failed");
|
||||||
|
//Test 4
|
||||||
|
longCorrectAnswer = Arrays.asList(2L, 3L, 5L, 7L, 11L, 13L, 17L, 19L, 23L, 29L, 31L, 37L, 41L, 43L, 47L, 53L, 59L, 61L, 67L, 71L, 73L, 79L, 83L, 89L, 97L);
|
||||||
|
longTopNum = 100;
|
||||||
|
longAnswer = NumberAlgorithms.getPrimes(longTopNum);
|
||||||
|
assertEquals(longCorrectAnswer, longAnswer, "getPrimes long 2 failed");
|
||||||
|
|
||||||
|
//Test 5
|
||||||
|
List<BigInteger> bigCorrectAnswer = new ArrayList<>();
|
||||||
|
BigInteger bigTopNum = BigInteger.ZERO;
|
||||||
List<BigInteger> bigAnswer = NumberAlgorithms.getPrimes(bigTopNum);
|
List<BigInteger> bigAnswer = NumberAlgorithms.getPrimes(bigTopNum);
|
||||||
assertEquals("getPrimes BigInteger failed", bigCorrectAnswer, bigAnswer);
|
assertEquals(bigCorrectAnswer, bigAnswer, "getPrimes BigInteger 1 failed");
|
||||||
|
//Test 6
|
||||||
|
bigCorrectAnswer = 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));
|
||||||
|
bigTopNum = BigInteger.valueOf(100);
|
||||||
|
bigAnswer = NumberAlgorithms.getPrimes(bigTopNum);
|
||||||
|
assertEquals(bigCorrectAnswer, bigAnswer, "getPrimes BigInteger 2 failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetNumPrimes(){
|
public void testGetNumPrimes(){
|
||||||
//Test 1
|
//Test 1
|
||||||
List<Integer> correctAnswer = Arrays.asList(2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97);
|
List<Integer> correctAnswer = new ArrayList<>();
|
||||||
int numPrimes = 25;
|
int numPrimes = 0;
|
||||||
List<Integer> answer = NumberAlgorithms.getNumPrimes(numPrimes);
|
List<Integer> answer = NumberAlgorithms.getNumPrimes(numPrimes);
|
||||||
assertEquals("getNumPrimes Integer failed", correctAnswer, answer);
|
assertEquals(correctAnswer, answer, "getNumPrimes int 1 failed");
|
||||||
|
|
||||||
//Test 2
|
//Test 2
|
||||||
List<Long> longCorrectAnswer = Arrays.asList(2L, 3L, 5L, 7L, 11L, 13L, 17L, 19L, 23L, 29L, 31L, 37L, 41L, 43L, 47L, 53L, 59L, 61L, 67L, 71L, 73L, 79L, 83L, 89L, 97L);
|
correctAnswer = Arrays.asList(2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97);
|
||||||
long longNumPrimes = 25L;
|
numPrimes = 25;
|
||||||
List<Long> longAnswer = NumberAlgorithms.getNumPrimes(longNumPrimes);
|
answer = NumberAlgorithms.getNumPrimes(numPrimes);
|
||||||
assertEquals("getNumPrimes Long failed", longCorrectAnswer, longAnswer);
|
assertEquals(correctAnswer, answer, "getNumPrimes int 2 failed");
|
||||||
|
|
||||||
//Test 3
|
//Test 3
|
||||||
List<BigInteger> bigCorrectAnswer = 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));
|
List<Long> longCorrectAnswer = new ArrayList<>();
|
||||||
BigInteger bigNumPrimes = BigInteger.valueOf(25);
|
long longNumPrimes = 0;
|
||||||
|
List<Long> longAnswer = NumberAlgorithms.getNumPrimes(longNumPrimes);
|
||||||
|
assertEquals(longCorrectAnswer, longAnswer, "getNumPrimes long 1 failed");
|
||||||
|
//Test 4
|
||||||
|
longCorrectAnswer = Arrays.asList(2L, 3L, 5L, 7L, 11L, 13L, 17L, 19L, 23L, 29L, 31L, 37L, 41L, 43L, 47L, 53L, 59L, 61L, 67L, 71L, 73L, 79L, 83L, 89L, 97L);
|
||||||
|
longNumPrimes = 25;
|
||||||
|
longAnswer = NumberAlgorithms.getNumPrimes(longNumPrimes);
|
||||||
|
assertEquals(longCorrectAnswer, longAnswer, "getNumPrimes long 2 failed");
|
||||||
|
|
||||||
|
//Test 5
|
||||||
|
List<BigInteger> bigCorrectAnswer = new ArrayList<>();
|
||||||
|
BigInteger bigNumPrimes = BigInteger.ZERO;
|
||||||
List<BigInteger> bigAnswer = NumberAlgorithms.getNumPrimes(bigNumPrimes);
|
List<BigInteger> bigAnswer = NumberAlgorithms.getNumPrimes(bigNumPrimes);
|
||||||
assertEquals("getNumPrimes BigInteger failed", bigCorrectAnswer, bigAnswer);
|
assertEquals(bigCorrectAnswer, bigAnswer, "getNumPrimes BigInteger 1 failed");
|
||||||
|
//Test 6
|
||||||
|
bigCorrectAnswer = 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));
|
||||||
|
bigNumPrimes = BigInteger.valueOf(25);
|
||||||
|
bigAnswer = NumberAlgorithms.getNumPrimes(bigNumPrimes);
|
||||||
|
assertEquals(bigCorrectAnswer, bigAnswer, "getNumPrimes BigInteger 2 failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsPrime(){
|
public void testIsPrime(){
|
||||||
//Test 1
|
//Test 1
|
||||||
int num = 2;
|
int num = 4;
|
||||||
boolean correctAnswer = true;
|
boolean correctAnswer = false;
|
||||||
boolean answer = NumberAlgorithms.isPrime(num);
|
boolean answer = NumberAlgorithms.isPrime(num);
|
||||||
assertEquals("isPrime Integer 1 failed", correctAnswer, answer);
|
assertEquals(correctAnswer, answer, "isPrime int 1 failed");
|
||||||
//Test 2
|
//Test 2
|
||||||
|
num = 9;
|
||||||
|
correctAnswer = false;
|
||||||
|
answer = NumberAlgorithms.isPrime(num);
|
||||||
|
assertEquals(correctAnswer, answer, "isPrime int 2 failed");
|
||||||
|
//Test 3
|
||||||
|
num = 15;
|
||||||
|
correctAnswer = false;
|
||||||
|
answer = NumberAlgorithms.isPrime(num);
|
||||||
|
assertEquals(correctAnswer, answer, "isPrime int 3 failed");
|
||||||
|
//Test 4
|
||||||
num = 97;
|
num = 97;
|
||||||
correctAnswer = true;
|
correctAnswer = true;
|
||||||
answer = NumberAlgorithms.isPrime(num);
|
answer = NumberAlgorithms.isPrime(num);
|
||||||
assertEquals("isPrime Integer 2 failed", correctAnswer, answer);
|
assertEquals(correctAnswer, answer, "isPrime int 4 failed");
|
||||||
//Test 3
|
//Test 5
|
||||||
num = 1000;
|
num = 1000;
|
||||||
correctAnswer = false;
|
correctAnswer = false;
|
||||||
answer = NumberAlgorithms.isPrime(num);
|
answer = NumberAlgorithms.isPrime(num);
|
||||||
assertEquals("isPrime Integer 3 failed", correctAnswer, answer);
|
assertEquals(correctAnswer, answer, "isPrime int 5 failed");
|
||||||
//Test 4
|
//Test 6
|
||||||
num = 1;
|
num = 1;
|
||||||
correctAnswer = false;
|
correctAnswer = false;
|
||||||
answer = NumberAlgorithms.isPrime(num);
|
answer = NumberAlgorithms.isPrime(num);
|
||||||
assertEquals("isPrime Integer 4 failed", correctAnswer, answer);
|
assertEquals(correctAnswer, answer, "isPrime int 6 failed");
|
||||||
|
|
||||||
//Test 5
|
//Test 7
|
||||||
long longNum = 2;
|
long longNum = 4;
|
||||||
correctAnswer = true;
|
correctAnswer = false;
|
||||||
answer = NumberAlgorithms.isPrime(longNum);
|
answer = NumberAlgorithms.isPrime(longNum);
|
||||||
assertEquals("isPrime Long 1 failed", correctAnswer, answer);
|
assertEquals(correctAnswer, answer, "isPrime long 1 failed");
|
||||||
//Test 6
|
//Test 8
|
||||||
|
longNum = 9;
|
||||||
|
correctAnswer = false;
|
||||||
|
answer = NumberAlgorithms.isPrime(longNum);
|
||||||
|
assertEquals(correctAnswer, answer, "isPrime long 2 failed");
|
||||||
|
//Test 9
|
||||||
|
longNum = 15;
|
||||||
|
correctAnswer = false;
|
||||||
|
answer = NumberAlgorithms.isPrime(longNum);
|
||||||
|
assertEquals(correctAnswer, answer, "isPrime long 3 failed");
|
||||||
|
//Test 10
|
||||||
longNum = 97;
|
longNum = 97;
|
||||||
correctAnswer = true;
|
correctAnswer = true;
|
||||||
answer = NumberAlgorithms.isPrime(longNum);
|
answer = NumberAlgorithms.isPrime(longNum);
|
||||||
assertEquals("isPrime Long 2 failed", correctAnswer, answer);
|
assertEquals(correctAnswer, answer, "isPrime long 4 failed");
|
||||||
//Test 7
|
//Test 11
|
||||||
longNum = 1000;
|
longNum = 1000;
|
||||||
correctAnswer = false;
|
correctAnswer = false;
|
||||||
answer = NumberAlgorithms.isPrime(longNum);
|
answer = NumberAlgorithms.isPrime(longNum);
|
||||||
assertEquals("isPrime Long 3 failed", correctAnswer, answer);
|
assertEquals(correctAnswer, answer, "isPrime long 5 failed");
|
||||||
//Test 8
|
//Test 12
|
||||||
longNum = 1;
|
longNum = 1;
|
||||||
correctAnswer = false;
|
correctAnswer = false;
|
||||||
answer = NumberAlgorithms.isPrime(longNum);
|
answer = NumberAlgorithms.isPrime(longNum);
|
||||||
assertEquals("isPrime Long 4 failed", correctAnswer, answer);
|
assertEquals(correctAnswer, answer, "isPrime long 6 failed");
|
||||||
|
|
||||||
//Test 9
|
//Test 13
|
||||||
BigInteger bigNum = BigInteger.TWO;
|
BigInteger bigNum = BigInteger.valueOf(4);
|
||||||
correctAnswer = true;
|
correctAnswer = false;
|
||||||
answer = NumberAlgorithms.isPrime(bigNum);
|
answer = NumberAlgorithms.isPrime(bigNum);
|
||||||
assertEquals("isPrime BigInteger 1 failed", correctAnswer, answer);
|
assertEquals(correctAnswer, answer, "isPrime BigInteger 1 failed");
|
||||||
//Test 10
|
//Test 14
|
||||||
|
bigNum = BigInteger.valueOf(9);
|
||||||
|
correctAnswer = false;
|
||||||
|
answer = NumberAlgorithms.isPrime(bigNum);
|
||||||
|
assertEquals(correctAnswer, answer, "isPrime BigInteger 2 failed");
|
||||||
|
//Test 15
|
||||||
|
bigNum = BigInteger.valueOf(15);
|
||||||
|
correctAnswer = false;
|
||||||
|
answer = NumberAlgorithms.isPrime(bigNum);
|
||||||
|
assertEquals(correctAnswer, answer, "isPrime BigInteger 3 failed");
|
||||||
|
//Test 16
|
||||||
bigNum = BigInteger.valueOf(97);
|
bigNum = BigInteger.valueOf(97);
|
||||||
correctAnswer = true;
|
correctAnswer = true;
|
||||||
answer = NumberAlgorithms.isPrime(bigNum);
|
answer = NumberAlgorithms.isPrime(bigNum);
|
||||||
assertEquals("isPrime BigInteger 2 failed", correctAnswer, answer);
|
assertEquals(correctAnswer, answer, "isPrime BigInteger 4 failed");
|
||||||
//Test 11
|
//Test 17
|
||||||
bigNum = BigInteger.valueOf(1000);
|
bigNum = BigInteger.valueOf(1000);
|
||||||
correctAnswer = false;
|
correctAnswer = false;
|
||||||
answer = NumberAlgorithms.isPrime(bigNum);
|
answer = NumberAlgorithms.isPrime(bigNum);
|
||||||
assertEquals("isPrime BigInteger 3 failed", correctAnswer, answer);
|
assertEquals(correctAnswer, answer, "isPrime BigInteger 5 failed");
|
||||||
//Test 12
|
//Test 18
|
||||||
bigNum = BigInteger.ONE;
|
bigNum = BigInteger.ONE;
|
||||||
correctAnswer = false;
|
correctAnswer = false;
|
||||||
answer = NumberAlgorithms.isPrime(bigNum);
|
answer = NumberAlgorithms.isPrime(bigNum);
|
||||||
assertEquals("isPrime BigInteger 4 failed", correctAnswer, answer);
|
assertEquals(correctAnswer, answer, "isPrime BigInteger 6 failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -148,24 +211,49 @@ public class TestNumberAlgorithms{
|
|||||||
List<Integer> correctAnswer = Arrays.asList(2, 2, 5, 5);
|
List<Integer> correctAnswer = Arrays.asList(2, 2, 5, 5);
|
||||||
int number = 100;
|
int number = 100;
|
||||||
List<Integer> answer = NumberAlgorithms.getFactors(number);
|
List<Integer> answer = NumberAlgorithms.getFactors(number);
|
||||||
assertEquals("getFactors Integer 1 failed", correctAnswer, answer);
|
assertEquals(correctAnswer, answer, "getFactors int 1 failed");
|
||||||
//Test 2
|
//Test 2
|
||||||
correctAnswer = Arrays.asList(2, 7, 7);
|
correctAnswer = Arrays.asList(2, 7, 7);
|
||||||
number = 98;
|
number = 98;
|
||||||
answer = NumberAlgorithms.getFactors(number);
|
answer = NumberAlgorithms.getFactors(number);
|
||||||
assertEquals("getFactors Integer 2 failed", correctAnswer, answer);
|
assertEquals(correctAnswer, answer, "getFactors int 2 failed");
|
||||||
|
|
||||||
//Test 3
|
//Test 3
|
||||||
|
correctAnswer = Arrays.asList(7);
|
||||||
|
number = 7;
|
||||||
|
answer = NumberAlgorithms.getFactors(number);
|
||||||
|
assertEquals(correctAnswer, answer, "getFactors int 3 failed");
|
||||||
|
|
||||||
|
//Test 4
|
||||||
List<Long> longCorrectAnswer = Arrays.asList(2L, 2L, 5L, 5L);
|
List<Long> longCorrectAnswer = Arrays.asList(2L, 2L, 5L, 5L);
|
||||||
long longNumber = 100L;
|
long longNumber = 100L;
|
||||||
List<Long> longAnswer = NumberAlgorithms.getFactors(longNumber);
|
List<Long> longAnswer = NumberAlgorithms.getFactors(longNumber);
|
||||||
assertEquals("getFactors Long failed", longCorrectAnswer, longAnswer);
|
assertEquals(longCorrectAnswer, longAnswer, "getFactors long 1 failed");
|
||||||
|
//Test 5
|
||||||
|
longCorrectAnswer = Arrays.asList(2L, 7L, 7L);
|
||||||
|
longNumber = 98;
|
||||||
|
longAnswer = NumberAlgorithms.getFactors(longNumber);
|
||||||
|
assertEquals(longCorrectAnswer, longAnswer, "getFactors long 2 failed");
|
||||||
|
//Test 6
|
||||||
|
longCorrectAnswer = Arrays.asList(7L);
|
||||||
|
longNumber = 7;
|
||||||
|
longAnswer = NumberAlgorithms.getFactors(longNumber);
|
||||||
|
assertEquals(longCorrectAnswer, longAnswer, "getFactors long 3 failed");
|
||||||
|
|
||||||
//Test 4
|
//Test 7
|
||||||
List<BigInteger> bigCorrectAnswer = Arrays.asList(BigInteger.valueOf(2), BigInteger.valueOf(7), BigInteger.valueOf(7));
|
List<BigInteger> bigCorrectAnswer = Arrays.asList(BigInteger.TWO, BigInteger.TWO, BigInteger.valueOf(5), BigInteger.valueOf(5));
|
||||||
BigInteger bigNumber = BigInteger.valueOf(98);
|
BigInteger bigNumber = BigInteger.valueOf(100);
|
||||||
List<BigInteger> bigAnswer = NumberAlgorithms.getFactors(bigNumber);
|
List<BigInteger> bigAnswer = NumberAlgorithms.getFactors(bigNumber);
|
||||||
assertEquals("getFactors BigInteger failed", bigCorrectAnswer, bigAnswer);
|
assertEquals(bigCorrectAnswer, bigAnswer, "getFactors BigInteger failed");
|
||||||
|
//Test 8
|
||||||
|
bigCorrectAnswer = Arrays.asList(BigInteger.valueOf(2), BigInteger.valueOf(7), BigInteger.valueOf(7));
|
||||||
|
bigNumber = BigInteger.valueOf(98);
|
||||||
|
bigAnswer = NumberAlgorithms.getFactors(bigNumber);
|
||||||
|
assertEquals(bigCorrectAnswer, bigAnswer, "getFactors BigInteger failed");
|
||||||
|
//Test 9
|
||||||
|
bigCorrectAnswer = Arrays.asList(BigInteger.valueOf(7));
|
||||||
|
bigNumber = BigInteger.valueOf(7);
|
||||||
|
bigAnswer = NumberAlgorithms.getFactors(bigNumber);
|
||||||
|
assertEquals(bigCorrectAnswer, bigAnswer, "getFactors BigInteger failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -174,140 +262,223 @@ public class TestNumberAlgorithms{
|
|||||||
List<Integer> correctAnswer = Arrays.asList(1, 2, 4, 5, 10, 20, 25, 50, 100);
|
List<Integer> correctAnswer = Arrays.asList(1, 2, 4, 5, 10, 20, 25, 50, 100);
|
||||||
int topNum = 100;
|
int topNum = 100;
|
||||||
List<Integer> answer = NumberAlgorithms.getDivisors(topNum);
|
List<Integer> answer = NumberAlgorithms.getDivisors(topNum);
|
||||||
assertEquals("getDivisors Integer 1 failed", correctAnswer, answer);
|
assertEquals(correctAnswer, answer, "getDivisors int 1 failed");
|
||||||
//Test 2
|
//Test 2
|
||||||
correctAnswer = Arrays.asList(1, 2, 3, 6);
|
correctAnswer = Arrays.asList(1, 2, 3, 6);
|
||||||
topNum = 6;
|
topNum = 6;
|
||||||
answer = NumberAlgorithms.getDivisors(topNum);
|
answer = NumberAlgorithms.getDivisors(topNum);
|
||||||
assertEquals("getDivisors Integer 2 failed", correctAnswer, answer);
|
assertEquals(correctAnswer, answer, "getDivisors int 2 failed");
|
||||||
|
|
||||||
//Test 3
|
//Test 3
|
||||||
|
correctAnswer = new ArrayList<>();
|
||||||
|
topNum = -1;
|
||||||
|
answer = NumberAlgorithms.getDivisors(topNum);
|
||||||
|
assertEquals(correctAnswer, answer, "getDivisors int 3 failed");
|
||||||
|
|
||||||
|
//Test 4
|
||||||
List<Long> longCorrectAnswer = Arrays.asList(1L, 2L, 4L, 5L, 10L, 20L, 25L, 50L, 100L);
|
List<Long> longCorrectAnswer = Arrays.asList(1L, 2L, 4L, 5L, 10L, 20L, 25L, 50L, 100L);
|
||||||
long longTopNum = 100;
|
long longTopNum = 100;
|
||||||
List<Long> longAnswer = NumberAlgorithms.getDivisors(longTopNum);
|
List<Long> longAnswer = NumberAlgorithms.getDivisors(longTopNum);
|
||||||
assertEquals("getDivisors Long 1 failed", longCorrectAnswer, longAnswer);
|
assertEquals(longCorrectAnswer, longAnswer, "getDivisors long 1 failed");
|
||||||
//Test 4
|
//Test 5
|
||||||
longCorrectAnswer = Arrays.asList(1L, 2L, 3L, 6L);
|
longCorrectAnswer = Arrays.asList(1L, 2L, 3L, 6L);
|
||||||
longTopNum = 6;
|
longTopNum = 6;
|
||||||
longAnswer = NumberAlgorithms.getDivisors(longTopNum);
|
longAnswer = NumberAlgorithms.getDivisors(longTopNum);
|
||||||
assertEquals("getDivisors Long 2 failed", longCorrectAnswer, longAnswer);
|
assertEquals(longCorrectAnswer, longAnswer, "getDivisors long 2 failed");
|
||||||
|
//Test 6
|
||||||
|
longCorrectAnswer = new ArrayList<>();
|
||||||
|
longTopNum = -1;
|
||||||
|
longAnswer = NumberAlgorithms.getDivisors(longTopNum);
|
||||||
|
assertEquals(longCorrectAnswer, longAnswer, "getDivisors long 3 failed");
|
||||||
|
|
||||||
//Test 5
|
//Test 7
|
||||||
List<BigInteger> bigCorrectAnswer = Arrays.asList(BigInteger.valueOf(1), BigInteger.valueOf(2), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(10), BigInteger.valueOf(20), BigInteger.valueOf(25), BigInteger.valueOf(50), BigInteger.valueOf(100));
|
List<BigInteger> bigCorrectAnswer = Arrays.asList(BigInteger.valueOf(1), BigInteger.valueOf(2), BigInteger.valueOf(4), BigInteger.valueOf(5), BigInteger.valueOf(10), BigInteger.valueOf(20), BigInteger.valueOf(25), BigInteger.valueOf(50), BigInteger.valueOf(100));
|
||||||
BigInteger bigTopNum = BigInteger.valueOf(100);
|
BigInteger bigTopNum = BigInteger.valueOf(100);
|
||||||
List<BigInteger> bigAnswer = NumberAlgorithms.getDivisors(bigTopNum);
|
List<BigInteger> bigAnswer = NumberAlgorithms.getDivisors(bigTopNum);
|
||||||
assertEquals("getDivisors BigInteger 1 failed", bigCorrectAnswer, bigAnswer);
|
assertEquals(bigCorrectAnswer, bigAnswer, "getDivisors BigInteger 1 failed");
|
||||||
//Test 6
|
//Test 8
|
||||||
bigCorrectAnswer = Arrays.asList(BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(6));
|
bigCorrectAnswer = Arrays.asList(BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(6));
|
||||||
bigTopNum = BigInteger.valueOf(6);
|
bigTopNum = BigInteger.valueOf(6);
|
||||||
bigAnswer = NumberAlgorithms.getDivisors(bigTopNum);
|
bigAnswer = NumberAlgorithms.getDivisors(bigTopNum);
|
||||||
assertEquals("getDivisors BigInteger 2 failed", bigCorrectAnswer, bigAnswer);
|
assertEquals(bigCorrectAnswer, bigAnswer, "getDivisors BigInteger 2 failed");
|
||||||
|
//Test 9
|
||||||
|
bigCorrectAnswer = new ArrayList<>();
|
||||||
|
bigTopNum = BigInteger.valueOf(-1);
|
||||||
|
bigAnswer = NumberAlgorithms.getDivisors(bigTopNum);
|
||||||
|
assertEquals(bigCorrectAnswer, bigAnswer, "getDivisors BigInteger 3 failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetFib(){
|
public void testGetFib(){
|
||||||
//Test 1
|
//Test 1
|
||||||
int correctAnswer = 144;
|
int correctAnswer = 0;
|
||||||
int number = 12;
|
int number = 0;
|
||||||
int answer = NumberAlgorithms.getFib(number);
|
int answer = NumberAlgorithms.getFib(number);
|
||||||
assertEquals("getFib Integer 1 failed", correctAnswer, answer);
|
assertEquals(correctAnswer, answer, "getFib int 1 failed");
|
||||||
//Test 2
|
//Test 2
|
||||||
|
correctAnswer = 144;
|
||||||
|
number = 12;
|
||||||
|
answer = NumberAlgorithms.getFib(number);
|
||||||
|
assertEquals(correctAnswer, answer, "getFib int 2 failed");
|
||||||
|
//Test 3
|
||||||
correctAnswer = 6765;
|
correctAnswer = 6765;
|
||||||
number = 20;
|
number = 20;
|
||||||
answer = NumberAlgorithms.getFib(number);
|
answer = NumberAlgorithms.getFib(number);
|
||||||
assertEquals("getFib Integer 2 failed", correctAnswer, answer);
|
assertEquals(correctAnswer, answer, "getFib int 3 failed");
|
||||||
|
|
||||||
//Test 3
|
|
||||||
long longCorrectAnswer = 6765L;
|
|
||||||
long longNumber = 20L;
|
|
||||||
long longAnswer = NumberAlgorithms.getFib(longNumber);
|
|
||||||
assertEquals("getFib Long failed", longCorrectAnswer, longAnswer);
|
|
||||||
|
|
||||||
//Test 4
|
//Test 4
|
||||||
BigInteger bigCorrectAnswer = new BigInteger("1070066266382758936764980584457396885083683896632151665013235203375314520604694040621889147582489792657804694888177591957484336466672569959512996030461262748092482186144069433051234774442750273781753087579391666192149259186759553966422837148943113074699503439547001985432609723067290192870526447243726117715821825548491120525013201478612965931381792235559657452039506137551467837543229119602129934048260706175397706847068202895486902666185435124521900369480641357447470911707619766945691070098024393439617474103736912503231365532164773697023167755051595173518460579954919410967778373229665796581646513903488154256310184224190259846088000110186255550245493937113651657039447629584714548523425950428582425306083544435428212611008992863795048006894330309773217834864543113205765659868456288616808718693835297350643986297640660000723562917905207051164077614812491885830945940566688339109350944456576357666151619317753792891661581327159616877487983821820492520348473874384736771934512787029218636250627816");
|
long longCorrectAnswer = 0;
|
||||||
BigInteger bigNumber = BigInteger.valueOf(4782);
|
long longNumber = 0;
|
||||||
|
long longAnswer = NumberAlgorithms.getFib(longNumber);
|
||||||
|
assertEquals(longCorrectAnswer, longAnswer, "getFib long 1 failed");
|
||||||
|
//Test 5
|
||||||
|
longCorrectAnswer = 144;
|
||||||
|
longNumber = 12;
|
||||||
|
longAnswer = NumberAlgorithms.getFib(longNumber);
|
||||||
|
assertEquals(longCorrectAnswer, longAnswer, "getFib long 2 failed");
|
||||||
|
//Test 6
|
||||||
|
longCorrectAnswer = 6765;
|
||||||
|
longNumber = 20;
|
||||||
|
longAnswer = NumberAlgorithms.getFib(longNumber);
|
||||||
|
assertEquals(longCorrectAnswer, longAnswer, "getFib long 3 failed");
|
||||||
|
|
||||||
|
//Test 7
|
||||||
|
BigInteger bigCorrectAnswer = BigInteger.ZERO;
|
||||||
|
BigInteger bigNumber = BigInteger.ZERO;
|
||||||
BigInteger bigAnswer = NumberAlgorithms.getFib(bigNumber);
|
BigInteger bigAnswer = NumberAlgorithms.getFib(bigNumber);
|
||||||
assertEquals("getFib BigInteger failed", bigCorrectAnswer, bigAnswer);
|
assertEquals(bigCorrectAnswer, bigAnswer, "getFib BigInteger 1 failed");
|
||||||
|
//Test 8
|
||||||
|
bigCorrectAnswer = BigInteger.valueOf(144);
|
||||||
|
bigNumber = BigInteger.valueOf(12);
|
||||||
|
bigAnswer = NumberAlgorithms.getFib(bigNumber);
|
||||||
|
assertEquals(bigCorrectAnswer, bigAnswer, "getFib BigInteger 2 failed");
|
||||||
|
//Test 9
|
||||||
|
bigCorrectAnswer = BigInteger.valueOf(6765);
|
||||||
|
bigNumber = BigInteger.valueOf(20);
|
||||||
|
bigAnswer = NumberAlgorithms.getFib(bigNumber);
|
||||||
|
assertEquals(bigCorrectAnswer, bigAnswer, "getFib BigInteger 3 failed");
|
||||||
|
//Test 10
|
||||||
|
bigCorrectAnswer = new BigInteger("1070066266382758936764980584457396885083683896632151665013235203375314520604694040621889147582489792657804694888177591957484336466672569959512996030461262748092482186144069433051234774442750273781753087579391666192149259186759553966422837148943113074699503439547001985432609723067290192870526447243726117715821825548491120525013201478612965931381792235559657452039506137551467837543229119602129934048260706175397706847068202895486902666185435124521900369480641357447470911707619766945691070098024393439617474103736912503231365532164773697023167755051595173518460579954919410967778373229665796581646513903488154256310184224190259846088000110186255550245493937113651657039447629584714548523425950428582425306083544435428212611008992863795048006894330309773217834864543113205765659868456288616808718693835297350643986297640660000723562917905207051164077614812491885830945940566688339109350944456576357666151619317753792891661581327159616877487983821820492520348473874384736771934512787029218636250627816");
|
||||||
|
bigNumber = BigInteger.valueOf(4782);
|
||||||
|
bigAnswer = NumberAlgorithms.getFib(bigNumber);
|
||||||
|
assertEquals(bigCorrectAnswer, bigAnswer, "getFib BigInteger 4 failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetAllFib(){
|
public void testGetAllFib(){
|
||||||
//Test 1
|
//Test 1
|
||||||
List<Integer> correctAnswer = Arrays.asList(1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89);
|
List<Integer> correctAnswer = new ArrayList<>();
|
||||||
int highestNumber = 100;
|
int highestNumber = 0;
|
||||||
List<Integer> answer = NumberAlgorithms.getAllFib(highestNumber);
|
List<Integer> answer = NumberAlgorithms.getAllFib(highestNumber);
|
||||||
assertEquals("getAllFib Integer 1 failed", correctAnswer, answer);
|
assertEquals(correctAnswer, answer, "getAllFib int 1 failed");
|
||||||
//Test 2
|
//Test 2
|
||||||
|
correctAnswer = Arrays.asList(1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89);
|
||||||
|
highestNumber = 100;
|
||||||
|
answer = NumberAlgorithms.getAllFib(highestNumber);
|
||||||
|
assertEquals(correctAnswer, answer, "getAllFib int 2 failed");
|
||||||
|
//Test 3
|
||||||
correctAnswer = Arrays.asList(1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987);
|
correctAnswer = Arrays.asList(1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987);
|
||||||
highestNumber = 1000;
|
highestNumber = 1000;
|
||||||
answer = NumberAlgorithms.getAllFib(highestNumber);
|
answer = NumberAlgorithms.getAllFib(highestNumber);
|
||||||
assertEquals("getAllFib Integer 2 failed", correctAnswer, answer);
|
assertEquals(correctAnswer, answer, "getAllFib int 3 failed");
|
||||||
|
|
||||||
//Test 3
|
|
||||||
List<Long> longCorrectAnswer = Arrays.asList(1L, 1L, 2L, 3L, 5L, 8L, 13L, 21L, 34L, 55L, 89L, 144L, 233L, 377L, 610L, 987L);
|
|
||||||
long longHighestNumber = 1000L;
|
|
||||||
List<Long> longAnswer = NumberAlgorithms.getAllFib(longHighestNumber);
|
|
||||||
assertEquals("getAllFib Long failed", longCorrectAnswer, longAnswer);
|
|
||||||
|
|
||||||
//Test 4
|
//Test 4
|
||||||
List<BigInteger> bigCorrectAnswer = Arrays.asList(BigInteger.valueOf(1), BigInteger.valueOf(1), BigInteger.valueOf(2), BigInteger.valueOf(3), BigInteger.valueOf(5), BigInteger.valueOf(8), BigInteger.valueOf(13), BigInteger.valueOf(21), BigInteger.valueOf(34), BigInteger.valueOf(55), BigInteger.valueOf(89));
|
List<Long> longCorrectAnswer = new ArrayList<>();
|
||||||
BigInteger bigHighestNumber = BigInteger.valueOf(100);
|
long longHighestNumber = 0;
|
||||||
|
List<Long> longAnswer = NumberAlgorithms.getAllFib(longHighestNumber);
|
||||||
|
assertEquals(longCorrectAnswer, longAnswer, "getAllFib long 1 failed");
|
||||||
|
//Test 5
|
||||||
|
longCorrectAnswer = Arrays.asList(1L, 1L, 2L, 3L, 5L, 8L, 13L, 21L, 34L, 55L, 89L);
|
||||||
|
longHighestNumber = 100;
|
||||||
|
longAnswer = NumberAlgorithms.getAllFib(longHighestNumber);
|
||||||
|
assertEquals(longCorrectAnswer, longAnswer, "getAllFib long 2 failed");
|
||||||
|
//Test 6
|
||||||
|
longCorrectAnswer = Arrays.asList(1L, 1L, 2L, 3L, 5L, 8L, 13L, 21L, 34L, 55L, 89L, 144L, 233L, 377L, 610L, 987L);
|
||||||
|
longHighestNumber = 1000L;
|
||||||
|
longAnswer = NumberAlgorithms.getAllFib(longHighestNumber);
|
||||||
|
assertEquals(longCorrectAnswer, longAnswer, "getAllFib long 3 failed");
|
||||||
|
|
||||||
|
//Test 7
|
||||||
|
List<BigInteger> bigCorrectAnswer = new ArrayList<>();
|
||||||
|
BigInteger bigHighestNumber = BigInteger.ZERO;
|
||||||
List<BigInteger> bigAnswer = NumberAlgorithms.getAllFib(bigHighestNumber);
|
List<BigInteger> bigAnswer = NumberAlgorithms.getAllFib(bigHighestNumber);
|
||||||
assertEquals("getAllFib BigInteger failed", bigCorrectAnswer, bigAnswer);
|
assertEquals(bigCorrectAnswer, bigAnswer, "gitAllFib BigInteger 1 failed");
|
||||||
|
//Test 8
|
||||||
|
bigCorrectAnswer = Arrays.asList(BigInteger.valueOf(1), BigInteger.valueOf(1), BigInteger.valueOf(2), BigInteger.valueOf(3), BigInteger.valueOf(5), BigInteger.valueOf(8), BigInteger.valueOf(13), BigInteger.valueOf(21), BigInteger.valueOf(34), BigInteger.valueOf(55), BigInteger.valueOf(89));
|
||||||
|
bigHighestNumber = BigInteger.valueOf(100);
|
||||||
|
bigAnswer = NumberAlgorithms.getAllFib(bigHighestNumber);
|
||||||
|
assertEquals(bigCorrectAnswer, bigAnswer, "getAllFib BigInteger 2 failed");
|
||||||
|
//Test 9
|
||||||
|
bigCorrectAnswer = Arrays.asList(BigInteger.ONE, BigInteger.ONE, BigInteger.TWO, BigInteger.valueOf(3), BigInteger.valueOf(5), BigInteger.valueOf(8), BigInteger.valueOf(13), BigInteger.valueOf(21), BigInteger.valueOf(34), BigInteger.valueOf(55), BigInteger.valueOf(89), BigInteger.valueOf(144), BigInteger.valueOf(233), BigInteger.valueOf(377), BigInteger.valueOf(610), BigInteger.valueOf(987));
|
||||||
|
bigHighestNumber = BigInteger.valueOf(1000);
|
||||||
|
bigAnswer = NumberAlgorithms.getAllFib(bigHighestNumber);
|
||||||
|
assertEquals(bigCorrectAnswer, bigAnswer, "getAllFib BigInteger 3 failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFactorial(){
|
public void testFactorial(){
|
||||||
//Integer
|
|
||||||
//Test 1
|
//Test 1
|
||||||
|
Exception error = assertThrows(InvalidParameterException.class, () -> {
|
||||||
|
NumberAlgorithms.factorial(-1);
|
||||||
|
});
|
||||||
|
assertEquals(NumberAlgorithms.FACTORIAL_NEGATIVE_MESSAGE, error.getMessage());
|
||||||
|
//Test 2
|
||||||
int correctAnswer = 720;
|
int correctAnswer = 720;
|
||||||
int number = 6;
|
int number = 6;
|
||||||
int answer = NumberAlgorithms.factorial(number);
|
int answer = NumberAlgorithms.factorial(number);
|
||||||
assertEquals("factorial Integer 1 failed", correctAnswer, answer);
|
assertEquals(correctAnswer, answer, "factorial int 1 failed");
|
||||||
//Test 2
|
//Test 3
|
||||||
correctAnswer = 479001600;
|
correctAnswer = 479001600;
|
||||||
number = 12;
|
number = 12;
|
||||||
answer = NumberAlgorithms.factorial(number);
|
answer = NumberAlgorithms.factorial(number);
|
||||||
assertEquals("factorial Integer 2 failed", correctAnswer, answer);
|
assertEquals(correctAnswer, answer, "factorial int 2 failed");
|
||||||
|
|
||||||
//Long
|
//Test 4
|
||||||
//Test 3
|
error = assertThrows(InvalidParameterException.class, () -> {
|
||||||
|
NumberAlgorithms.factorial(-1L);
|
||||||
|
});
|
||||||
|
assertEquals(NumberAlgorithms.FACTORIAL_NEGATIVE_MESSAGE, error.getMessage());
|
||||||
|
//Test 5
|
||||||
long correctAnswerLong = 720L;
|
long correctAnswerLong = 720L;
|
||||||
long numberLong = 6L;
|
long numberLong = 6L;
|
||||||
long answerLong = NumberAlgorithms.factorial(numberLong);
|
long answerLong = NumberAlgorithms.factorial(numberLong);
|
||||||
assertEquals("factorial Long 1 failed", correctAnswerLong, answerLong);
|
assertEquals(correctAnswerLong, answerLong, "factorial long 1 failed");
|
||||||
//Test 4
|
//Test 6
|
||||||
correctAnswerLong = 479001600L;
|
correctAnswerLong = 479001600L;
|
||||||
numberLong = 12L;
|
numberLong = 12L;
|
||||||
answerLong = NumberAlgorithms.factorial(numberLong);
|
answerLong = NumberAlgorithms.factorial(numberLong);
|
||||||
assertEquals("factorial Long 2 failed", correctAnswerLong, answerLong);
|
assertEquals(correctAnswerLong, answerLong, "factorial long 2 failed");
|
||||||
//Test 5
|
//Test 7
|
||||||
correctAnswerLong = 2432902008176640000L;
|
correctAnswerLong = 2432902008176640000L;
|
||||||
numberLong = 20L;
|
numberLong = 20L;
|
||||||
answerLong = NumberAlgorithms.factorial(numberLong);
|
answerLong = NumberAlgorithms.factorial(numberLong);
|
||||||
assertEquals("factorial Long 3 failed", correctAnswerLong, answerLong);
|
assertEquals(correctAnswerLong, answerLong, "factorial long 3 failed");
|
||||||
|
|
||||||
//BigInteger
|
//Test 8
|
||||||
//Test 6
|
final BigInteger exceptionNumberBig = BigInteger.valueOf(-1);
|
||||||
|
error = assertThrows(InvalidParameterException.class, () -> {
|
||||||
|
NumberAlgorithms.factorial(exceptionNumberBig);
|
||||||
|
});
|
||||||
|
assertEquals(NumberAlgorithms.FACTORIAL_NEGATIVE_MESSAGE, error.getMessage());
|
||||||
|
//Test 9
|
||||||
BigInteger correctAnswerBig = BigInteger.valueOf(720L);
|
BigInteger correctAnswerBig = BigInteger.valueOf(720L);
|
||||||
BigInteger numberBig = BigInteger.valueOf(6);
|
BigInteger numberBig = BigInteger.valueOf(6);
|
||||||
BigInteger answerBig = NumberAlgorithms.factorial(numberBig);
|
BigInteger answerBig = NumberAlgorithms.factorial(numberBig);
|
||||||
assertEquals("factorial BigInteger 1 failed", correctAnswerBig, answerBig);
|
assertEquals(correctAnswerBig, answerBig, "factorial BigInteger 1 failed");
|
||||||
//Test 7
|
//Test 10
|
||||||
correctAnswerBig = BigInteger.valueOf(479001600L);
|
correctAnswerBig = BigInteger.valueOf(479001600L);
|
||||||
numberBig = BigInteger.valueOf(12);
|
numberBig = BigInteger.valueOf(12);
|
||||||
answerBig = NumberAlgorithms.factorial(numberBig);
|
answerBig = NumberAlgorithms.factorial(numberBig);
|
||||||
assertEquals("factorial BigInteger 2 failed", correctAnswerBig, answerBig);
|
assertEquals(correctAnswerBig, answerBig, "factorial BigInteger 2 failed");
|
||||||
//Test 8
|
//Test 11
|
||||||
correctAnswerBig = BigInteger.valueOf(2432902008176640000L);
|
correctAnswerBig = BigInteger.valueOf(2432902008176640000L);
|
||||||
numberBig = BigInteger.valueOf(20L);
|
numberBig = BigInteger.valueOf(20L);
|
||||||
answerBig = NumberAlgorithms.factorial(numberBig);
|
answerBig = NumberAlgorithms.factorial(numberBig);
|
||||||
assertEquals("factorial BigInteger 3 failed", correctAnswerBig, answerBig);
|
assertEquals(correctAnswerBig, answerBig, "factorial BigInteger 3 failed");
|
||||||
//Test 9
|
//Test 12
|
||||||
correctAnswerBig = new BigInteger("265252859812191058636308480000000");
|
correctAnswerBig = new BigInteger("265252859812191058636308480000000");
|
||||||
numberBig = BigInteger.valueOf(30L);
|
numberBig = BigInteger.valueOf(30L);
|
||||||
answerBig = NumberAlgorithms.factorial(numberBig);
|
answerBig = NumberAlgorithms.factorial(numberBig);
|
||||||
assertEquals("factorial BigInteger 4 failed", correctAnswerBig, answerBig);
|
assertEquals(correctAnswerBig, answerBig, "factorial BigInteger 4 failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -317,57 +488,57 @@ public class TestNumberAlgorithms{
|
|||||||
int num2 = 3;
|
int num2 = 3;
|
||||||
int correctAnswer = 1;
|
int correctAnswer = 1;
|
||||||
int answer = NumberAlgorithms.gcd(num1, num2);
|
int answer = NumberAlgorithms.gcd(num1, num2);
|
||||||
assertEquals("GCD Integer 1 failed", correctAnswer, answer);
|
assertEquals(correctAnswer, answer, "GCD int 1 failed");
|
||||||
//Test 2
|
//Test 2
|
||||||
num1 = 1000;
|
num1 = 1000;
|
||||||
num2 = 575;
|
num2 = 575;
|
||||||
correctAnswer = 25;
|
correctAnswer = 25;
|
||||||
answer = NumberAlgorithms.gcd(num1, num2);
|
answer = NumberAlgorithms.gcd(num1, num2);
|
||||||
assertEquals("GCD Integer 2 failed", correctAnswer, answer);
|
assertEquals(correctAnswer, answer, "GCD int 2 failed");
|
||||||
//Test 3
|
//Test 3
|
||||||
num1 = 1000;
|
num1 = 1000;
|
||||||
num2 = 1000;
|
num2 = 1000;
|
||||||
correctAnswer = 1000;
|
correctAnswer = 1000;
|
||||||
answer = NumberAlgorithms.gcd(num1, num2);
|
answer = NumberAlgorithms.gcd(num1, num2);
|
||||||
assertEquals("GCD Integer 3 failed", correctAnswer, answer);
|
assertEquals(correctAnswer, answer, "GCD int 3 failed");
|
||||||
|
|
||||||
//Test 4
|
//Test 4
|
||||||
long longNum1 = 2;
|
long longNum1 = 2;
|
||||||
long longNum2 = 3;
|
long longNum2 = 3;
|
||||||
long longCorrectAnswer = 1;
|
long longCorrectAnswer = 1;
|
||||||
long longAnswer = NumberAlgorithms.gcd(longNum1, longNum2);
|
long longAnswer = NumberAlgorithms.gcd(longNum1, longNum2);
|
||||||
assertEquals("GCD Long 1 failed", longCorrectAnswer, longAnswer);
|
assertEquals(longCorrectAnswer, longAnswer, "GCD long 1 failed");
|
||||||
//Test 5
|
//Test 5
|
||||||
longNum1 = 1000;
|
longNum1 = 1000;
|
||||||
longNum2 = 575;
|
longNum2 = 575;
|
||||||
longCorrectAnswer = 25;
|
longCorrectAnswer = 25;
|
||||||
longAnswer = NumberAlgorithms.gcd(longNum1, longNum2);
|
longAnswer = NumberAlgorithms.gcd(longNum1, longNum2);
|
||||||
assertEquals("GCD Long 2 failed", longCorrectAnswer, longAnswer);
|
assertEquals(longCorrectAnswer, longAnswer, "GCD long 2 failed");
|
||||||
//Test 6
|
//Test 6
|
||||||
longNum1 = 1000;
|
longNum1 = 1000;
|
||||||
longNum2 = 1000;
|
longNum2 = 1000;
|
||||||
longCorrectAnswer = 1000;
|
longCorrectAnswer = 1000;
|
||||||
longAnswer = NumberAlgorithms.gcd(longNum1, longNum2);
|
longAnswer = NumberAlgorithms.gcd(longNum1, longNum2);
|
||||||
assertEquals("GCD Long 3 failed", longCorrectAnswer, longAnswer);
|
assertEquals(longCorrectAnswer, longAnswer, "GCD long 3 failed");
|
||||||
|
|
||||||
//Test 7
|
//Test 7
|
||||||
BigInteger bigNum1 = BigInteger.TWO;
|
BigInteger bigNum1 = BigInteger.TWO;
|
||||||
BigInteger bigNum2 = BigInteger.valueOf(3);
|
BigInteger bigNum2 = BigInteger.valueOf(3);
|
||||||
BigInteger bigCorrectAnswer = BigInteger.ONE;
|
BigInteger bigCorrectAnswer = BigInteger.ONE;
|
||||||
BigInteger bigAnswer = NumberAlgorithms.gcd(bigNum1, bigNum2);
|
BigInteger bigAnswer = NumberAlgorithms.gcd(bigNum1, bigNum2);
|
||||||
assertEquals("GCD BigInteger 1 failed", bigCorrectAnswer, bigAnswer);
|
assertEquals(bigCorrectAnswer, bigAnswer, "GCD BigInteger 1 failed");
|
||||||
//Test 8
|
//Test 8
|
||||||
bigNum1 = BigInteger.valueOf(1000);
|
bigNum1 = BigInteger.valueOf(1000);
|
||||||
bigNum2 = BigInteger.valueOf(575);
|
bigNum2 = BigInteger.valueOf(575);
|
||||||
bigCorrectAnswer = BigInteger.valueOf(25);
|
bigCorrectAnswer = BigInteger.valueOf(25);
|
||||||
bigAnswer = NumberAlgorithms.gcd(bigNum1, bigNum2);
|
bigAnswer = NumberAlgorithms.gcd(bigNum1, bigNum2);
|
||||||
assertEquals("GCD BigInteger 2 failed", bigCorrectAnswer, bigAnswer);
|
assertEquals(bigCorrectAnswer, bigAnswer, "GCD BigInteger 2 failed");
|
||||||
//Test 9
|
//Test 9
|
||||||
bigNum1 = BigInteger.valueOf(1000);
|
bigNum1 = BigInteger.valueOf(1000);
|
||||||
bigNum2 = BigInteger.valueOf(1000);
|
bigNum2 = BigInteger.valueOf(1000);
|
||||||
bigCorrectAnswer = BigInteger.valueOf(1000);
|
bigCorrectAnswer = BigInteger.valueOf(1000);
|
||||||
bigAnswer = NumberAlgorithms.gcd(bigNum1, bigNum2);
|
bigAnswer = NumberAlgorithms.gcd(bigNum1, bigNum2);
|
||||||
assertEquals("GCD BigInteger 3 failed", bigCorrectAnswer, bigAnswer);
|
assertEquals(bigCorrectAnswer, bigAnswer, "GCD BigInteger 3 failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -376,48 +547,48 @@ public class TestNumberAlgorithms{
|
|||||||
int num = 7;
|
int num = 7;
|
||||||
String correctAnswer = "111";
|
String correctAnswer = "111";
|
||||||
String answer = NumberAlgorithms.toBin(num);
|
String answer = NumberAlgorithms.toBin(num);
|
||||||
assertEquals("toBin 1 failed", correctAnswer, answer);
|
assertEquals(correctAnswer, answer, "toBin 1 failed");
|
||||||
//Test 2
|
//Test 2
|
||||||
num = 0;
|
num = 0;
|
||||||
correctAnswer = "0";
|
correctAnswer = "0";
|
||||||
answer = NumberAlgorithms.toBin(num);
|
answer = NumberAlgorithms.toBin(num);
|
||||||
assertEquals("toBin 2 failed", correctAnswer, answer);
|
assertEquals(correctAnswer, answer, "toBin 2 failed");
|
||||||
//Test 3
|
//Test 3
|
||||||
num = 1000000;
|
num = 1000000;
|
||||||
correctAnswer = "11110100001001000000";
|
correctAnswer = "11110100001001000000";
|
||||||
answer = NumberAlgorithms.toBin(num);
|
answer = NumberAlgorithms.toBin(num);
|
||||||
assertEquals("toBin 3 failed", correctAnswer, answer);
|
assertEquals(correctAnswer, answer, "toBin 3 failed");
|
||||||
|
|
||||||
//Test 4
|
//Test 4
|
||||||
long longNum = 7;
|
long longNum = 7;
|
||||||
correctAnswer = "111";
|
correctAnswer = "111";
|
||||||
answer = NumberAlgorithms.toBin(longNum);
|
answer = NumberAlgorithms.toBin(longNum);
|
||||||
assertEquals("toBin long 1 failed", correctAnswer, answer);
|
assertEquals(correctAnswer, answer, "toBin long 1 failed");
|
||||||
//Test 5
|
//Test 5
|
||||||
longNum = 0;
|
longNum = 0;
|
||||||
correctAnswer = "0";
|
correctAnswer = "0";
|
||||||
answer = NumberAlgorithms.toBin(longNum);
|
answer = NumberAlgorithms.toBin(longNum);
|
||||||
assertEquals("toBin long 2 failed", correctAnswer, answer);
|
assertEquals(correctAnswer, answer, "toBin long 2 failed");
|
||||||
//Test 6
|
//Test 6
|
||||||
longNum = 1000000;
|
longNum = 1000000;
|
||||||
correctAnswer = "11110100001001000000";
|
correctAnswer = "11110100001001000000";
|
||||||
answer = NumberAlgorithms.toBin(longNum);
|
answer = NumberAlgorithms.toBin(longNum);
|
||||||
assertEquals("toBin long 3 failed", correctAnswer, answer);
|
assertEquals(correctAnswer, answer, "toBin long 3 failed");
|
||||||
|
|
||||||
//Test 7
|
//Test 7
|
||||||
BigInteger bigNum = BigInteger.valueOf(7);
|
BigInteger bigNum = BigInteger.valueOf(7);
|
||||||
correctAnswer = "111";
|
correctAnswer = "111";
|
||||||
answer = NumberAlgorithms.toBin(bigNum);
|
answer = NumberAlgorithms.toBin(bigNum);
|
||||||
assertEquals("toBin big 1 failed", correctAnswer, answer);
|
assertEquals(correctAnswer, answer, "toBin big 1 failed");
|
||||||
//Test 8
|
//Test 8
|
||||||
bigNum = BigInteger.ZERO;
|
bigNum = BigInteger.ZERO;
|
||||||
correctAnswer = "0";
|
correctAnswer = "0";
|
||||||
answer = NumberAlgorithms.toBin(bigNum);
|
answer = NumberAlgorithms.toBin(bigNum);
|
||||||
assertEquals("toBin big 2 failed", correctAnswer, answer);
|
assertEquals(correctAnswer, answer, "toBin big 2 failed");
|
||||||
//Test 9
|
//Test 9
|
||||||
bigNum = BigInteger.valueOf(1000000);
|
bigNum = BigInteger.valueOf(1000000);
|
||||||
correctAnswer = "11110100001001000000";
|
correctAnswer = "11110100001001000000";
|
||||||
answer = NumberAlgorithms.toBin(bigNum);
|
answer = NumberAlgorithms.toBin(bigNum);
|
||||||
assertEquals("toBin big 3 failed", correctAnswer, answer);
|
assertEquals(correctAnswer, answer, "toBin big 3 failed");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
//JavaClasses/src/test/java/mattrixwv/TestSieveOfEratosthenes.java
|
//JavaClasses/src/test/java/mattrixwv/TestSieveOfEratosthenes.java
|
||||||
//Matthew Ellison
|
//Matthew Ellison
|
||||||
// Created: 06-30-21
|
// Created: 06-30-21
|
||||||
//Modified: 06-30-21
|
//Modified: 06-26-22
|
||||||
//This class uses to Sieve of Eratosthenes to generate an infinite number of primes
|
//This class uses to Sieve of Eratosthenes to generate an infinite number of primes
|
||||||
/*
|
/*
|
||||||
Copyright (C) 2021 Matthew Ellison
|
Copyright (C) 2022 Matthew Ellison
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
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
|
it under the terms of the GNU Lesser General Public License as published by
|
||||||
@@ -22,13 +22,15 @@ Copyright (C) 2021 Matthew Ellison
|
|||||||
package mattrixwv;
|
package mattrixwv;
|
||||||
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
|
||||||
public class TestSieveOfEratosthenes{
|
public class TestSieveOfEratosthenes{
|
||||||
@@ -36,24 +38,26 @@ public class TestSieveOfEratosthenes{
|
|||||||
public void testSieveOfEratosthenes(){
|
public void testSieveOfEratosthenes(){
|
||||||
//Test 1
|
//Test 1
|
||||||
SieveOfEratosthenes sieve = new SieveOfEratosthenes();
|
SieveOfEratosthenes sieve = new SieveOfEratosthenes();
|
||||||
ArrayList<Long> correctAnswer = new ArrayList<Long>(Arrays.asList(2L, 3L, 5L, 7L, 11L, 13L, 17L, 19L, 23L, 29L, 31L, 37L, 41L, 43L, 47L, 53L, 59L, 61L, 67L, 71L, 73L, 79L, 83L, 89L, 97L));
|
List<Long> correctAnswer = Arrays.asList(2L, 3L, 5L, 7L, 11L, 13L, 17L, 19L, 23L, 29L, 31L, 37L, 41L, 43L, 47L, 53L, 59L, 61L, 67L, 71L, 73L, 79L, 83L, 89L, 97L);
|
||||||
ArrayList<Long> answer = new ArrayList<Long>();
|
ArrayList<Long> answer = new ArrayList<Long>();
|
||||||
for(int cnt = 0;cnt < 25;++cnt){
|
for(int cnt = 0;cnt < 25;++cnt){
|
||||||
long prime = sieve.next();
|
long prime = sieve.next();
|
||||||
answer.add(prime);
|
answer.add(prime);
|
||||||
}
|
}
|
||||||
assertEquals("SieveOfEratosthenes failed", correctAnswer, answer);
|
assertEquals(correctAnswer, answer, "SieveOfEratosthenes failed");
|
||||||
|
assertTrue(sieve.hasNext());
|
||||||
}
|
}
|
||||||
@Test
|
@Test
|
||||||
public void testSieveOfEratosthenesBig(){
|
public void testSieveOfEratosthenesBig(){
|
||||||
//Test 1
|
//Test 1
|
||||||
SieveOfEratosthenesBig sieve = new SieveOfEratosthenesBig();
|
SieveOfEratosthenesBig sieve = new SieveOfEratosthenesBig();
|
||||||
ArrayList<BigInteger> correctAnswer = new ArrayList<BigInteger>(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)));
|
List<BigInteger> correctAnswer = 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));
|
||||||
ArrayList<BigInteger> answer = new ArrayList<BigInteger>();
|
ArrayList<BigInteger> answer = new ArrayList<BigInteger>();
|
||||||
for(int cnt = 0;cnt < 25;++cnt){
|
for(int cnt = 0;cnt < 25;++cnt){
|
||||||
BigInteger prime = sieve.next();
|
BigInteger prime = sieve.next();
|
||||||
answer.add(prime);
|
answer.add(prime);
|
||||||
}
|
}
|
||||||
assertEquals("SieveOfEratosthenesBig failed", correctAnswer, answer);
|
assertEquals(correctAnswer, answer, "SieveOfEratosthenesBig failed");
|
||||||
|
assertTrue(sieve.hasNext());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
//JavaClasses/src/test/java/mattrixwv/TestStopwatch.java
|
//JavaClasses/src/test/java/mattrixwv/TestStopwatch.java
|
||||||
//Matthew Ellison
|
//Matthew Ellison
|
||||||
// Created: 06-07-20
|
// Created: 06-07-20
|
||||||
//Modified: 07-28-20
|
//Modified: 06-26-22
|
||||||
//This class holds many algorithms that I have found it useful to keep around
|
//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
|
//As such all of the functions in here are static and meant to be used as stand alone functions
|
||||||
/*
|
/*
|
||||||
Copyright (C) 2020 Matthew Ellison
|
Copyright (C) 2022 Matthew Ellison
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
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
|
it under the terms of the GNU Lesser General Public License as published by
|
||||||
@@ -24,17 +24,20 @@ Copyright (C) 2020 Matthew Ellison
|
|||||||
|
|
||||||
package mattrixwv;
|
package mattrixwv;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
import static org.junit.Assert.assertNotEquals;
|
|
||||||
import static org.junit.Assert.assertNotNull;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import mattrixwv.exceptions.InvalidResult;
|
import mattrixwv.exceptions.InvalidResult;
|
||||||
|
|
||||||
|
|
||||||
public class TestStopwatch{
|
public class TestStopwatch{
|
||||||
private static final Integer NUM_TO_RUN = 100000;
|
private static final Integer NUM_TO_RUN = 100000;
|
||||||
private static final Double ALLOWANCE = .0000000001;
|
private static final Double ALLOWANCE = .0000000001;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testStartStop(){
|
public void testStartStop(){
|
||||||
Stopwatch timer = new Stopwatch();
|
Stopwatch timer = new Stopwatch();
|
||||||
@@ -43,6 +46,7 @@ public class TestStopwatch{
|
|||||||
assertNotNull(timer.toString());
|
assertNotNull(timer.toString());
|
||||||
//If it gets to here without throwing an exception everything went well
|
//If it gets to here without throwing an exception everything went well
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testConversion() throws InvalidResult{
|
public void testConversion() throws InvalidResult{
|
||||||
Stopwatch timer = new Stopwatch();
|
Stopwatch timer = new Stopwatch();
|
||||||
@@ -56,15 +60,16 @@ public class TestStopwatch{
|
|||||||
//Stop the timer
|
//Stop the timer
|
||||||
timer.stop();
|
timer.stop();
|
||||||
//Assert something so the sum isn't ignored during compile
|
//Assert something so the sum isn't ignored during compile
|
||||||
assertNotEquals("You really messed up", sum, Integer.valueOf(0));
|
assertNotEquals(sum, Integer.valueOf(0), "You really messed up");
|
||||||
//Check that the different resolutions work out correctly
|
//Check that the different resolutions work out correctly
|
||||||
Double nano = timer.getNano();
|
Double nano = timer.getNano();
|
||||||
assertEquals("Micro resolution test failed", timer.getMicro(), (nano / 1000D), ALLOWANCE);
|
assertEquals(timer.getMicro(), (nano / 1000D), ALLOWANCE, "Micro resolution test failed");
|
||||||
assertEquals("Milli resolution test failed", timer.getMilli(), (nano / 1000000D), ALLOWANCE);
|
assertEquals(timer.getMilli(), (nano / 1000000D), ALLOWANCE, "Milli resolution test failed");
|
||||||
assertEquals("Second resolution test failed", timer.getSecond(), (nano / 1000000000D), ALLOWANCE);
|
assertEquals(timer.getSecond(), (nano / 1000000000D), ALLOWANCE, "Second resolution test failed");
|
||||||
assertEquals("Minute resolution test failed", timer.getMinute(), (nano / 60000000000D), ALLOWANCE);
|
assertEquals(timer.getMinute(), (nano / 60000000000D), ALLOWANCE, "Minute resolution test failed");
|
||||||
assertEquals("Hour resolution test failed", timer.getHour(), (nano / 3600000000000D), ALLOWANCE);
|
assertEquals(timer.getHour(), (nano / 3600000000000D), ALLOWANCE, "Hour resolution test failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testStringConversion() throws InvalidResult{
|
public void testStringConversion() throws InvalidResult{
|
||||||
//Test nanoseconds
|
//Test nanoseconds
|
||||||
@@ -86,4 +91,19 @@ public class TestStopwatch{
|
|||||||
results = Stopwatch.getStr(1.0e13);
|
results = Stopwatch.getStr(1.0e13);
|
||||||
assertEquals("2.778 hours", results);
|
assertEquals("2.778 hours", results);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testErrors(){
|
||||||
|
Stopwatch timer = new Stopwatch();
|
||||||
|
assertEquals(0.0, timer.getNano(), "Stopwatch failed not started test");
|
||||||
|
|
||||||
|
timer.stop();
|
||||||
|
assertEquals(0.0, timer.getNano(), "Stopwatch failed stop before start test");
|
||||||
|
|
||||||
|
timer.start();
|
||||||
|
assertNotEquals(0.0, timer.getNano(), "Stopwatch failed not stopped test");
|
||||||
|
|
||||||
|
timer.reset();
|
||||||
|
assertEquals(0.0, timer.getNano(), "Stopwatch failed reset test");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,13 +22,12 @@
|
|||||||
package mattrixwv;
|
package mattrixwv;
|
||||||
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
|
||||||
public class TestStringAlgorithms{
|
public class TestStringAlgorithms{
|
||||||
@@ -36,9 +35,9 @@ public class TestStringAlgorithms{
|
|||||||
public void testGetPermutations(){
|
public void testGetPermutations(){
|
||||||
//Test 1
|
//Test 1
|
||||||
String permString = "012";
|
String permString = "012";
|
||||||
ArrayList<String> correctAnswer = new ArrayList<String>(Arrays.asList("012", "021", "102", "120", "201", "210"));
|
List<String> correctAnswer = Arrays.asList("012", "021", "102", "120", "201", "210");
|
||||||
List<String> answer = StringAlgorithms.getPermutations(permString);
|
List<String> answer = StringAlgorithms.getPermutations(permString);
|
||||||
assertEquals("getPermutations failed", correctAnswer, answer);
|
assertEquals(correctAnswer, answer, "getPermutations failed");
|
||||||
}
|
}
|
||||||
@Test
|
@Test
|
||||||
public void testFindNumOccurrence(){
|
public void testFindNumOccurrence(){
|
||||||
@@ -47,17 +46,17 @@ public class TestStringAlgorithms{
|
|||||||
char testChar = 'a';
|
char testChar = 'a';
|
||||||
long correctAnswer = 1;
|
long correctAnswer = 1;
|
||||||
long answer = StringAlgorithms.findNumOccurrence(testString, testChar);
|
long answer = StringAlgorithms.findNumOccurrence(testString, testChar);
|
||||||
assertEquals("FindNumOccurrence 1 failed", correctAnswer, answer);
|
assertEquals(correctAnswer, answer, "FindNumOccurrence 1 failed");
|
||||||
//Test 2
|
//Test 2
|
||||||
testChar = 'd';
|
testChar = 'd';
|
||||||
correctAnswer = 3;
|
correctAnswer = 3;
|
||||||
answer = StringAlgorithms.findNumOccurrence(testString, testChar);
|
answer = StringAlgorithms.findNumOccurrence(testString, testChar);
|
||||||
assertEquals("FindNumOccurrence 2 failed", correctAnswer, answer);
|
assertEquals(correctAnswer, answer, "FindNumOccurrence 2 failed");
|
||||||
//Test 3
|
//Test 3
|
||||||
testChar = 'h';
|
testChar = 'h';
|
||||||
correctAnswer = 0;
|
correctAnswer = 0;
|
||||||
answer = StringAlgorithms.findNumOccurrence(testString, testChar);
|
answer = StringAlgorithms.findNumOccurrence(testString, testChar);
|
||||||
assertEquals("FindNumOccurrence 3 failed", correctAnswer, answer);
|
assertEquals(correctAnswer, answer, "FindNumOccurrence 3 failed");
|
||||||
}
|
}
|
||||||
@Test
|
@Test
|
||||||
public void testIsPalindrome(){
|
public void testIsPalindrome(){
|
||||||
@@ -65,17 +64,17 @@ public class TestStringAlgorithms{
|
|||||||
String str = "101";
|
String str = "101";
|
||||||
boolean correctAnswer = true;
|
boolean correctAnswer = true;
|
||||||
boolean answer = StringAlgorithms.isPalindrome(str);
|
boolean answer = StringAlgorithms.isPalindrome(str);
|
||||||
assertEquals("isPalindrome 1 failed", correctAnswer, answer);
|
assertEquals(correctAnswer, answer, "isPalindrome 1 failed");
|
||||||
//Test 2
|
//Test 2
|
||||||
str = "100";
|
str = "100";
|
||||||
correctAnswer = false;
|
correctAnswer = false;
|
||||||
answer = StringAlgorithms.isPalindrome(str);
|
answer = StringAlgorithms.isPalindrome(str);
|
||||||
assertEquals("isPalindrome 2 failed", correctAnswer, answer);
|
assertEquals(correctAnswer, answer, "isPalindrome 2 failed");
|
||||||
//Test 3
|
//Test 3
|
||||||
str = "";
|
str = "";
|
||||||
correctAnswer = true;
|
correctAnswer = true;
|
||||||
answer = StringAlgorithms.isPalindrome(str);
|
answer = StringAlgorithms.isPalindrome(str);
|
||||||
assertEquals("isPalindrome 3 failed", correctAnswer, answer);
|
assertEquals(correctAnswer, answer, "isPalindrome 3 failed");
|
||||||
}
|
}
|
||||||
@Test
|
@Test
|
||||||
public void testIsPandigital(){
|
public void testIsPandigital(){
|
||||||
@@ -83,36 +82,36 @@ public class TestStringAlgorithms{
|
|||||||
String num = "123456789";
|
String num = "123456789";
|
||||||
boolean correctAnswer = true;
|
boolean correctAnswer = true;
|
||||||
boolean answer = StringAlgorithms.isPandigital(num);
|
boolean answer = StringAlgorithms.isPandigital(num);
|
||||||
assertEquals("isPandigital 1 failed", correctAnswer, answer);
|
assertEquals(correctAnswer, answer, "isPandigital 1 failed");
|
||||||
|
|
||||||
//Test 2
|
//Test 2
|
||||||
num = "123";
|
num = "123";
|
||||||
correctAnswer = true;
|
correctAnswer = true;
|
||||||
answer = StringAlgorithms.isPandigital(num, '1', '3');
|
answer = StringAlgorithms.isPandigital(num, '1', '3');
|
||||||
assertEquals("isPandigital 2 failed", correctAnswer, answer);
|
assertEquals(correctAnswer, answer, "isPandigital 2 failed");
|
||||||
|
|
||||||
//Test 3
|
//Test 3
|
||||||
num = "123";
|
num = "123";
|
||||||
correctAnswer = false;
|
correctAnswer = false;
|
||||||
answer = StringAlgorithms.isPandigital(num);
|
answer = StringAlgorithms.isPandigital(num);
|
||||||
assertEquals("isPandigital 3 failed", correctAnswer, answer);
|
assertEquals(correctAnswer, answer, "isPandigital 3 failed");
|
||||||
|
|
||||||
//Test 4
|
//Test 4
|
||||||
num = "123";
|
num = "123";
|
||||||
correctAnswer = false;
|
correctAnswer = false;
|
||||||
answer = StringAlgorithms.isPandigital(num, '3', '1');
|
answer = StringAlgorithms.isPandigital(num, '3', '1');
|
||||||
assertEquals("inPandigital 4 failed", correctAnswer, answer);
|
assertEquals(correctAnswer, answer, "isPandigital 4 failed");
|
||||||
|
|
||||||
//Test 5
|
//Test 5
|
||||||
num = "1";
|
num = "1";
|
||||||
correctAnswer = true;
|
correctAnswer = true;
|
||||||
answer = StringAlgorithms.isPandigital(num, '1', '1');
|
answer = StringAlgorithms.isPandigital(num, '1', '1');
|
||||||
assertEquals("inPandigital 5 failed", correctAnswer, answer);
|
assertEquals(correctAnswer, answer, "isPandigital 5 failed");
|
||||||
|
|
||||||
//Test 6
|
//Test 6
|
||||||
num = "112";
|
num = "112";
|
||||||
correctAnswer = false;
|
correctAnswer = false;
|
||||||
answer = StringAlgorithms.isPandigital(num, '1', '3');
|
answer = StringAlgorithms.isPandigital(num, '1', '3');
|
||||||
assertEquals("inPandigital 6 failed", correctAnswer, answer);
|
assertEquals(correctAnswer, answer, "isPandigital 6 failed");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
17
version-rules.xml
Normal file
17
version-rules.xml
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ruleset xmlns="http://mojo.codehaus.org/versions-maven-plugin/rule/2.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" comparisonMethod="maven"
|
||||||
|
xsi:schemaLocation="http://mojo.codehaus.org/versions-maven-plugin/rule/2.0.0 https://www.mojohaus.org/versions-maven-plugin/xsd/rule-2.0.0.xsd">
|
||||||
|
<ignoreVersions>
|
||||||
|
<!-- Ignore Alpha's, Beta's, release candidates and milestones -->
|
||||||
|
<ignoreVersion type="regex">(?i).*Alpha(?:-?\d+)?</ignoreVersion>
|
||||||
|
<ignoreVersion type="regex">(?i).*a(?:-?\d+)?</ignoreVersion>
|
||||||
|
<ignoreVersion type="regex">(?i).*Beta(?:-?\d+)?</ignoreVersion>
|
||||||
|
<ignoreVersion type="regex">(?i).*-B(?:-?\d+)?</ignoreVersion>
|
||||||
|
<ignoreVersion type="regex">(?i).*RC(?:-?\d+)?</ignoreVersion>
|
||||||
|
<ignoreVersion type="regex">(?i).*CR(?:-?\d+)?</ignoreVersion>
|
||||||
|
<ignoreVersion type="regex">(?i).*M(?:-?\d+)?</ignoreVersion>
|
||||||
|
</ignoreVersions>
|
||||||
|
<rules>
|
||||||
|
</rules>
|
||||||
|
</ruleset>
|
||||||
Reference in New Issue
Block a user