chromium/base/rand_util_unittest.cc

// Copyright 2011 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/40284755): Remove this and spanify to fix the errors.
#pragma allow_unsafe_buffers
#endif

#include "base/rand_util.h"

#include <stddef.h>
#include <stdint.h>

#include <algorithm>
#include <cmath>
#include <limits>
#include <memory>
#include <vector>

#include "base/containers/span.h"
#include "base/logging.h"
#include "base/time/time.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace base {

namespace {

const int kIntMin =;
const int kIntMax =;

}  // namespace

TEST(RandUtilTest, RandInt) {}

TEST(RandUtilTest, RandDouble) {}

TEST(RandUtilTest, RandFloat) {}

TEST(RandUtilTest, RandTimeDelta) {}

TEST(RandUtilTest, RandTimeDeltaUpTo) {}

TEST(RandUtilTest, BitsToOpenEndedUnitInterval) {}

TEST(RandUtilTest, BitsToOpenEndedUnitIntervalF) {}

TEST(RandUtilTest, RandBytes) {}

// Verify that calling base::RandBytes with an empty buffer doesn't fail.
TEST(RandUtilTest, RandBytes0) {}

TEST(RandUtilTest, RandBytesAsVector) {}

TEST(RandUtilTest, RandBytesAsString) {}

// Make sure that it is still appropriate to use RandGenerator in conjunction
// with std::random_shuffle().
TEST(RandUtilTest, RandGeneratorForRandomShuffle) {}

TEST(RandUtilTest, RandGeneratorIsUniform) {}

TEST(RandUtilTest, RandUint64ProducesBothValuesOfAllBits) {}

TEST(RandUtilTest, RandBytesLonger) {}

// Benchmark test for RandBytes().  Disabled since it's intentionally slow and
// does not test anything that isn't already tested by the existing RandBytes()
// tests.
TEST(RandUtilTest, DISABLED_RandBytesPerf) {}

TEST(RandUtilTest, InsecureRandomGeneratorProducesBothValuesOfAllBits) {}

namespace {

constexpr double kXp1Percent =;
constexpr double kXp99Percent =;

double ChiSquaredCriticalValue(double nu, double x_p) {}

int ExtractBits(uint64_t value, int from_bit, int num_bits) {}

// Performs a Chi-Squared test on a subset of |num_bits| extracted starting from
// |from_bit| in the generated value.
//
// See TAOCP, Volume 2, Section 3.3.1, and
// https://en.wikipedia.org/wiki/Pearson%27s_chi-squared_test for details.
//
// This is only one of the many, many random number generator test we could do,
// but they are cumbersome, as they are typically very slow, and expected to
// fail from time to time, due to their probabilistic nature.
//
// The generator we use has however been vetted with the BigCrush test suite
// from Marsaglia, so this should suffice as a smoke test that our
// implementation is wrong.
bool ChiSquaredTest(InsecureRandomGenerator& gen,
                    size_t n,
                    int from_bit,
                    int num_bits) {}

}  // namespace

TEST(RandUtilTest, InsecureRandomGeneratorChiSquared) {}

TEST(RandUtilTest, InsecureRandomGeneratorRandDouble) {}

TEST(RandUtilTest, MetricsSubSampler) {}

TEST(RandUtilTest, MetricsSubSamplerTestingSupport) {}

}  // namespace base