ClockTests.cpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #include "tests/ClockTests.h"
  2. #include "test/Test.h"
  3. #include "utils/Clock.h"
  4. static void testUpdate() {
  5. Core::Clock c;
  6. Core::Clock::Nanos n1 = 0;
  7. Core::Clock::Nanos n2 = 0;
  8. Core::Clock::Nanos n3 = 0;
  9. Core::Clock::Nanos n4 = 0;
  10. CORE_TEST_ERROR(c.update(n1));
  11. CORE_TEST_ERROR(c.update(n2));
  12. CORE_TEST_ERROR(c.update(n3));
  13. CORE_TEST_ERROR(c.update(n4));
  14. CORE_TEST_TRUE(n1 == 0);
  15. CORE_TEST_TRUE(n2 > 0);
  16. CORE_TEST_TRUE(n3 > 0);
  17. CORE_TEST_TRUE(n4 > 0);
  18. }
  19. static void testUpdatesPerSecond() {
  20. Core::Clock c;
  21. for(int i = 0; i < 1000; i++) {
  22. Core::Clock::Nanos n = 0;
  23. CORE_TEST_ERROR(c.update(n));
  24. }
  25. CORE_TEST_TRUE(c.getUpdatesPerSecond() > 0.0f);
  26. }
  27. static void testWait(Core::Clock::Nanos wait) {
  28. Core::Clock c;
  29. Core::Clock::Nanos n = 0;
  30. CORE_TEST_ERROR(c.update(n));
  31. CORE_TEST_ERROR(c.wait(wait));
  32. Core::Clock::Nanos n2 = 0;
  33. CORE_TEST_ERROR(c.update(n2));
  34. CORE_TEST_TRUE(n2 >= wait && n2 <= wait * 11 / 10);
  35. }
  36. void Core::ClockTests::test() {
  37. testUpdate();
  38. testUpdatesPerSecond();
  39. testWait(50'000'000);
  40. testWait(1'300'000'000);
  41. }