Files
video-shader-toys/tests/RuntimeClockTests.cpp
Aiden 414ef62479
Some checks failed
CI / React UI Build (push) Successful in 11s
CI / Native Windows Build And Tests (push) Successful in 1m32s
CI / Windows Release Package (push) Failing after 2m7s
Added clock time
2026-05-06 12:38:23 +10:00

51 lines
1.2 KiB
C++

#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;
}