blob: cbc338a3b4eec23299af3c4a7d97082ed60904d0 [file] [log] [blame]
[email protected]05f9b682008-09-29 22:18:011// 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
3// found in the LICENSE file.
4
5#include "base/rand_util.h"
6
7#include <limits>
8
9#include "testing/gtest/include/gtest/gtest.h"
10
11namespace {
12
13const int kIntMin = std::numeric_limits<int>::min();
14const int kIntMax = std::numeric_limits<int>::max();
15
16} // namespace
17
18TEST(RandUtilTest, SameMinAndMax) {
19 EXPECT_EQ(base::RandInt(0, 0), 0);
20 EXPECT_EQ(base::RandInt(kIntMin, kIntMin), kIntMin);
21 EXPECT_EQ(base::RandInt(kIntMax, kIntMax), kIntMax);
22}
[email protected]94a0f312008-09-30 14:26:3323
24TEST(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}
[email protected]a74dcae2010-08-30 21:07:0530
31// Make sure that it is still appropriate to use RandGenerator in conjunction
32// with std::random_shuffle().
33TEST(RandUtilTest, RandGeneratorForRandomShuffle) {
34 EXPECT_EQ(base::RandGenerator(1), 0U);
35 EXPECT_LE(std::numeric_limits<ptrdiff_t>::max(),
36 std::numeric_limits<int64>::max());
37}