Added test for isPrime

This commit is contained in:
2020-10-30 15:28:37 -04:00
parent b54a223934
commit a1e0d53e8d

View File

@@ -38,6 +38,7 @@ typedef bool (*boolFn)();
//Some of the functions are overloaded, so I test all overloaded functions in each function
bool testGetPrimes();
bool testGetNumPrimes();
bool testIsPrime();
bool testGetFactors();
bool tetsGetDivisors();
bool testGetSum();
@@ -57,9 +58,9 @@ bool testFindNumOccurrence();
int main(){
mee::Stopwatch timer;
bool passedTest = false;
std::vector<boolFn> functions {testGetPrimes, testGetNumPrimes, testGetFactors, tetsGetDivisors, testGetSum, testGetProduct, testIsFound, testGetPermutations,
std::vector<boolFn> functions {testGetPrimes, testGetNumPrimes, testIsPrime, testGetFactors, tetsGetDivisors, testGetSum, testGetProduct, testIsFound, testGetPermutations,
testGetFib, testGetAllFib, testBubbleSort, testQuickSort, testSearch, testFindMin, testFindMax, testFindNumOccurrence};
std::vector<std::string> names {"getPrimes", "getNumPrimes", "getFactors", "getDivisors", "getSum", "getProduct", "isFound", "getPermutations",
std::vector<std::string> names {"getPrimes", "getNumPrimes", "isPrime", "getFactors", "getDivisors", "getSum", "getProduct", "isFound", "getPermutations",
"getFib", "getAllFib", "bubbleSort", "quickSort", "search", "findMin", "findMax", "findNumOccurrence"};
//Start doing tests and print out the results of each
@@ -103,6 +104,32 @@ bool testGetNumPrimes(){
return true;
}
bool testIsPrime(){
int64_t num = 2;
bool correctAnswer = true;
bool answer = mee::isPrime(num);
if(correctAnswer != answer){
return false;
}
num = 97;
correctAnswer = true;
answer = mee::isPrime(num);
if(correctAnswer != answer){
return false;
}
num = 1000;
correctAnswer = false;
answer = mee::isPrime(num);
if(correctAnswer != answer){
return false;
}
//If the false was not triggered it must have passed all tests
return true;
}
bool testGetFactors(){
std::vector<uint64_t> correctAnswer {2, 2, 5, 5};
uint64_t number = 100;