ClockTests.cpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #include "tests/ClockTests.h"
  2. #include "tests/Test.h"
  3. #include "utils/Clock.h"
  4. static void testUpdate(Test& test) {
  5. Clock c;
  6. Clock::Nanos n1 = c.update();
  7. Clock::Nanos n2 = c.update();
  8. Clock::Nanos n3 = c.update();
  9. Clock::Nanos n4 = c.update();
  10. test.checkEqual(true, n1 > 0, "time measurement is positive 1");
  11. test.checkEqual(true, n2 > 0, "time measurement is positive 2");
  12. test.checkEqual(true, n3 > 0, "time measurement is positive 3");
  13. test.checkEqual(true, n4 > 0, "time measurement is positive 4");
  14. }
  15. static void testUpdatesPerSecond(Test& test) {
  16. Clock c;
  17. for(int i = 0; i < 1000; i++) {
  18. c.update();
  19. }
  20. test.checkEqual(true, c.getUpdatesPerSecond() > 0.0f, "updates per second are a positive");
  21. }
  22. static void testWait(Test& test) {
  23. const Clock::Nanos wait = 50'000'000;
  24. Clock c;
  25. c.update();
  26. c.wait(wait);
  27. Clock::Nanos n2 = c.update();
  28. test.checkEqual(true, n2 >= wait, "wait passes time");
  29. }
  30. void ClockTests::test() {
  31. Test test("Clock");
  32. testUpdate(test);
  33. testUpdatesPerSecond(test);
  34. testWait(test);
  35. test.finalize();
  36. }