/*
 *  Copyright (c) 2018 The WebRTC project authors. All Rights Reserved.
 *
 *  Use of this source code is governed by a BSD-style license
 *  that can be found in the LICENSE file in the root of the source
 *  tree. An additional intellectual property rights grant can be found
 *  in the file PATENTS.  All contributing project authors may
 *  be found in the AUTHORS file in the root of the source tree.
 */

#include "rtc_base/numerics/moving_average.h"

#include <optional>

#include "test/gtest.h"

namespace test {

TEST(MovingAverageTest, EmptyAverage) {
  rtc::MovingAverage moving_average(1);
  EXPECT_EQ(0u, moving_average.Size());
  EXPECT_EQ(std::nullopt, moving_average.GetAverageRoundedDown());
}

// Test single value.
TEST(MovingAverageTest, OneElement) {
  rtc::MovingAverage moving_average(1);
  moving_average.AddSample(3);
  EXPECT_EQ(1u, moving_average.Size());
  EXPECT_EQ(3, *moving_average.GetAverageRoundedDown());
}

TEST(MovingAverageTest, GetAverage) {
  rtc::MovingAverage moving_average(1024);
  moving_average.AddSample(1);
  moving_average.AddSample(1);
  moving_average.AddSample(3);
  moving_average.AddSample(3);
  EXPECT_EQ(*moving_average.GetAverageRoundedDown(), 2);
  EXPECT_EQ(*moving_average.GetAverageRoundedToClosest(), 2);
}

TEST(MovingAverageTest, GetAverageRoundedDownRounds) {
  rtc::MovingAverage moving_average(1024);
  moving_average.AddSample(1);
  moving_average.AddSample(2);
  moving_average.AddSample(2);
  moving_average.AddSample(2);
  EXPECT_EQ(*moving_average.GetAverageRoundedDown(), 1);
}

TEST(MovingAverageTest, GetAverageRoundedToClosestRounds) {
  rtc::MovingAverage moving_average(1024);
  moving_average.AddSample(1);
  moving_average.AddSample(2);
  moving_average.AddSample(2);
  moving_average.AddSample(2);
  EXPECT_EQ(*moving_average.GetAverageRoundedToClosest(), 2);
}

TEST(MovingAverageTest, Reset) {
  rtc::MovingAverage moving_average(5);
  moving_average.AddSample(1);
  EXPECT_EQ(1, *moving_average.GetAverageRoundedDown());
  EXPECT_EQ(1, *moving_average.GetAverageRoundedToClosest());

  moving_average.Reset();

  EXPECT_FALSE(moving_average.GetAverageRoundedDown());
  moving_average.AddSample(10);
  EXPECT_EQ(10, *moving_average.GetAverageRoundedDown());
  EXPECT_EQ(10, *moving_average.GetAverageRoundedToClosest());
}

TEST(MovingAverageTest, ManySamples) {
  rtc::MovingAverage moving_average(10);
  for (int i = 1; i < 11; i++) {
    moving_average.AddSample(i);
  }
  EXPECT_EQ(*moving_average.GetAverageRoundedDown(), 5);
  EXPECT_EQ(*moving_average.GetAverageRoundedToClosest(), 6);
  for (int i = 1; i < 2001; i++) {
    moving_average.AddSample(i);
  }
  EXPECT_EQ(*moving_average.GetAverageRoundedDown(), 1995);
  EXPECT_EQ(*moving_average.GetAverageRoundedToClosest(), 1996);
}

}  // namespace test
