mirror of
https://github.com/krgamestudios/Toy.git
synced 2026-04-15 23:04:08 +10:00
Reduced test duration by a factor of 11,000. Don't ask. Also, something funny is going on with the time headers, so I stuck them into source/toy_common.h, I'll figure it out later.
61 lines
1.6 KiB
Plaintext
61 lines
1.6 KiB
Plaintext
//test the timer library
|
|
{
|
|
//create a timer, run it for a short period
|
|
import timer;
|
|
|
|
var timerA: opaque = startTimer();
|
|
for (var i: int = 0; i < 1000 * 1; i++);
|
|
var diffA: opaque = timerA.stopTimer();
|
|
|
|
//create another timer, run it for a longer period
|
|
var timerB: opaque = startTimer();
|
|
for (var i: int = 0; i < 1000 * 10; i++);
|
|
var diffB: opaque = timerB.stopTimer();
|
|
|
|
//check to ensure that the second timer took longer than the first
|
|
//WARNING: this has the small possibility of failing due to external factors
|
|
var difference: opaque = diffA.compareTimer(diffB);
|
|
|
|
assert difference.getTimerSeconds() >= 0, "compareTimer() (seconds) failed";
|
|
if (difference.getTimerSeconds() == 0) {
|
|
assert difference.getTimerMicroseconds() >= 0, "compareTimer() (microseconds) failed";
|
|
}
|
|
|
|
//all timers must be destroyed after use
|
|
timerA.destroyTimer();
|
|
timerB.destroyTimer();
|
|
diffA.destroyTimer();
|
|
diffB.destroyTimer();
|
|
difference.destroyTimer();
|
|
}
|
|
|
|
{
|
|
//create a timer, manipulate it's values
|
|
import timer;
|
|
|
|
//set the timer values manually
|
|
var timer: opaque = createTimer(42, 8891);
|
|
|
|
//check the timer values
|
|
assert timer.getTimerSeconds() == 42, "getTimerSeconds() failed";
|
|
assert timer.getTimerMicroseconds() == 8891, "getTimerMicroseconds() failed";
|
|
|
|
//all timers must be destroyed after use
|
|
timer.destroyTimer();
|
|
}
|
|
|
|
{
|
|
//set a timer to check string representation
|
|
import timer;
|
|
|
|
var timer: opaque = createTimer(42, 999);
|
|
|
|
assert timer.timerToString() == "42.000999", "timerToString() failed";
|
|
|
|
//all timers must be destroyed after use
|
|
timer.destroyTimer();
|
|
}
|
|
|
|
|
|
print "All good";
|