| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <cmath> | 5 #include <cmath> |
| 6 #include <limits> | 6 #include <limits> |
| 7 #include <numeric> | 7 #include <numeric> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/guid.h" | 10 #include "base/guid.h" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/prefs/testing_pref_service.h" | 12 #include "base/prefs/testing_pref_service.h" |
| 13 #include "base/rand_util.h" | 13 #include "base/rand_util.h" |
| 14 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
| 15 #include "chrome/common/metrics/entropy_provider.h" | 15 #include "chrome/common/metrics/entropy_provider.h" |
| 16 #include "chrome/common/metrics/metrics_util.h" | 16 #include "chrome/common/metrics/metrics_util.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 18 | 18 |
| 19 namespace metrics { | 19 namespace metrics { |
| 20 | 20 |
| 21 namespace { | 21 namespace { |
| 22 | 22 |
| 23 // Size of the low entropy source to use for the permuted entropy provider | 23 // Size of the low entropy source to use for the permuted entropy provider |
| 24 // in tests. | 24 // in tests. |
| 25 const size_t kMaxLowEntropySize = (1 << 13); | 25 const size_t kMaxLowEntropySize = 8000; |
| 26 | 26 |
| 27 // Field trial names used in unit tests. | 27 // Field trial names used in unit tests. |
| 28 const std::string kTestTrialNames[] = { "TestTrial", "AnotherTestTrial", | 28 const std::string kTestTrialNames[] = { "TestTrial", "AnotherTestTrial", |
| 29 "NewTabButton" }; | 29 "NewTabButton" }; |
| 30 | 30 |
| 31 // Computes the Chi-Square statistic for |values| assuming they follow a uniform | 31 // Computes the Chi-Square statistic for |values| assuming they follow a uniform |
| 32 // distribution, where each entry has expected value |expected_value|. | 32 // distribution, where each entry has expected value |expected_value|. |
| 33 // | 33 // |
| 34 // The Chi-Square statistic is defined as Sum((O-E)^2/E) where O is the observed | 34 // The Chi-Square statistic is defined as Sum((O-E)^2/E) where O is the observed |
| 35 // value and E is the expected value. | 35 // value and E is the expected value. |
| (...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 386 kMaxLowEntropySize); | 386 kMaxLowEntropySize); |
| 387 for (size_t i = 0; i < 2 * arraysize(kTestTrialNames); ++i) { | 387 for (size_t i = 0; i < 2 * arraysize(kTestTrialNames); ++i) { |
| 388 const std::string trial_name = | 388 const std::string trial_name = |
| 389 kTestTrialNames[i % arraysize(kTestTrialNames)]; | 389 kTestTrialNames[i % arraysize(kTestTrialNames)]; |
| 390 EXPECT_EQ(provider.GetEntropyForTrial(trial_name, 0), | 390 EXPECT_EQ(provider.GetEntropyForTrial(trial_name, 0), |
| 391 cached_provider.GetEntropyForTrial(trial_name, 0)); | 391 cached_provider.GetEntropyForTrial(trial_name, 0)); |
| 392 } | 392 } |
| 393 } | 393 } |
| 394 | 394 |
| 395 } // namespace metrics | 395 } // namespace metrics |
| OLD | NEW |