Added clock time
This commit is contained in:
50
tests/RuntimeClockTests.cpp
Normal file
50
tests/RuntimeClockTests.cpp
Normal file
@@ -0,0 +1,50 @@
|
||||
#include "RuntimeClock.h"
|
||||
|
||||
#include <cmath>
|
||||
#include <iostream>
|
||||
|
||||
namespace
|
||||
{
|
||||
int gFailures = 0;
|
||||
|
||||
void Expect(bool condition, const char* message)
|
||||
{
|
||||
if (condition)
|
||||
return;
|
||||
|
||||
std::cerr << "FAIL: " << message << "\n";
|
||||
++gFailures;
|
||||
}
|
||||
|
||||
void TestUtcSecondsOfDay()
|
||||
{
|
||||
const RuntimeClockSnapshot midnight = MakeRuntimeClockSnapshot(0);
|
||||
Expect(midnight.utcTimeSeconds == 0.0, "Unix epoch starts at UTC midnight");
|
||||
|
||||
const RuntimeClockSnapshot midday = MakeRuntimeClockSnapshot(12 * 3600 + 34 * 60 + 56);
|
||||
Expect(midday.utcTimeSeconds == 45296.0, "UTC time of day is seconds since midnight");
|
||||
}
|
||||
|
||||
void TestOffsetLooksLikeTimezoneOffset()
|
||||
{
|
||||
const RuntimeClockSnapshot snapshot = MakeRuntimeClockSnapshot(12 * 3600);
|
||||
Expect(std::fmod(snapshot.utcOffsetSeconds, 60.0) == 0.0, "UTC offset is minute-aligned");
|
||||
Expect(snapshot.utcOffsetSeconds >= -14.0 * 3600.0 && snapshot.utcOffsetSeconds <= 14.0 * 3600.0,
|
||||
"UTC offset is in the normal timezone range");
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
TestUtcSecondsOfDay();
|
||||
TestOffsetLooksLikeTimezoneOffset();
|
||||
|
||||
if (gFailures != 0)
|
||||
{
|
||||
std::cerr << gFailures << " RuntimeClock test failure(s).\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::cout << "RuntimeClock tests passed.\n";
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user