mirror of
https://bitbucket.org/Mattrixwv/my-classes.git
synced 2025-12-06 18:23:57 -05:00
Added ability for Stopwatch to be sent to an
ostream
This commit is contained in:
@@ -191,7 +191,13 @@ public:
|
||||
hasStarted = hasStopped = false; //Set the flags as though nothing has happened
|
||||
endTime = startTime = std::chrono::high_resolution_clock::time_point(); //Set the times with a blank time
|
||||
}
|
||||
friend std::ostream& operator<<(std::ostream& out, Stopwatch& timer);
|
||||
}; //end class Stopwatch
|
||||
std::ostream& operator<<(std::ostream& out, Stopwatch& timer){
|
||||
out << timer.getStr();
|
||||
bool num = timer.hasStopped;
|
||||
return out;
|
||||
}
|
||||
} //end namespace mee
|
||||
|
||||
#endif //end STOPWATCH_HPP
|
||||
|
||||
@@ -17,34 +17,34 @@ int main(){
|
||||
std::cout << "Test failed" << std::endl;
|
||||
}
|
||||
catch(mee::Stopwatch::invalidTimeResolution){
|
||||
std::cout << "There was an invalid time resolution" << std::endl;
|
||||
std::cout << "There was an invalid time resolution\n";
|
||||
std::cout << "Test failed" << std::endl;
|
||||
}
|
||||
catch(mee::Stopwatch::timeBeforeStart){
|
||||
std::cout << "Tried to get time before the stopwatch was started" << std::endl;
|
||||
std::cout << "Tried to get time before the stopwatch was started\n";
|
||||
std::cout << "Test failed" << std::endl;
|
||||
}
|
||||
catch(mee::Stopwatch::stopBeforeStart){
|
||||
std::cout << "Tried to stop the stopwatch before it was started" << std::endl;
|
||||
std::cout << "Tried to stop the stopwatch before it was started\n";
|
||||
std::cout << "Test successful" << std::endl;
|
||||
}
|
||||
|
||||
//Try to get the time on it without starting it
|
||||
std::cout << "Testing the timeBeforeStart error" << std::endl;
|
||||
try{
|
||||
std::cout << timer.getStr() << std::endl;
|
||||
std::cout << timer.getStr() << '\n';
|
||||
std::cout << "Test failed" << std::endl;
|
||||
}
|
||||
catch(mee::Stopwatch::invalidTimeResolution){
|
||||
std::cout << "There was an invalid time resolution" << std::endl;
|
||||
std::cout << "There was an invalid time resolution\n";
|
||||
std::cout << "Test failed" << std::endl;
|
||||
}
|
||||
catch(mee::Stopwatch::timeBeforeStart){
|
||||
std::cout << "Tried to get time before the stopwatch was started" << std::endl;
|
||||
std::cout << "Tried to get time before the stopwatch was started\n";
|
||||
std::cout << "Test successful" << std::endl;
|
||||
}
|
||||
catch(mee::Stopwatch::stopBeforeStart){
|
||||
std::cout << "Tried to stop the stopwatch before it was started" << std::endl;
|
||||
std::cout << "Tried to stop the stopwatch before it was started\n";
|
||||
std::cout << "Test failed" << std::endl;
|
||||
}
|
||||
|
||||
@@ -56,19 +56,20 @@ int main(){
|
||||
int num = cnt;
|
||||
}
|
||||
timer.stop();
|
||||
std::cout << "It took " << timer.getStr() << " to complete this loop" << std::endl;
|
||||
std::cout << "It took " << timer.getStr() << " to complete this loop\n";
|
||||
std::cout << "It took " << timer << " to complete this loop\n";
|
||||
std::cout << "Test successful" << std::endl;
|
||||
}
|
||||
catch(mee::Stopwatch::invalidTimeResolution){
|
||||
std::cout << "There was an invalid time resolution" << std::endl;
|
||||
std::cout << "There was an invalid time resolution\n";
|
||||
std::cout << "Test failed" << std::endl;
|
||||
}
|
||||
catch(mee::Stopwatch::timeBeforeStart){
|
||||
std::cout << "Tried to get time before the stopwatch was started" << std::endl;
|
||||
std::cout << "Tried to get time before the stopwatch was started\n";
|
||||
std::cout << "Test failed" << std::endl;
|
||||
}
|
||||
catch(mee::Stopwatch::stopBeforeStart){
|
||||
std::cout << "Tried to stop the stopwatch before it was started" << std::endl;
|
||||
std::cout << "Tried to stop the stopwatch before it was started\n";
|
||||
std::cout << "Test failed" << std::endl;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user