mirror of
https://bitbucket.org/Mattrixwv/pytutorial.git
synced 2025-12-06 18:23:57 -05:00
Added new tests for different resolutions of time
This commit is contained in:
@@ -6,24 +6,42 @@
|
|||||||
|
|
||||||
from Stopwatch import Stopwatch
|
from Stopwatch import Stopwatch
|
||||||
|
|
||||||
|
#Start of the tests
|
||||||
timer = Stopwatch()
|
timer = Stopwatch()
|
||||||
|
|
||||||
|
print("BEGIN TEST\n")
|
||||||
|
#Tests that should cause faults
|
||||||
print("Trying to print the time before it has been started:")
|
print("Trying to print the time before it has been started:")
|
||||||
print(str(timer.getTime()))
|
print(str(timer.getTime()))
|
||||||
timer.stop()
|
timer.stop()
|
||||||
print("Trying to print the time after stop was called, but before start was")
|
print("Trying to print the time after stop was called, but before start was:")
|
||||||
print(str(timer.getTime()))
|
print(str(timer.getTime()))
|
||||||
timer.start()
|
timer.start()
|
||||||
print("Trying to print the time after it was started but before it was stopped:")
|
print("Trying to print the time after it was started but before it was stopped:")
|
||||||
print(str(timer.getTime()))
|
print(str(timer.getTime()))
|
||||||
cnt = 0
|
cnt = 0
|
||||||
print("Entering loop:")
|
#A loop just to eat up time
|
||||||
while(cnt < 1000):
|
print("\n\nEntering loop")
|
||||||
print(cnt)
|
while(cnt < 10000):
|
||||||
|
#print(cnt)
|
||||||
cnt = cnt + 1
|
cnt = cnt + 1
|
||||||
print("Exiting loop")
|
print("Exiting loop\n")
|
||||||
timer.stop()
|
timer.stop()
|
||||||
print("Trying to print time after it was finished")
|
#Get the correct ending to the test
|
||||||
|
print("Trying to print time after it was finished:")
|
||||||
print(str(timer.getTime()))
|
print(str(timer.getTime()))
|
||||||
|
print("\n")
|
||||||
|
|
||||||
|
#Test the different time resolutions
|
||||||
|
print("Print times in specific resolutions:")
|
||||||
|
print('{:08.6f}'.format(timer.getSeconds()) + " seconds")
|
||||||
|
print(str(timer.getMilliseconds()) + " milliseconds")
|
||||||
|
print(str(timer.getMicroseconds()) + " microseconds")
|
||||||
|
print(str(timer.getNanoseconds()) + " nanoseconds")
|
||||||
|
|
||||||
|
|
||||||
|
#Test end
|
||||||
|
print("\nEND OF TEST")
|
||||||
|
|
||||||
"""Results:
|
"""Results:
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user