mirror of
https://bitbucket.org/Mattrixwv/my-classes.git
synced 2025-12-06 18:23:57 -05:00
89 lines
2.7 KiB
C++
89 lines
2.7 KiB
C++
//myClasses/testStopwatch.cpp
|
|
//Matthew Ellison
|
|
// Created: 02-12-19
|
|
//Modified: 02-12-19
|
|
//This file is a simple test for the Stopwatch class
|
|
|
|
|
|
#include <iostream>
|
|
#include "Stopwatch.hpp"
|
|
|
|
int main(){
|
|
mee::Stopwatch timer;
|
|
//Try to stop the timer without starting it
|
|
std::cout << "Testing the stopBeforeStart error" << std::endl;
|
|
try{
|
|
timer.stop();
|
|
std::cout << "Test failed" << std::endl;
|
|
}
|
|
catch(mee::Stopwatch::invalidTimeResolution){
|
|
std::cout << "There was an invalid time resolution" << std::endl;
|
|
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 << "Test failed" << std::endl;
|
|
}
|
|
catch(mee::Stopwatch::stopBeforeStart){
|
|
std::cout << "Tried to stop the stopwatch before it was started" << std::endl;
|
|
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 << "Test failed" << std::endl;
|
|
}
|
|
catch(mee::Stopwatch::invalidTimeResolution){
|
|
std::cout << "There was an invalid time resolution" << std::endl;
|
|
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 << "Test successful" << std::endl;
|
|
}
|
|
catch(mee::Stopwatch::stopBeforeStart){
|
|
std::cout << "Tried to stop the stopwatch before it was started" << std::endl;
|
|
std::cout << "Test failed" << std::endl;
|
|
}
|
|
|
|
//Use it correctly
|
|
std::cout << "Using the class correctly" << std::endl;
|
|
try{
|
|
timer.start();
|
|
for(int cnt = 0;cnt < 1000000;++cnt){
|
|
int num = cnt;
|
|
}
|
|
timer.stop();
|
|
std::cout << "It took " << timer.getStr() << " to complete this loop" << std::endl;
|
|
std::cout << "Test successful" << std::endl;
|
|
}
|
|
catch(mee::Stopwatch::invalidTimeResolution){
|
|
std::cout << "There was an invalid time resolution" << std::endl;
|
|
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 << "Test failed" << std::endl;
|
|
}
|
|
catch(mee::Stopwatch::stopBeforeStart){
|
|
std::cout << "Tried to stop the stopwatch before it was started" << std::endl;
|
|
std::cout << "Test failed" << std::endl;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
/* Results:
|
|
Testing the stopBeforeStart error
|
|
Tried to stop the stopwatch before it was started
|
|
Test successful
|
|
Testing the timeBeforeStart error
|
|
Tried to get time before the stopwatch was started
|
|
Test successful
|
|
Using the class correctly
|
|
It took 1.855 milliseconds to complete this loop
|
|
Test successful
|
|
*/
|