src/net/nqe/observation_buffer_unittest.cc
// Verifies that the percentiles are correctly computed. All observations have
// same timestamp with half the observations taken at low RSSI, and half the
// observations with high RSSI. Percentiles should be computed based on the
// current RSSI and the RSSI of the observations.
Verifies that the percentiles are correctly computed. All observations have
same timestamp with half the observations taken at low RSSI, and half the
observations with high RSSI. Percentiles should be computed based on the
current RSSI and the RSSI of the observations.
Verifies that the percentiles are correctly computed . All observations have same timestamp with half the observations taken at low RSSI and half the observations with high RSSI . Percentiles should be computed based on the current RSSI and the RSSI of the observations .
TEST(NetworkQualityObservationBufferTest, PercentileDifferentRSSI) {
  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, 1.0, 0.25);
  const base::TimeTicks now = tick_clock.NowTicks();
  int32_t high_rssi = 4;
  int32_t low_rssi = 0;
  EXPECT_FALSE(buffer.GetPercentile(base::TimeTicks(), INT32_MIN, 50, nullptr)
                   .has_value());
  for (int i = 1; i <= 50; ++i) {
    buffer.AddObservation(
        Observation(i, now, low_rssi, NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP));
  }
  for (int i = 51; i <= 100; ++i) {
    buffer.AddObservation(Observation(i, now, high_rssi,
                                      NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP));
  }
  for (int i = 1; i < 100; ++i) {
    base::Optional<int32_t> result =
        buffer.GetPercentile(now, high_rssi, i, nullptr);
    EXPECT_TRUE(result.has_value());
    EXPECT_NEAR(result.value(), 51 + 0.49 * i, 2);
  }
  for (int i = 1; i < 100; ++i) {
    base::Optional<int32_t> result =
        buffer.GetPercentile(now, low_rssi, i, nullptr);
    EXPECT_TRUE(result.has_value());
    EXPECT_NEAR(result.value(), i / 2, 2);
  }
}
TEST ( NetworkQualityObservationBufferTest , PercentileDifferentRSSI ) { 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 , 1.0 , 0.25 ) ; const base :: TimeTicks now = tick_clock . NowTicks ( ) ; int32_t high_rssi = 4 ; int32_t low_rssi = 0 ; EXPECT_FALSE ( buffer . GetPercentile ( base :: TimeTicks ( ) , INT32_MIN , 50 , nullptr ) . has_value ( ) ) ; for ( int i = 1 ; i <= 50 ; ++ i ) { buffer . AddObservation ( Observation ( i , now , low_rssi , NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP ) ) ; } for ( int i = 51 ; i <= 100 ; ++ i ) { buffer . AddObservation ( Observation ( i , now , high_rssi , NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP ) ) ; } for ( int i = 1 ; i < 100 ; ++ i ) { base :: Optional < int32_t > result = buffer . GetPercentile ( now , high_rssi , i , nullptr ) ; EXPECT_TRUE ( result . has_value ( ) ) ; EXPECT_NEAR ( result . value ( ) , 51 + 0.49 * i , 2 ) ; } for ( int i = 1 ; i < 100 ; ++ i ) { base :: Optional < int32_t > result = buffer . GetPercentile ( now , low_rssi , i , nullptr ) ; EXPECT_TRUE ( result . has_value ( ) ) ; EXPECT_NEAR ( result . value ( ) , i / 2 , 2 ) ; } }
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 low RSSI. // Next 50 (i.e., from 51 to 100) have high RSSI. // When the current RSSI is |high_rssi|, higher weight should be assigned // to observations that were taken at |high_rssi|. // When the current RSSI is |low_rssi|, higher weight should be assigned // to observations that were taken at |low_rssi|.