| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- module Tests;
- import Core.Clock;
- import Core.Test;
- import Core.Types;
- import ErrorSimulator;
- using Core::Clock;
- static void testUpdate() {
- Clock c;
- Core::testTrue(c.update() == 0);
- Core::testTrue(c.update() >= 0);
- Core::testTrue(c.update() >= 0);
- Core::testTrue(c.update() >= 0);
- }
- static void testUpdatesPerSecond() {
- Clock c;
- for(int i = 0; i < 1000; i++) {
- Core::testTrue(c.update() >= 0);
- }
- Core::testTrue(c.getUpdatesPerSecond() > 0.0f);
- }
- static void testSleep(i64 nanos) {
- Clock c;
- Core::testTrue(c.update() >= 0);
- Core::testFalse(Clock::sleepNanos(nanos));
- i64 n = c.update();
- Core::testTrue(n >= nanos && n <= nanos * 13 / 10);
- }
- static void testSleepMillis(i64 millis) {
- Clock c;
- Core::testTrue(c.update() >= 0);
- Core::testFalse(Clock::sleepMillis(millis));
- i64 n = c.update();
- i64 nanos = millis * 1'000'000;
- Core::testTrue(n >= nanos && n <= nanos * 13 / 10);
- }
- static void testFail() {
- Clock c;
- #ifdef ERROR_SIMULATOR
- failStepThrow = 1;
- Core::test(-1l, c.update());
- failStepThrow = 1;
- Core::test(-1l, Clock::getNanos());
- failStepThrow = 1;
- Core::testTrue(Clock::sleepMillis(5));
- failStepThrow = 0;
- #endif
- }
- void testClock(bool light) {
- testUpdate();
- testUpdatesPerSecond();
- testSleep(light ? 5'000'000 : 50'000'000);
- testSleep(light ? 50'000'000 : 1'300'000'000);
- testSleepMillis(light ? 5 : 50);
- testSleepMillis(light ? 50 : 1300);
- testFail();
- }
|