Added functions to create a string from a vector

This commit is contained in:
2021-06-30 14:02:57 -04:00
parent 16b2a6f792
commit cf8fd4d65e
2 changed files with 92 additions and 26 deletions

View File

@@ -56,15 +56,18 @@ bool testFindNumOccurrence();
bool testFactorial();
bool testIsPalindrome();
bool testToBin();
bool testPrintVector();
int main(){
mee::Stopwatch timer;
bool passedTest = false;
std::vector<boolFn> functions {testGetPrimes, testGetNumPrimes, testIsPrime, testGetFactors, tetsGetDivisors, testGetSum, testGetProduct, testIsFound, testGetPermutations,
testGetFib, testGetAllFib, testBubbleSort, testQuickSort, testSearch, testFindMin, testFindMax, testFindNumOccurrence, testFactorial, testIsPalindrome, testToBin};
testGetFib, testGetAllFib, testBubbleSort, testQuickSort, testSearch, testFindMin, testFindMax, testFindNumOccurrence, testFactorial, testIsPalindrome, testToBin,
testPrintVector};
std::vector<std::string> names {"getPrimes", "getNumPrimes", "isPrime", "getFactors", "getDivisors", "getSum", "getProduct", "isFound", "getPermutations",
"getFib", "getAllFib", "bubbleSort", "quickSort", "search", "findMin", "findMax", "findNumOccurrence", "factorial", "isPalindrome", "toBin"};
"getFib", "getAllFib", "bubbleSort", "quickSort", "search", "findMin", "findMax", "findNumOccurrence", "factorial", "isPalindrome", "toBin",
"testPrintVector"};
//Start doing tests and print out the results of each
for(int cnt = 0;cnt < functions.size();++cnt){
@@ -580,73 +583,116 @@ bool testToBin(){
return true;
}
bool testPrintVector(){
//Test 1
std::vector<int> nums;
std::string correctAnswer = "[]";
std::string answer = mee::printVector(nums);
if(correctAnswer != answer){
return false;
}
//Test 2
nums = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
correctAnswer = "[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]";
answer = mee::printVector(nums);
if(correctAnswer != answer){
return false;
}
//Test 3
nums = {-3, -2, -1, 0, 1, 2, 3};
correctAnswer = "[-3, -2, -1, 0, 1, 2, 3]";
answer = mee::printVector(nums);
if(correctAnswer != answer){
return false;
}
//Test 4
std::vector<std::string> strings = {"A", "B", "C"};
correctAnswer = "[A, B, C]";
answer = mee::printVector(strings);
if(correctAnswer != answer){
return false;
}
//Test 5
strings = {"abc", "def", "ghi"};
correctAnswer = "[abc, def, ghi]";
answer = mee::printVector(strings);
if(correctAnswer != answer){
return false;
}
//If it hasn't failed a test then return true for passing all the tests
return true;
}
/* Results:
Function getPrimes() passed the test
The test took 14.100 microseconds
The test took 9.400 microseconds
Function getNumPrimes() passed the test
The test took 15.100 microseconds
The test took 6.400 microseconds
Function isPrime() passed the test
The test took 300.000 nanoseconds
The test took 200.000 nanoseconds
Function getFactors() passed the test
The test took 10.200 microseconds
The test took 5.400 microseconds
Function getDivisors() passed the test
The test took 5.800 microseconds
Function getSum() passed the test
The test took 9.300 microseconds
Function getProduct() passed the test
The test took 2.000 microseconds
Function getSum() passed the test
The test took 8.500 microseconds
Function getProduct() passed the test
The test took 1.200 microseconds
Function isFound() passed the test
The test took 23.500 microseconds
The test took 7.100 microseconds
Function getPermutations() passed the test
The test took 30.100 microseconds
The test took 8.800 microseconds
Function getFib() passed the test
The test took 228.800 microseconds
The test took 221.400 microseconds
Function getAllFib() passed the test
The test took 9.000 microseconds
The test took 4.100 microseconds
Function bubbleSort() passed the test
The test took 995.215 milliseconds
The test took 1.186 seconds
Function quickSort() passed the test
The test took 3.559 milliseconds
The test took 3.580 milliseconds
Function search() passed the test
The test took 2.800 microseconds
The test took 1.300 microseconds
Function findMin() passed the test
The test took 2.500 microseconds
The test took 1.700 microseconds
Function findMax() passed the test
The test took 2.500 microseconds
The test took 1.600 microseconds
Function findNumOccurrence() passed the test
The test took 1.100 microseconds
The test took 1.400 microseconds
Function factorial() passed the test
@@ -654,9 +700,13 @@ The test took 200.000 nanoseconds
Function isPalindrome() passed the test
The test took 1.500 microseconds
The test took 1.400 microseconds
Function toBin() passed the test
The test took 2.100 microseconds
The test took 9.300 microseconds
Function testPrintVector() passed the test
The test took 9.900 microseconds
*/