libcxx initial import
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@103490 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
93
test/numerics/rand/rand.adapt/rand.adapt.shuf/eval.pass.cpp
Normal file
93
test/numerics/rand/rand.adapt/rand.adapt.shuf/eval.pass.cpp
Normal file
@@ -0,0 +1,93 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <random>
|
||||
|
||||
// template<class Engine, size_t k>
|
||||
// class shuffle_order_engine
|
||||
|
||||
// result_type operator()();
|
||||
|
||||
#include <random>
|
||||
#include <cassert>
|
||||
|
||||
template <class UIntType, UIntType Min, UIntType Max>
|
||||
class rand1
|
||||
{
|
||||
public:
|
||||
// types
|
||||
typedef UIntType result_type;
|
||||
|
||||
private:
|
||||
result_type x_;
|
||||
|
||||
static_assert(Min < Max, "rand1 invalid parameters");
|
||||
public:
|
||||
|
||||
// Temporary work around for lack of constexpr
|
||||
static const result_type _Min = Min;
|
||||
static const result_type _Max = Max;
|
||||
|
||||
static const/*expr*/ result_type min() {return Min;}
|
||||
static const/*expr*/ result_type max() {return Max;}
|
||||
|
||||
explicit rand1(result_type sd = Min) : x_(sd)
|
||||
{
|
||||
if (x_ < Min)
|
||||
x_ = Min;
|
||||
if (x_ > Max)
|
||||
x_ = Max;
|
||||
}
|
||||
|
||||
result_type operator()()
|
||||
{
|
||||
result_type r = x_;
|
||||
if (x_ < Max)
|
||||
++x_;
|
||||
else
|
||||
x_ = Min;
|
||||
return r;
|
||||
}
|
||||
};
|
||||
|
||||
void
|
||||
test1()
|
||||
{
|
||||
typedef std::knuth_b E;
|
||||
|
||||
E e;
|
||||
assert(e() == 152607844u);
|
||||
}
|
||||
|
||||
void
|
||||
test2()
|
||||
{
|
||||
typedef rand1<unsigned long long, 0, 0xFFFFFFFFFFFFFFFFull> E0;
|
||||
typedef std::shuffle_order_engine<E0, 101> E;
|
||||
E e;
|
||||
e.discard(400);
|
||||
assert(e() == 501);
|
||||
}
|
||||
|
||||
void
|
||||
test3()
|
||||
{
|
||||
typedef rand1<unsigned long long, 0, 0xFFFFFFFFFFFFFFFFull> E0;
|
||||
typedef std::shuffle_order_engine<E0, 100> E;
|
||||
E e;
|
||||
e.discard(400);
|
||||
assert(e() == 500);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test1();
|
||||
test2();
|
||||
test3();
|
||||
}
|
Reference in New Issue
Block a user