Esempio n. 1
0
static void
TestExpiration()
{
  ClimbAverageCalculator c;
  c.Reset();

  constexpr double AVERAGE_TIME = 30;


  // Test expiration for empty data
  ok1(c.Expired(0, 60));
  ok1(c.Expired(15, 60));

  // Add values and test non-expiration
  bool expired = false;
  for (unsigned i = 1; i <= 60; i++) {
    c.GetAverage(i, i, AVERAGE_TIME);
    expired = expired || c.Expired(i, 60);
  }

  ok1(!expired);

  // Test expiration with 30sec
  ok1(!c.Expired(89, 30));
  ok1(!c.Expired(90, 30));
  ok1(c.Expired(91, 30));

  // Test expiration with 60sec
  ok1(!c.Expired(119, 60));
  ok1(!c.Expired(120, 60));
  ok1(c.Expired(121, 60));

  // Time warp
  ok1(c.Expired(59, 60));
  ok1(!c.Expired(60, 60));
  ok1(!c.Expired(61, 60));
}
Esempio n. 2
0
static void
TestExpiration()
{
  ClimbAverageCalculator c;
  c.Reset();

  constexpr fixed AVERAGE_TIME = fixed(30);


  // Test expiration for empty data
  ok1(c.Expired(fixed(0), fixed(60)));
  ok1(c.Expired(fixed(15), fixed(60)));

  // Add values and test non-expiration
  bool expired = false;
  for (unsigned i = 1; i <= 60; i++) {
    c.GetAverage(fixed(i), fixed(i), AVERAGE_TIME);
    expired = expired || c.Expired(fixed(i), fixed(60));
  }

  ok1(!expired);

  // Test expiration with 30sec
  ok1(!c.Expired(fixed(89), fixed(30)));
  ok1(!c.Expired(fixed(90), fixed(30)));
  ok1(c.Expired(fixed(91), fixed(30)));

  // Test expiration with 60sec
  ok1(!c.Expired(fixed(119), fixed(60)));
  ok1(!c.Expired(fixed(120), fixed(60)));
  ok1(c.Expired(fixed(121), fixed(60)));

  // Time warp
  ok1(c.Expired(fixed(59), fixed(60)));
  ok1(!c.Expired(fixed(60), fixed(60)));
  ok1(!c.Expired(fixed(61), fixed(60)));
}