package iris.audit.client;

import org.testng.annotations.Test;
import static org.testng.Assert.*;

public class RateLimiterTest
{
  @Test
  public void attemptRequestAt()
  {
    final RateLimiter limiter = new RateLimiter( 3, 10 );

    assertEquals( true, limiter.attemptRequestAt( 11 ) );
    assertEquals( true, limiter.attemptRequestAt( 12 ) );
    assertEquals( true, limiter.attemptRequestAt( 13 ) );
    assertEquals( false, limiter.attemptRequestAt( 11 ) );
    assertEquals( false, limiter.attemptRequestAt( 20 ) );
    assertEquals( true, limiter.attemptRequestAt( 22 ) );
    assertEquals( false, limiter.attemptRequestAt( 22 ) );
    assertEquals( true, limiter.attemptRequestAt( 23 ) );
    assertEquals( true, limiter.attemptRequestAt( 24 ) );
    assertEquals( false, limiter.attemptRequestAt( 25 ) );
  }

  @Test
  public void reset()
  {
    final RateLimiter limiter = new RateLimiter( 1, 10 );

    assertEquals( true, limiter.attemptRequestAt( 11 ) );
    assertEquals( false, limiter.attemptRequestAt( 12 ) );
    limiter.reset();
    assertEquals( true, limiter.attemptRequestAt( 12 ) );
  }
}
