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

Side by Side Diff: base/field_trial_unittest.cc

Issue 7638: Construct a field trial to see if HIGH or MEDIUM memory model "works better"... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 12 years, 2 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
« no previous file with comments | « base/field_trial.cc ('k') | chrome/browser/browser.vcproj » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright (c) 2006-2008 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 // Test of FieldTrial class
6
7 #include "base/field_trial.h"
8
9 #include "base/logging.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11
12 class FieldTrialTest : public testing::Test {
13 public:
14 FieldTrialTest() : trial_list_() { }
15 ~FieldTrialTest() { FieldTrialList::ResetConstructorCountForTestingOnly(); }
16
17 private:
18 FieldTrialList trial_list_;
19 };
20
21 // Test registration, and also check that destructors are called for trials
22 // (and that Purify doesn't catch us leaking).
23 TEST_F(FieldTrialTest, Registration) {
24 const wchar_t* name1 = L"name 1 test";
25 const wchar_t* name2 = L"name 2 test";
26 EXPECT_FALSE(FieldTrialList::Find(name1));
27 EXPECT_FALSE(FieldTrialList::Find(name2));
28
29 FieldTrial* trial1 = new FieldTrial(name1, 0.7);
30
31 EXPECT_EQ(trial1, FieldTrialList::Find(name1));
32 EXPECT_FALSE(FieldTrialList::Find(name2));
33
34 FieldTrial* trial2 = new FieldTrial(name2, 0.7);
35
36 EXPECT_EQ(trial1, FieldTrialList::Find(name1));
37 EXPECT_EQ(trial2, FieldTrialList::Find(name2));
38 // Note: FieldTrialList should delete the objects at shutdown.
39 }
40
41 TEST_F(FieldTrialTest, AbsoluteProbabilities) {
42 wchar_t always_true[] = L" always true";
43 wchar_t always_false[] = L" always false";
44 for (int i = 1; i < 250; ++i) {
45 // Try lots of names, by changing the first character of the name.
46 always_true[0] = i;
47 always_false[0] = i;
48 FieldTrial* trial_true = new FieldTrial(always_true, 1.0);
49 EXPECT_TRUE(trial_true->boolean_value());
50 FieldTrial* trial_false = new FieldTrial(always_false, 0.0);
51 EXPECT_FALSE(trial_false->boolean_value());
52 }
53 }
54
55 TEST_F(FieldTrialTest, MiddleProbabalities) {
56 wchar_t name[] = L" same name";
57 bool false_event_seen = false;
58 bool true_event_seen = false;
59 for (int i = 1; i < 250; ++i) {
60 name[0] = i;
61 FieldTrial* trial = new FieldTrial(name, 0.5);
62 if (trial->boolean_value()) {
63 true_event_seen = true;
64 } else {
65 false_event_seen = true;
66 }
67 if (false_event_seen && true_event_seen)
68 return; // Successful test!!!
69 }
70 // Very surprising to get here. Probability should be around 1 in 2 ** 250.
71 // One of the following will fail.
72 EXPECT_TRUE(false_event_seen);
73 EXPECT_TRUE(true_event_seen);
74 }
OLDNEW
« no previous file with comments | « base/field_trial.cc ('k') | chrome/browser/browser.vcproj » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698