//Java/JavaClasses/testAlgorithms.java
//Matthew Ellison
// Created: 03-02-19
//Modified: 03-24-19
//This program runs tests on all function in the Algorithms library
/*
Copyright (C) 2019 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
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see .
*/
import mattrixwv.Algorithms;
import mattrixwv.Stopwatch;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
public class testAlgorithms{
public static void main(String[] argv){
//Create a timer so you can time the execution time of the tests
Stopwatch timer = new Stopwatch();
timer.start();
//Test getPrimes
testGetPrimes();
timer.stop();
System.out.println("It took " + timer.getStr() + " to run this test\n");
//Test getNumPrimes
timer.start();
testGetNumPrimes();
timer.stop();
System.out.println("It took " + timer.getStr() + " to run this test\n");
//Test getFactors
timer.start();
testGetFactors();
timer.stop();
System.out.println("It took " + timer.getStr() + " to run this test\n");
//Test getDivisors
timer.start();
testGetDivisors();
timer.stop();
System.out.println("It took " + timer.getStr() + " to run this test\n");
//Test getFib
timer.start();
testGetFib();
timer.stop();
System.out.println("It took " + timer.getStr() + " to run this test\n");
//Test getAllFib
timer.start();
testGetAllFib();
timer.stop();
System.out.println("It took " + timer.getStr() + " to run this test\n");
//Test factorial
timer.start();
testFactorial();
timer.stop();
System.out.println("It took " + timer.getStr() + " to run this test\n");
//Tets getSum
timer.start();
testGetSum();
timer.stop();
System.out.println("It took " + timer.getStr() + " to run this test\n");
//Test getProd
timer.start();
testGetProd();
timer.stop();
System.out.println("It took " + timer.getStr() + " to run this test\n");
//Test getProd
timer.start();
testIsFound();
timer.stop();
System.out.println("It took " + timer.getStr() + " to run this test\n");
timer.start();
testGetPermutations();
timer.stop();
System.out.println("It took " + timer.getStr() + " to run this test\n");
//Print a closing message
System.out.println("Tests completed");
}
//This function tests the getPrimes function
private static void testGetPrimes(){
Boolean failed = false; //Holds whether a test was failed
//Test 1
ArrayList correctAnswer = new ArrayList(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));
Integer topNum = 100;
ArrayList answer = Algorithms.getPrimes(topNum);
//Print an error message if the function returned the wrong answer
if(!correctAnswer.equals(answer)){
System.out.println("getPrimes failed the first test");
failed = true;
}
//Test 2
ArrayList longCorrectAnswer = new ArrayList(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));
Long longTopNum = 100L;
ArrayList longAnswer = Algorithms.getPrimes(longTopNum);
//Print an error message if the function returned the wrong answer
if(!longCorrectAnswer.equals(longAnswer)){
System.out.println("getPrimes failed the second test");
failed = true;
}
//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(100);
ArrayList bigAnswer = Algorithms.getPrimes(bigTopNum);
//Print an error message if the function returned the wrong answer
if(!bigCorrectAnswer.equals(bigAnswer)){
System.out.println("getPrimes failed the third test");
failed = true;
}
//Print a message if all of the tests passed
if(!failed){
System.out.println("getPrimes passed all tests");
}
}
//This function tests the getNumPrimes function
private static void testGetNumPrimes(){
Boolean failed = false; //Holds whether a test was failed
//Test 1
ArrayList correctAnswer = new ArrayList(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));
Integer numPrimes = 25;
ArrayList answer = Algorithms.getNumPrimes(numPrimes);
//Print an error message if the function return the wrong answer
if(!correctAnswer.equals(answer)){
System.out.println("getNumPrimes failed at the first test");
failed = true;
}
//Test 2
ArrayList longCorrectAnswer = new ArrayList(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));
Long longNumPrimes = 25L;
ArrayList longAnswer = Algorithms.getNumPrimes(longNumPrimes);
//Print an error message if the function return the wrong answer
if(!longCorrectAnswer.equals(longAnswer)){
System.out.println("getNumPrimes failed at the second test");
failed = true;
}
//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);
//Print an error message if the function returned the wrong answer
if(!bigCorrectAnswer.equals(bigAnswer)){
System.out.println("getPrimes failed the third test");
failed = true;
}
//Print a message if all of the tests passed
if(!failed){
System.out.println("getNumPrimes passed all tests");
}
}
//This function tests the getFactors function
private static void testGetFactors(){
Boolean failed = false; //Holds whether a test was failed
//Test 1
ArrayList correctAnswer = new ArrayList(Arrays.asList(2, 2, 5, 5));
Integer number = 100;
ArrayList answer = Algorithms.getFactors(number);
//Print an error message if the function returned the wrong answer
if(!correctAnswer.equals(answer)){
System.out.println("getFactors failed the first test");
failed = true;
}
//Test 2
correctAnswer = new ArrayList(Arrays.asList(2, 7, 7));
number = 98;
answer = Algorithms.getFactors(number);
//Print an error message if the function returned the wrong answer
if(!correctAnswer.equals(answer)){
System.out.println("getFactors failed the second test");
failed = true;
}
//Test 3
ArrayList longCorrectAnswer = new ArrayList(Arrays.asList(2L, 2L, 5L, 5L));
Long longNumber = 100L;
ArrayList longAnswer = Algorithms.getFactors(longNumber);
//Print an error message if the function returned the wrong answer
if(!longCorrectAnswer.equals(longAnswer)){
System.out.println("getFactors failed the third test");
failed = true;
}
//Test 4
ArrayList bigCorrectAnswer = new ArrayList(Arrays.asList(BigInteger.valueOf(2), BigInteger.valueOf(7), BigInteger.valueOf(7)));
BigInteger bigNumber = BigInteger.valueOf(98);
ArrayList bigAnswer = Algorithms.getFactors(bigNumber);
//Print an error message if the function returned the wrong answer
if(!bigCorrectAnswer.equals(bigAnswer)){
System.out.println("getFactors failed the fourth test");
failed = true;
}
//Print a message if all of the tests passed
if(!failed){
System.out.println("getFactors passed all tests");
}
}
//This function tests the getDivisors function
private static void testGetDivisors(){
Boolean failed = false; //Holds whether a test was failed
//Test 1
ArrayList correctAnswer = new ArrayList(Arrays.asList(1, 2, 4, 5, 10, 20, 25, 50, 100));
Integer topNum = 100;
ArrayList answer = Algorithms.getDivisors(topNum);
//Print an error message if the function returned the wrong answer
if(!correctAnswer.equals(answer)){
System.out.println("getDivisors failed the first test");
failed = true;
}
//Test 2
ArrayList longCorrectAnswer = new ArrayList(Arrays.asList(1L, 2L, 4L, 5L, 10L, 20L, 25L, 50L, 100L));
Long longTopNum = 100L;
ArrayList longAnswer = Algorithms.getDivisors(longTopNum);
//Print an error message if the function returned the wrong answer
if(!longCorrectAnswer.equals(longAnswer)){
System.out.println("getDivisors failed the second test");
failed = true;
}
//Test 3
ArrayList bigCorrectAnswer = new ArrayList(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);
ArrayList bigAnswer = Algorithms.getDivisors(bigTopNum);
//Print an error message if the function returned the wrong answer
if(!bigCorrectAnswer.equals(bigAnswer)){
System.out.println("getDivisors failed the third test");
failed = true;
}
//Print a message if all of the tests passed
if(!failed){
System.out.println("getDivisors passed all tests");
}
}
//This function tests the getFib function
private static void testGetFib(){
Boolean failed = false; //Holds whether a test was failed
//Test 1
Integer correctAnswer = 144;
Integer number = 12;
Integer answer = Algorithms.getFib(number);
//Print an error message if the function returned the wrong answer
if(!correctAnswer.equals(answer)){
System.out.println("getFib failed the first test");
failed = true;
}
//Test 2
correctAnswer = 6765;
number = 20;
answer = Algorithms.getFib(number);
//Print an error message if the function returned the wrong answer
if(!correctAnswer.equals(answer)){
System.out.println("getFib failed the seconds test");
failed = true;
}
//Test 3
Long longCorrectAnswer = 6765L;
Long longNumber = 20L;
Long longAnswer = Algorithms.getFib(longNumber);
//Print an error message if the function returned the wrong answer
if(!longCorrectAnswer.equals(longAnswer)){
System.out.println("getFib failed the third test");
failed = true;
}
//Test 4
BigInteger bigCorrectAnswer = new BigInteger("1070066266382758936764980584457396885083683896632151665013235203375314520604694040621889147582489792657804694888177591957484336466672569959512996030461262748092482186144069433051234774442750273781753087579391666192149259186759553966422837148943113074699503439547001985432609723067290192870526447243726117715821825548491120525013201478612965931381792235559657452039506137551467837543229119602129934048260706175397706847068202895486902666185435124521900369480641357447470911707619766945691070098024393439617474103736912503231365532164773697023167755051595173518460579954919410967778373229665796581646513903488154256310184224190259846088000110186255550245493937113651657039447629584714548523425950428582425306083544435428212611008992863795048006894330309773217834864543113205765659868456288616808718693835297350643986297640660000723562917905207051164077614812491885830945940566688339109350944456576357666151619317753792891661581327159616877487983821820492520348473874384736771934512787029218636250627816");
BigInteger bigNumber = BigInteger.valueOf(4782);
BigInteger bigAnswer = Algorithms.getFib(bigNumber);
//Print an error message if the function returned the wrong answer
if(!bigCorrectAnswer.equals(bigAnswer)){
System.out.println("getFib failed the fourth test");
failed = true;
}
//Print a message if all of the tests passed
if(!failed){
System.out.println("getFib passed all tests");
}
}
//This function tests the getAllFib function
private static void testGetAllFib(){
Boolean failed = false; //Holds whether a test was failed
//Test 1
ArrayList correctAnswer = new ArrayList(Arrays.asList(1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89));
Integer highestNumber = 100;
ArrayList answer = Algorithms.getAllFib(highestNumber);
//Print an error message if the function returned the wrong answer
if(!correctAnswer.equals(answer)){
System.out.println("getAllFib failed the first test");
failed = true;
}
//Test 2
correctAnswer = new ArrayList(Arrays.asList(1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987));
highestNumber = 1000;
answer = Algorithms.getAllFib(highestNumber);
//Print an error message if the function returned the wrong answer
if(!correctAnswer.equals(answer)){
System.out.println("getAllFib failed the second test");
failed = true;
}
//Test 3
ArrayList longCorrectAnswer = new ArrayList(Arrays.asList(1L, 1L, 2L, 3L, 5L, 8L, 13L, 21L, 34L, 55L, 89L, 144L, 233L, 377L, 610L, 987L));
Long longHighestNumber = 1000L;
ArrayList longAnswer = Algorithms.getAllFib(longHighestNumber);
//Print an error message if the function returned the wrong answer
if(!longCorrectAnswer.equals(longAnswer)){
System.out.println("getAllFib failed the third test");
failed = true;
}
//Test 4
ArrayList bigCorrectAnswer = new ArrayList(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)));
BigInteger bigHighestNumber = BigInteger.valueOf(100);
ArrayList bigAnswer = Algorithms.getAllFib(bigHighestNumber);
//Print an error message if the function returned the wrong answer
if(!bigCorrectAnswer.equals(bigAnswer)){
System.out.println("getAllFib failed the fourth test");
failed = true;
}
//Print a message if all of the tests passed
if(!failed){
System.out.println("getAllFib passed all tests");
}
}
//This function tests the factorial function
private static void testFactorial(){
Boolean failed = false; //Holds whether a test was failed
//Test 1
Integer correctAnswer = 720;
Integer number = 6;
Integer answer = Algorithms.factorial(number);
//Print a message if the function returned the wrong answer
if(!correctAnswer.equals(answer)){
System.out.println("factorial failed the first test");
failed = true;
}
//Test 2
correctAnswer = 479001600;
number = 12;
answer = Algorithms.factorial(number);
//Print a message if the function returned the wrong answer
if(!correctAnswer.equals(answer)){
System.out.println("factorial failed the first test");
failed = true;
}
//Test 3
Long correctAnswerLong = 720L;
Long numberLong = 6L;
Long answerLong = Algorithms.factorial(numberLong);
//Print a message if the function returned the wrong answer
if(!correctAnswerLong.equals(answerLong)){
System.out.println("factorial failed the first test");
failed = true;
}
//Test 4
correctAnswerLong = 479001600L;
numberLong = 12L;
answerLong = Algorithms.factorial(numberLong);
//Print a message if the function returned the wrong answer
if(!correctAnswerLong.equals(answerLong)){
System.out.println("factorial failed the first test");
failed = true;
}
//Test 5
correctAnswerLong = 2432902008176640000L;
numberLong = 20L;
answerLong = Algorithms.factorial(numberLong);
//Print a message if the function returned the wrong answer
if(!correctAnswerLong.equals(answerLong)){
System.out.println("factorial failed the first test");
failed = true;
}
//Test 6
BigInteger correctAnswerBig = BigInteger.valueOf(720L);
BigInteger numberBig = BigInteger.valueOf(6);
BigInteger answerBig = Algorithms.factorial(numberBig);
//Print a message if the function returned the wrong answer
if(!correctAnswerBig.equals(answerBig)){
System.out.println("factorial failed the first test");
failed = true;
}
//Test 7
correctAnswerBig = BigInteger.valueOf(479001600L);
numberBig = BigInteger.valueOf(12);
answerBig = Algorithms.factorial(numberBig);
//Print a message if the function returned the wrong answer
if(!correctAnswerBig.equals(answerBig)){
System.out.println("factorial failed the first test");
failed = true;
}
//Test 8
correctAnswerBig = BigInteger.valueOf(2432902008176640000L);
numberBig = BigInteger.valueOf(20L);
answerBig = Algorithms.factorial(numberBig);
//Print a message if the function returned the wrong answer
if(!correctAnswerBig.equals(answerBig)){
System.out.println("factorial failed the first test");
failed = true;
}
//Test 9
correctAnswerBig = new BigInteger("265252859812191058636308480000000");
numberBig = BigInteger.valueOf(30L);
answerBig = Algorithms.factorial(numberBig);
//Print a message if the function returned the wrong answer
if(!correctAnswerBig.equals(answerBig)){
System.out.println("factorial failed the first test");
failed = true;
}
//Print a message if all of the tests passed
if(!failed){
System.out.println("factorial passed all tests");
}
}
//This function tests the getSum function
private static void testGetSum(){
Boolean failed = false; //Holds whether a test was failed
//Test 1
Integer correctAnswer = 0;
ArrayList numbers = new ArrayList();
Integer answer = Algorithms.getSum(numbers);
//Print a message if the function returned the wrong answer
if(!correctAnswer.equals(answer)){
System.out.println("getSum failed the first test");
failed = true;
}
//Test 2
correctAnswer = 118;
numbers = new ArrayList(Arrays.asList(2, 2, 3, 3, 4, 4, 100));
answer = Algorithms.getSum(numbers);
//Print a message if the function returned the wrong answer
if(!correctAnswer.equals(answer)){
System.out.println("getSum failed the second test");
failed = true;
}
//Test 3
Long longCorrectAnswer = 118L;
ArrayList longNumbers = new ArrayList(Arrays.asList(2L, 2L, 3L, 3L, 4L, 4L, 100L));
Long longAnswer = Algorithms.getLongSum(longNumbers);
//Print a message if the function returned the wrong answer
if(!longCorrectAnswer.equals(longAnswer)){
System.out.println("getSum failed the third test");
failed = true;
}
//Test 4
BigInteger bigCorrectAnswer = BigInteger.valueOf(118);
ArrayList bigNumbers = new ArrayList(Arrays.asList(BigInteger.valueOf(2), BigInteger.valueOf(2), BigInteger.valueOf(3), BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(4), BigInteger.valueOf(100)));
BigInteger bigAnswer = Algorithms.getBigSum(bigNumbers);
//Print a message if the function returned the wrong answer
if(!bigCorrectAnswer.equals(bigAnswer)){
System.out.println("getSum failed the fourth test");
failed = true;
}
//Print a message if all of the tests passed
if(!failed){
System.out.println("getSum passed all tests");
}
}
//This function tests the getProd function
private static void testGetProd(){
Boolean failed = false; //Holds whether a test was failed
//Test 1
Integer correctAnswer = 0;
ArrayList numbers = new ArrayList();
Integer answer = Algorithms.getProd(numbers);
//Print a message if the function returned the wrong answer
if(!correctAnswer.equals(answer)){
System.out.println("getProd failed the first test");
failed = true;
}
//Test 2
correctAnswer = 57600;
numbers = new ArrayList(Arrays.asList(2, 2, 3, 3, 4, 4, 100));
answer = Algorithms.getProd(numbers);
//Print a message if the function returned the wrong answer
if(!correctAnswer.equals(answer)){
System.out.println("getProd failed the second test");
failed = true;
}
//Test 3
Long longCorrectAnswer = 57600L;
ArrayList longNumbers = new ArrayList(Arrays.asList(2L, 2L, 3L, 3L, 4L, 4L, 100L));
Long longAnswer = Algorithms.getLongProd(longNumbers);
//Print a message if the function returned the wrong answer
if(!longCorrectAnswer.equals(longAnswer)){
System.out.println("getProd failed the third test");
failed = true;
}
//Test 4
BigInteger bigCorrectAnswer = BigInteger.valueOf(57600);
ArrayList bigNumbers = new ArrayList(Arrays.asList(BigInteger.valueOf(2), BigInteger.valueOf(2), BigInteger.valueOf(3), BigInteger.valueOf(3), BigInteger.valueOf(4), BigInteger.valueOf(4), BigInteger.valueOf(100)));
BigInteger bigAnswer = Algorithms.getBigProd(bigNumbers);
//Print a message if the function returned the wrong answer
if(!bigCorrectAnswer.equals(bigAnswer)){
System.out.println("getProd failed the fourth test");
failed = true;
}
//Print a message if all of the tests passed
if(!failed){
System.out.println("getProd passed all tests");
}
}
//This function tests the isFound functions
private static void testIsFound(){
Boolean failed = false; //Holds whether a test was failed
//Test 1
Boolean correctAnswer = true;
ArrayList numbers = new ArrayList(Arrays.asList(0, 1, 2, 3, 4, 5, 6, 7, 8, 9));
Boolean answer = Algorithms.isFound(numbers, 0);
if(!answer.equals(correctAnswer)){
System.out.println("isFound failed the first test");
System.out.println("compare = " + answer.compareTo(correctAnswer));
failed = true;
}
//Test 2
correctAnswer = true;
numbers = new ArrayList(Arrays.asList(0, 1, 2, 3, 4, 5, 6, 7, 8, 9));
answer = Algorithms.isFound(numbers, 9);
if(!answer.equals(correctAnswer)){
System.out.println("isFound failed the second test");
failed = true;
}
//Test 3
correctAnswer = true;
numbers = new ArrayList(Arrays.asList(0, 1, 2, 3, 4, 5, 6, 7, 8, 9));
answer = Algorithms.isFound(numbers, 5);
if(!answer.equals(correctAnswer)){
System.out.println("isFound failed the third test");
failed = true;
}
//Test 4
correctAnswer = false;
numbers = new ArrayList(Arrays.asList(0, 1, 2, 3, 4, 5, 6, 7, 8, 9));
answer = Algorithms.isFound(numbers, 10);
if(!answer.equals(correctAnswer)){
System.out.println("isFound failed the fourth test");
failed = true;
}
//Test 5
correctAnswer = true;
ArrayList longNumbers = new ArrayList(Arrays.asList(0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L));
answer = Algorithms.isLongFound(longNumbers, 0L);
if(!answer.equals(correctAnswer)){
System.out.println("isFound failed the fifth test");
failed = true;
}
//Test 6
correctAnswer = true;
longNumbers = new ArrayList(Arrays.asList(0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L));
answer = Algorithms.isLongFound(longNumbers, 9L);
if(!answer.equals(correctAnswer)){
System.out.println("isFound failed the sixth test");
failed = true;
}
//Test 7
correctAnswer = true;
longNumbers = new ArrayList(Arrays.asList(0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L));
answer = Algorithms.isLongFound(longNumbers, 5L);
if(!answer.equals(correctAnswer)){
System.out.println("isFound failed the seventh test");
failed = true;
}
//Test 8
correctAnswer = false;
longNumbers = new ArrayList(Arrays.asList(0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L));
answer = Algorithms.isLongFound(longNumbers, 10L);
if(!answer.equals(correctAnswer)){
System.out.println("isFound failed the eighth test");
failed = true;
}
//Test 9
correctAnswer = true;
ArrayList bigNumbers = new ArrayList(Arrays.asList(BigInteger.valueOf(0L), BigInteger.valueOf(1L), BigInteger.valueOf(2L), BigInteger.valueOf(3L), BigInteger.valueOf(4L), BigInteger.valueOf(5L), BigInteger.valueOf(6L), BigInteger.valueOf(7L), BigInteger.valueOf(8L), BigInteger.valueOf(9L)));
answer = Algorithms.isBigFound(bigNumbers, BigInteger.valueOf(0L));
if(!answer.equals(correctAnswer)){
System.out.println("isFound failed the nineth test");
failed = true;
}
//Test 10
correctAnswer = true;
bigNumbers = new ArrayList(Arrays.asList(BigInteger.valueOf(0L), BigInteger.valueOf(1L), BigInteger.valueOf(2L), BigInteger.valueOf(3L), BigInteger.valueOf(4L), BigInteger.valueOf(5L), BigInteger.valueOf(6L), BigInteger.valueOf(7L), BigInteger.valueOf(8L), BigInteger.valueOf(9L)));
answer = Algorithms.isBigFound(bigNumbers, BigInteger.valueOf(9L));
if(!answer.equals(correctAnswer)){
System.out.println("isFound failed the tenth test");
failed = true;
}
//Test 11
correctAnswer = true;
bigNumbers = new ArrayList(Arrays.asList(BigInteger.valueOf(0L), BigInteger.valueOf(1L), BigInteger.valueOf(2L), BigInteger.valueOf(3L), BigInteger.valueOf(4L), BigInteger.valueOf(5L), BigInteger.valueOf(6L), BigInteger.valueOf(7L), BigInteger.valueOf(8L), BigInteger.valueOf(9L)));
answer = Algorithms.isBigFound(bigNumbers, BigInteger.valueOf(5L));
if(!answer.equals(correctAnswer)){
System.out.println("isFound failed the eleventh test");
failed = true;
}
//Test 12
correctAnswer = false;
bigNumbers = new ArrayList(Arrays.asList(BigInteger.valueOf(0L), BigInteger.valueOf(1L), BigInteger.valueOf(2L), BigInteger.valueOf(3L), BigInteger.valueOf(4L), BigInteger.valueOf(5L), BigInteger.valueOf(6L), BigInteger.valueOf(7L), BigInteger.valueOf(8L), BigInteger.valueOf(9L)));
answer = Algorithms.isBigFound(bigNumbers, BigInteger.valueOf(10L));
if(!answer.equals(correctAnswer)){
System.out.println("isFound failed the twelth test");
failed = true;
}
//Print a message if all of the tests passed
if(!failed){
System.out.println("isFound passed all tests");
}
}
//This function tests the getPermutations function
private static void testGetPermutations(){
Boolean failed = false;
//Test 1
String permString = "012";
ArrayList correctAnswer = new ArrayList(Arrays.asList("012", "021", "102", "120", "201", "210"));
ArrayList answer = Algorithms.getPermutations(permString);
if(!answer.equals(correctAnswer)){
System.out.println("getPermutations failed the first test");
System.out.println(answer.toString());
failed = true;
}
//Print a message if all of the tests passed
if(!failed){
System.out.println("getPermutations passed all tests");
}
}
}
/* Results:
getPrimes passed all tests
It took 5.209 milliseconds to run this test
getNumPrimes passed all tests
It took 1.464 milliseconds to run this test
getFactors passed all tests
It took 456.699 microseconds to run this test
getDivisors passed all tests
It took 428.300 microseconds to run this test
getFib passed all tests
It took 6.107 milliseconds to run this test
getAllFib passed all tests
It took 708.100 microseconds to run this test
factorial passed all tests
It took 522.200 microseconds to run this test
getSum passed all tests
It took 1.736 milliseconds to run this test
getProd passed all tests
It took 541.600 microseconds to run this test
isFound passed all tests
It took 537.700 microseconds to run this test
getPermutations passed all tests
It took 336.500 microseconds to run this test
Tests completed
*/