// ok cpp include
/// @file timeout.cpp
/// @brief Test for Timeout class rollover-safe arithmetic

#include "test.h"
#include "fl/system/timeout.h"

using namespace fl;

FL_TEST_CASE("Timeout - rollover test") {
    // Test critical rollover scenario: timeout starts before rollover (0xFFFFFFFF),
    // ends after rollover (0x00000000+). This verifies unsigned arithmetic works correctly.

    uint32_t start = 0xFFFFFF00;  // 256 ticks before rollover
    uint32_t duration = 512;       // Duration spans the rollover boundary

    Timeout timeout(start, duration);

    // At start: not done, zero elapsed
    FL_CHECK_FALSE(timeout.done(start));
    FL_CHECK(timeout.elapsed(start) == 0);

    // 256 ticks later: at rollover point (0x00000000), still not done
    uint32_t at_rollover = start + 256;  // = 0x00000000 due to wraparound
    FL_CHECK_FALSE(timeout.done(at_rollover));
    FL_CHECK(timeout.elapsed(at_rollover) == 256);

    // 256 more ticks: past rollover (0x00000100), now done
    uint32_t past_rollover = at_rollover + 256;  // = 0x00000100
    FL_CHECK(timeout.done(past_rollover));
    FL_CHECK(timeout.elapsed(past_rollover) == 512);
}

// Grouped tests
#include "tests/fl/math/time_alpha.hpp"

FL_TEST_FILE(FL_FILEPATH) {

} // FL_TEST_FILE
