src/net/nqe/observation_buffer_unittest.cc
// Verifies that the percentiles are correctly computed. Observations have
// different timestamps with half the observations being very old and the rest
// of them being very recent. Percentiles should factor in recent observations
// much more heavily than older samples.
Verifies that the percentiles are correctly computed. Observations have
different timestamps with half the observations being very old and the rest
of them being very recent. Percentiles should factor in recent observations
much more heavily than older samples.
Verifies that the percentiles are correctly computed . Observations have different timestamps with half the observations being very old and the rest of them being very recent . Percentiles should factor in recent observations much more heavily than older samples .
TEST(NetworkQualityObservationBufferTest, PercentileDifferentTimestamps) {
  std::map<std::string, std::string> variation_params;
  NetworkQualityEstimatorParams params(variation_params);
  base::SimpleTestTickClock tick_clock;
  tick_clock.Advance(base::TimeDelta::FromMinutes(1));
  ObservationBuffer buffer(&params, &tick_clock, 0.5, 1.0);
  const base::TimeTicks now = tick_clock.NowTicks();
  const base::TimeTicks very_old = now - base::TimeDelta::FromDays(7);
  size_t observations_count;
  EXPECT_FALSE(
      buffer
          .GetPercentile(base::TimeTicks(), INT32_MIN, 50,
                         &observations_count)
          .has_value());
  EXPECT_EQ(0u, observations_count);
  for (int i = 1; i <= 50; ++i) {
    buffer.AddObservation(Observation(i, very_old, INT32_MIN,
                                      NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP));
  }
  for (int i = 51; i <= 100; ++i) {
    buffer.AddObservation(Observation(i, now, INT32_MIN,
                                      NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP));
  }
  for (int i = 1; i < 100; ++i) {
    base::Optional<int32_t> result =
        buffer.GetPercentile(very_old, INT32_MIN, i, &observations_count);
    EXPECT_TRUE(result.has_value());
    EXPECT_NEAR(result.value(), 51 + 0.49 * i, 1);
    EXPECT_EQ(100u, observations_count);
  }
  EXPECT_FALSE(buffer.GetPercentile(now + base::TimeDelta::FromSeconds(1),
                                    INT32_MIN, 50, &observations_count));
  EXPECT_EQ(0u, observations_count);
}
TEST ( NetworkQualityObservationBufferTest , PercentileDifferentTimestamps ) { std :: map < std :: string , std :: string > variation_params ; NetworkQualityEstimatorParams params ( variation_params ) ; base :: SimpleTestTickClock tick_clock ; tick_clock . Advance ( base :: TimeDelta :: FromMinutes ( 1 ) ) ; ObservationBuffer buffer ( & params , & tick_clock , 0.5 , 1.0 ) ; const base :: TimeTicks now = tick_clock . NowTicks ( ) ; const base :: TimeTicks very_old = now - base :: TimeDelta :: FromDays ( 7 ) ; size_t observations_count ; EXPECT_FALSE ( buffer . GetPercentile ( base :: TimeTicks ( ) , INT32_MIN , 50 , & observations_count ) . has_value ( ) ) ; EXPECT_EQ ( 0u , observations_count ) ; for ( int i = 1 ; i <= 50 ; ++ i ) { buffer . AddObservation ( Observation ( i , very_old , INT32_MIN , NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP ) ) ; } for ( int i = 51 ; i <= 100 ; ++ i ) { buffer . AddObservation ( Observation ( i , now , INT32_MIN , NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP ) ) ; } for ( int i = 1 ; i < 100 ; ++ i ) { base :: Optional < int32_t > result = buffer . GetPercentile ( very_old , INT32_MIN , i , & observations_count ) ; EXPECT_TRUE ( result . has_value ( ) ) ; EXPECT_NEAR ( result . value ( ) , 51 + 0.49 * i , 1 ) ; EXPECT_EQ ( 100u , observations_count ) ; } EXPECT_FALSE ( buffer . GetPercentile ( now + base :: TimeDelta :: FromSeconds ( 1 ) , INT32_MIN , 50 , & observations_count ) ) ; EXPECT_EQ ( 0u , observations_count ) ; }
Verifies that the percentiles are correctly computed.
Verifies that the percentiles are correctly computed .
// Network quality should be unavailable when no observations are available. // First 50 samples have very old timestamps. // Next 50 (i.e., from 51 to 100) have recent timestamps. // Older samples have very little weight. So, all percentiles are >= 51 // (lowest value among recent observations). // Checks if the difference between the two integers is less than 1. This is // required because computed percentiles may be slightly different from // what is expected due to floating point computation errors and integer // rounding off errors.