Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(16)

Side by Side Diff: components/variations/caching_permuted_entropy_provider_unittest.cc

Issue 293623003: [Metrics] Move CachingPermutedEntropyProvider into the variations component. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add a newline Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "chrome/common/metrics/caching_permuted_entropy_provider.h" 5 #include "components/variations/caching_permuted_entropy_provider.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/prefs/testing_pref_service.h" 10 #include "base/prefs/testing_pref_service.h"
11 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
12 12
13 namespace metrics { 13 namespace metrics {
14 14
15 // Size of the low entropy source to use for the permuted entropy provider 15 // Size of the low entropy source to use for the permuted entropy provider
16 // in tests. 16 // in tests.
17 const size_t kMaxLowEntropySize = 8000; 17 const size_t kMaxLowEntropySize = 8000;
18 18
19 // Field trial names used in unit tests. 19 // Field trial names used in unit tests.
20 const char* const kTestTrialNames[] = { "TestTrial", "AnotherTestTrial", 20 const char* const kTestTrialNames[] = {"TestTrial", "AnotherTestTrial",
21 "NewTabButton" }; 21 "NewTabButton"};
22 22
23 TEST(CachingPermutedEntropyProviderTest, HasConsistentResults) { 23 TEST(CachingPermutedEntropyProviderTest, HasConsistentResults) {
24 TestingPrefServiceSimple prefs; 24 TestingPrefServiceSimple prefs;
25 CachingPermutedEntropyProvider::RegisterPrefs(prefs.registry()); 25 CachingPermutedEntropyProvider::RegisterPrefs(prefs.registry());
26 const int kEntropyValue = 1234; 26 const int kEntropyValue = 1234;
27 27
28 // Check that the caching provider returns the same results as the non caching 28 // Check that the caching provider returns the same results as the non caching
29 // one. Loop over the trial names twice, to test that caching returns the 29 // one. Loop over the trial names twice, to test that caching returns the
30 // expected results. 30 // expected results.
31 PermutedEntropyProvider provider(kEntropyValue, kMaxLowEntropySize); 31 PermutedEntropyProvider provider(kEntropyValue, kMaxLowEntropySize);
32 for (size_t i = 0; i < 2 * arraysize(kTestTrialNames); ++i) { 32 for (size_t i = 0; i < 2 * arraysize(kTestTrialNames); ++i) {
33 CachingPermutedEntropyProvider cached_provider(&prefs, kEntropyValue, 33 CachingPermutedEntropyProvider cached_provider(
34 kMaxLowEntropySize); 34 &prefs, kEntropyValue, kMaxLowEntropySize);
35 const std::string trial_name = 35 const std::string trial_name =
36 kTestTrialNames[i % arraysize(kTestTrialNames)]; 36 kTestTrialNames[i % arraysize(kTestTrialNames)];
37 EXPECT_DOUBLE_EQ(provider.GetEntropyForTrial(trial_name, 0), 37 EXPECT_DOUBLE_EQ(provider.GetEntropyForTrial(trial_name, 0),
38 cached_provider.GetEntropyForTrial(trial_name, 0)); 38 cached_provider.GetEntropyForTrial(trial_name, 0));
39 } 39 }
40 40
41 // Now, do the same test re-using the same caching provider. 41 // Now, do the same test re-using the same caching provider.
42 CachingPermutedEntropyProvider cached_provider(&prefs, kEntropyValue, 42 CachingPermutedEntropyProvider cached_provider(
43 kMaxLowEntropySize); 43 &prefs, kEntropyValue, kMaxLowEntropySize);
44 for (size_t i = 0; i < 2 * arraysize(kTestTrialNames); ++i) { 44 for (size_t i = 0; i < 2 * arraysize(kTestTrialNames); ++i) {
45 const std::string trial_name = 45 const std::string trial_name =
46 kTestTrialNames[i % arraysize(kTestTrialNames)]; 46 kTestTrialNames[i % arraysize(kTestTrialNames)];
47 EXPECT_DOUBLE_EQ(provider.GetEntropyForTrial(trial_name, 0), 47 EXPECT_DOUBLE_EQ(provider.GetEntropyForTrial(trial_name, 0),
48 cached_provider.GetEntropyForTrial(trial_name, 0)); 48 cached_provider.GetEntropyForTrial(trial_name, 0));
49 } 49 }
50 } 50 }
51 51
52 } // namespace metrics 52 } // namespace metrics
OLDNEW
« no previous file with comments | « components/variations/caching_permuted_entropy_provider.cc ('k') | components/variations/pref_names.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698