mirror of
https://bitbucket.org/Mattrixwv/my-classes.git
synced 2025-12-06 18:23:57 -05:00
Added test for isPrime
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user