Added test for new function

This commit is contained in:
2020-07-09 15:46:46 -04:00
parent 2bebbd2db9
commit 9a64623008

View File

@@ -1,7 +1,7 @@
//myClasses/testStopwatch.cpp
//Matthew Ellison
// Created: 02-12-19
//Modified: 02-12-19
//Modified: 07-09-20
//This file is a simple test for the Stopwatch class
@@ -73,6 +73,42 @@ int main(){
std::cout << "Test failed" << std::endl;
}
//Test string function
bool failedTimeResolutionTests = false;
std::string results = mee::Stopwatch::getStr(1.0);
if(results != "1.000 nanoseconds"){
failedTimeResolutionTests = true;
std::cout << "Failed the nanosecond test" << std::endl;
}
results = mee::Stopwatch::getStr(1.0e3);
if(results != "1.000 microseconds"){
failedTimeResolutionTests = true;
std::cout << "Failed the microsecond test" << std::endl;
}
results = mee::Stopwatch::getStr(1.0e6);
if(results != "1.000 milliseconds"){
failedTimeResolutionTests = true;
std::cout << "Failed the millisecond test" << std::endl;
}
results = mee::Stopwatch::getStr(1.0e9);
if(results != "1.000 seconds"){
failedTimeResolutionTests = true;
std::cout << "Failed the second test" << std::endl;
}
results = mee::Stopwatch::getStr(1.0e12);
if(results != "16.667 minutes"){
failedTimeResolutionTests = true;
std::cout << "Failed the minute test" << std::endl;
}
results = mee::Stopwatch::getStr(1.0e13);
if(results != "2.778 hours"){
failedTimeResolutionTests = true;
std::cout << "Failed the hour test" << std::endl;
}
if(!failedTimeResolutionTests){
std::cout << "Passed all string resolution tests" << std::endl;
}
return 0;
}