package com.foxx.androidcast.network.transport;

/*********************************************************************
 * NackRateLimiterTest.java
 * Created at: Mon 18 May 2026 14:25:02 +0200
 * Updated at: Wed 20 May 2026 15:17:13 +0200 by Anton Afanasyeu <a.afanasieff@gmail.com>
 * Commit: 5d8e82d2e60a21fff3138d2a394ee4e8b4c6dcb8
 * class NackRateLimiterTest
 * Contributors:
 *    - Anton Afanasyeu <a.afanasieff@gmail.com> (2 commits, 32 lines)
 *    - Cursor Agent (project assistant)
 * Digest: SHA256	74f200b84b1cdf01b8315ca61fd4665a39bef8ae80caf75542d77820f137273c
**********************************************************************/
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import org.junit.Test;

public class NackRateLimiterTest {
    @Test
    public void capsPerMessage() throws InterruptedException {
        NackRateLimiter limiter = new NackRateLimiter();
        for (int i = 0; i < 6; i++) {
            assertTrue(limiter.allow(42));
            Thread.sleep(45);
        }
        assertFalse(limiter.allow(42));
    }

    @Test
    public void rateLimitsRapidRepeats() {
        NackRateLimiter limiter = new NackRateLimiter();
        assertTrue(limiter.allow(1));
        assertFalse(limiter.allow(1));
    }
}
