diff --git a/testAlgorithms.cpp b/testAlgorithms.cpp index 318cecb..934b53f 100644 --- a/testAlgorithms.cpp +++ b/testAlgorithms.cpp @@ -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 functions {testGetPrimes, testGetNumPrimes, testGetFactors, tetsGetDivisors, testGetSum, testGetProduct, testIsFound, testGetPermutations, + std::vector functions {testGetPrimes, testGetNumPrimes, testIsPrime, testGetFactors, tetsGetDivisors, testGetSum, testGetProduct, testIsFound, testGetPermutations, testGetFib, testGetAllFib, testBubbleSort, testQuickSort, testSearch, testFindMin, testFindMax, testFindNumOccurrence}; - std::vector names {"getPrimes", "getNumPrimes", "getFactors", "getDivisors", "getSum", "getProduct", "isFound", "getPermutations", + std::vector 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 correctAnswer {2, 2, 5, 5}; uint64_t number = 100;