#include "tests/ClockTests.h"
#include "tests/Test.h"
#include "utils/Clock.h"

static void testUpdate(Test& test) {
    Clock c;
    Clock::Nanos n1 = c.update();
    Clock::Nanos n2 = c.update();
    Clock::Nanos n3 = c.update();
    Clock::Nanos n4 = c.update();
    test.checkEqual(true, n1 > 0, "time measurement is positive 1");
    test.checkEqual(true, n2 > 0, "time measurement is positive 2");
    test.checkEqual(true, n3 > 0, "time measurement is positive 3");
    test.checkEqual(true, n4 > 0, "time measurement is positive 4");
}

static void testUpdatesPerSecond(Test& test) {
    Clock c;
    for(int i = 0; i < 1000; i++) {
        c.update();
    }
    test.checkEqual(true, c.getUpdatesPerSecond() > 0.0f, "updates per second are a positive");
}

static void testWait(Test& test) {
    const Clock::Nanos wait = 50'000'000;
    Clock c;
    c.update();
    c.wait(wait);
    Clock::Nanos n2 = c.update();
    test.checkEqual(true, n2 >= wait, "wait passes time");
}

void ClockTests::test() {
    Test test("Clock");
    testUpdate(test);
    testUpdatesPerSecond(test);
    testWait(test);
    test.finalize();
}