1/*
2 *  Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
3 *
4 *  Use of this source code is governed by a BSD-style license
5 *  that can be found in the LICENSE file in the root of the source
6 *  tree. An additional intellectual property rights grant can be found
7 *  in the file PATENTS.  All contributing project authors may
8 *  be found in the AUTHORS file in the root of the source tree.
9 */
10#include "webrtc/test/statistics.h"
11
12#include <math.h>
13
14namespace webrtc {
15namespace test {
16
17Statistics::Statistics() : sum_(0.0), sum_squared_(0.0), count_(0) {}
18
19void Statistics::AddSample(double sample) {
20  sum_ += sample;
21  sum_squared_ += sample * sample;
22  ++count_;
23}
24
25double Statistics::Mean() const {
26  if (count_ == 0)
27    return 0.0;
28  return sum_ / count_;
29}
30
31double Statistics::Variance() const {
32  if (count_ == 0)
33    return 0.0;
34  return sum_squared_ / count_ - Mean() * Mean();
35}
36
37double Statistics::StandardDeviation() const {
38  return sqrt(Variance());
39}
40}  // namespace test
41}  // namespace webrtc
42