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

Side by Side Diff: base/rand_util_unittest.cc

Issue 5801: Reduce RandDouble to one call to ldexp, add one bit of precision (Closed) Base URL: svn://chrome-svn.corp.google.com/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
« no previous file with comments | « base/rand_util.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2008 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 "base/rand_util.h" 5 #include "base/rand_util.h"
6 6
7 #include <limits> 7 #include <limits>
8 8
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 10
11 namespace { 11 namespace {
12 12
13 const int kIntMin = std::numeric_limits<int>::min(); 13 const int kIntMin = std::numeric_limits<int>::min();
14 const int kIntMax = std::numeric_limits<int>::max(); 14 const int kIntMax = std::numeric_limits<int>::max();
15 15
16 } // namespace 16 } // namespace
17 17
18 TEST(RandUtilTest, SameMinAndMax) { 18 TEST(RandUtilTest, SameMinAndMax) {
19 EXPECT_EQ(base::RandInt(0, 0), 0); 19 EXPECT_EQ(base::RandInt(0, 0), 0);
20 EXPECT_EQ(base::RandInt(kIntMin, kIntMin), kIntMin); 20 EXPECT_EQ(base::RandInt(kIntMin, kIntMin), kIntMin);
21 EXPECT_EQ(base::RandInt(kIntMax, kIntMax), kIntMax); 21 EXPECT_EQ(base::RandInt(kIntMax, kIntMax), kIntMax);
22 } 22 }
23
24 TEST(RandUtilTest, RandDouble) {
25 // Force 64-bit precision, making sure we're not in a 80-bit FPU register.
26 volatile double number = base::RandDouble();
27 EXPECT_GT(1.0, number);
28 EXPECT_LE(0.0, number);
29 }
OLDNEW
« no previous file with comments | « base/rand_util.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698