1 // Copyright 2014 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include <math.h> 6 7 #include <algorithm> 8 9 #include "base/strings/stringprintf.h" 10 #include "media/cast/test/utility/test_util.h" 11 12 namespace media { 13 namespace cast { 14 namespace test { 15 MeanAndError(const std::vector<double> & values)16MeanAndError::MeanAndError(const std::vector<double>& values) { 17 double sum = 0.0; 18 double sqr_sum = 0.0; 19 num_values = values.size(); 20 if (num_values) { 21 for (size_t i = 0; i < num_values; i++) { 22 sum += values[i]; 23 sqr_sum += values[i] * values[i]; 24 } 25 mean = sum / num_values; 26 std_dev = 27 sqrt(std::max(0.0, num_values * sqr_sum - sum * sum)) / num_values; 28 } 29 } 30 AsString() const31std::string MeanAndError::AsString() const { 32 return base::StringPrintf("%f +/- %f", mean, std_dev); 33 } 34 35 } // namespace test 36 } // namespace cast 37 } // namespace media 38