Move test into test/std subdirectory.

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@224658 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Eric Fiselier
2014-12-20 01:40:03 +00:00
parent 669a8a5a19
commit a90c6dd460
4817 changed files with 13 additions and 0 deletions

View File

@@ -0,0 +1,12 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
int main()
{
}

View File

@@ -0,0 +1,12 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
int main()
{
}

View File

@@ -0,0 +1,56 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <random>
// template<class Engine, size_t p, size_t r>
// class discard_block_engine
// discard_block_engine& operator=(const discard_block_engine&);
#include <random>
#include <cassert>
void
test1()
{
typedef std::ranlux24 E;
E e1(2);
e1();
E e2(5);
e2 = e1;
assert(e1 == e2);
assert(e1() == e2());
E::result_type k = e1();
assert(e1 != e2);
assert(e2() == k);
assert(e1 == e2);
}
void
test2()
{
typedef std::ranlux48 E;
E e1(3);
e1();
E e2(5);
e2 = e1;
assert(e1 == e2);
assert(e1() == e2());
E::result_type k = e1();
assert(e1 != e2);
assert(e2() == k);
assert(e1 == e2);
}
int main()
{
test1();
test2();
}

View File

@@ -0,0 +1,54 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <random>
// template<class Engine, size_t p, size_t r>
// class discard_block_engine
// discard_block_engine(const discard_block_engine&);
#include <random>
#include <cassert>
void
test1()
{
typedef std::ranlux24 E;
E e1;
e1();
E e2 = e1;
assert(e1 == e2);
assert(e1() == e2());
E::result_type k = e1();
assert(e1 != e2);
assert(e2() == k);
assert(e1 == e2);
}
void
test2()
{
typedef std::ranlux48 E;
E e1;
e1();
E e2 = e1;
assert(e1 == e2);
assert(e1() == e2());
E::result_type k = e1();
assert(e1 != e2);
assert(e2() == k);
assert(e1 == e2);
}
int main()
{
test1();
test2();
}

View File

@@ -0,0 +1,29 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <random>
// template<class Engine, size_t p, size_t r>
// class discard_block_engine
// explicit discard_block_engine(const Engine& e);
#include <random>
#include <cassert>
int main()
{
{
typedef std::ranlux24_base Engine;
typedef std::ranlux24 Adaptor;
Engine e;
Adaptor a(e);
assert(a.base() == e);
}
}

View File

@@ -0,0 +1,30 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <random>
// template<class Engine, size_t p, size_t r>
// class discard_block_engine
// explicit discard_block_engine(const Engine& e);
#include <random>
#include <cassert>
int main()
{
{
typedef std::ranlux24_base Engine;
typedef std::ranlux24 Adaptor;
Engine e;
Engine e0 = e;
Adaptor a(std::move(e0));
assert(a.base() == e);
}
}

View File

@@ -0,0 +1,51 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <random>
// template<class Engine, size_t p, size_t r>
// class discard_block_engine
// explicit discard_block_engine(result_type s = default_seed);
#include <random>
#include <sstream>
#include <cassert>
void
test1()
{
const char* a = "15136306 8587749 2346244 16479026 15515802 9510553 "
"16090340 14501685 13839944 10789678 11581259 9590790 5840316 5953700 "
"13398366 8134459 16629731 6851902 15583892 1317475 4231148 9092691 "
"5707268 2355175 0 0";
std::ranlux24 e1(0);
std::ostringstream os;
os << e1;
assert(os.str() == a);
}
void
test2()
{
const char* a = "10880375256626 126660097854724 33643165434010 "
"78293780235492 179418984296008 96783156950859 238199764491708 "
"34339434557790 155299155394531 29014415493780 209265474179052 "
"263777435457028 0 0";
std::ranlux48 e1(0);
std::ostringstream os;
os << e1;
assert(os.str() == a);
}
int main()
{
test1();
test2();
}

View File

@@ -0,0 +1,55 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <random>
// template<class Engine, size_t p, size_t r>
// class discard_block_engine
// template<class Sseq> explicit discard_block_engine(Sseq& q);
#include <random>
#include <sstream>
#include <cassert>
void
test1()
{
const char* a = "13604817 711567 9760686 13278398 3323440 175548 5553651 "
"3028863 10748297 2216688 275779 14778841 14438394 9483441 4229545 "
"14657301 12636508 15978210 1653340 1718567 9272421 14302862 7940348 "
"889045 0 0";
unsigned as[] = {3, 5, 7};
std::seed_seq sseq(as, as+3);
std::ranlux24 e1(sseq);
std::ostringstream os;
os << e1;
assert(os.str() == a);
}
void
test2()
{
const char* a = "241408498702289 172342669275054 191026374555184 "
"61020585639411 231929771458953 142769679250755 198672786411514 "
"183712717244841 227473912549724 62843577252444 68782400568421 "
"159248704678140 0 0";
unsigned as[] = {3, 5, 7};
std::seed_seq sseq(as, as+3);
std::ranlux48 e1(sseq);
std::ostringstream os;
os << e1;
assert(os.str() == a);
}
int main()
{
test1();
test2();
}

View File

@@ -0,0 +1,42 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <random>
// template<class Engine, size_t p, size_t r>
// class discard_block_engine
// explicit discard_block_engine();
#include <random>
#include <cassert>
void
test1()
{
std::ranlux24 e1;
std::ranlux24 e2(std::ranlux24_base::default_seed);
assert(e1 == e2);
assert(e1() == 15039276);
}
void
test2()
{
std::ranlux48 e1;
std::ranlux48 e2(std::ranlux48_base::default_seed);
assert(e1 == e2);
assert(e1() == 23459059301164ull);
}
int main()
{
test1();
test2();
}

View File

@@ -0,0 +1,52 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <random>
// template<class Engine, size_t p, size_t r>
// class discard_block_engine
// void discard(unsigned long long z);
#include <random>
#include <cassert>
void
test1()
{
std::ranlux24 e1;
std::ranlux24 e2 = e1;
assert(e1 == e2);
e1.discard(3);
assert(e1 != e2);
e2();
e2();
e2();
assert(e1 == e2);
}
void
test2()
{
std::ranlux48 e1;
std::ranlux48 e2 = e1;
assert(e1 == e2);
e1.discard(3);
assert(e1 != e2);
e2();
e2();
e2();
assert(e1 == e2);
}
int main()
{
test1();
test2();
}

View File

@@ -0,0 +1,42 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <random>
// template<class Engine, size_t p, size_t r>
// class discard_block_engine
// result_type operator()();
#include <random>
#include <cassert>
void
test1()
{
std::ranlux24 e;
assert(e() == 15039276u);
assert(e() == 16323925u);
assert(e() == 14283486u);
}
void
test2()
{
std::ranlux48 e;
assert(e() == 23459059301164ull);
assert(e() == 28639057539807ull);
assert(e() == 276846226770426ull);
}
int main()
{
test1();
test2();
}

View File

@@ -0,0 +1,63 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <random>
// template<class Engine, size_t p, size_t r>
// class discard_block_engine
// template <class charT, class traits,
// class Engine, size_t p, size_t r>
// basic_ostream<charT, traits>&
// operator<<(basic_ostream<charT, traits>& os,
// const discard_block_engine<Engine, p, r>& x);
//
// template <class charT, class traits,
// class Engine, size_t p, size_t r>
// basic_istream<charT, traits>&
// operator>>(basic_istream<charT, traits>& is,
// discard_block_engine<Engine, p, r>& x);
#include <random>
#include <sstream>
#include <cassert>
void
test1()
{
typedef std::ranlux24 E;
E e1;
e1.discard(100);
std::ostringstream os;
os << e1;
std::istringstream is(os.str());
E e2;
is >> e2;
assert(e1 == e2);
}
void
test2()
{
typedef std::ranlux48 E;
E e1;
e1.discard(100);
std::ostringstream os;
os << e1;
std::istringstream is(os.str());
E e2;
is >> e2;
assert(e1 == e2);
}
int main()
{
test1();
test2();
}

View File

@@ -0,0 +1,42 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <random>
// template<class Engine, size_t p, size_t r>
// class discard_block_engine
// {
// public:
// // types
// typedef typename Engine::result_type result_type;
#include <random>
#include <type_traits>
void
test1()
{
static_assert((std::is_same<
std::ranlux24::result_type,
std::uint_fast32_t>::value), "");
}
void
test2()
{
static_assert((std::is_same<
std::ranlux48::result_type,
std::uint_fast64_t>::value), "");
}
int main()
{
test1();
test2();
}

View File

@@ -0,0 +1,50 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <random>
// template<class Engine, size_t p, size_t r>
// class discard_block_engine
// void seed(result_type s = default_seed);
#include <random>
#include <cassert>
void
test1()
{
for (int s = 0; s < 20; ++s)
{
typedef std::ranlux24 E;
E e1(s);
E e2;
e2.seed(s);
assert(e1 == e2);
}
}
void
test2()
{
for (int s = 0; s < 20; ++s)
{
typedef std::ranlux48 E;
E e1(s);
E e2;
e2.seed(s);
assert(e1 == e2);
}
}
int main()
{
test1();
test2();
}

View File

@@ -0,0 +1,48 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <random>
// template<class Engine, size_t p, size_t r>
// class discard_block_engine
// template<class Sseq> void seed(Sseq& q);
#include <random>
#include <cassert>
void
test1()
{
unsigned a[] = {3, 5, 7};
std::seed_seq sseq(a, a+3);
std::ranlux24 e1;
std::ranlux24 e2(sseq);
assert(e1 != e2);
e1.seed(sseq);
assert(e1 == e2);
}
void
test2()
{
unsigned a[] = {3, 5, 7};
std::seed_seq sseq(a, a+3);
std::ranlux48 e1;
std::ranlux48 e2(sseq);
assert(e1 != e2);
e1.seed(sseq);
assert(e1 == e2);
}
int main()
{
test1();
test2();
}

View File

@@ -0,0 +1,60 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <random>
// template<class Engine, size_t p, size_t r>
// class discard_block_engine
// {
// public:
// // types
// typedef typename Engine::result_type result_type;
//
// // engine characteristics
// static constexpr size_t block_size = p;
// static constexpr size_t used_block = r;
// static constexpr result_type min() { return Engine::min(); }
// static constexpr result_type max() { return Engine::max(); }
#include <random>
#include <type_traits>
#include <cassert>
template <class _Tp>
void where(const _Tp &) {}
void
test1()
{
typedef std::ranlux24 E;
static_assert((E::block_size == 223), "");
static_assert((E::used_block == 23), "");
/*static_*/assert((E::min() == 0)/*, ""*/);
/*static_*/assert((E::max() == 0xFFFFFF)/*, ""*/);
where(E::block_size);
where(E::used_block);
}
void
test2()
{
typedef std::ranlux48 E;
static_assert((E::block_size == 389), "");
static_assert((E::used_block == 11), "");
/*static_*/assert((E::min() == 0)/*, ""*/);
/*static_*/assert((E::max() == 0xFFFFFFFFFFFFull)/*, ""*/);
where(E::block_size);
where(E::used_block);
}
int main()
{
test1();
test2();
}

View File

@@ -0,0 +1,56 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <random>
// template<class Engine, size_t w, class UIntType>
// class independent_bits_engine
// independent_bits_engine& operator=(const independent_bits_engine&);
#include <random>
#include <cassert>
void
test1()
{
typedef std::independent_bits_engine<std::ranlux24, 32, unsigned> E;
E e1(2);
e1();
E e2(5);
e2 = e1;
assert(e1 == e2);
assert(e1() == e2());
E::result_type k = e1();
assert(e1 != e2);
assert(e2() == k);
assert(e1 == e2);
}
void
test2()
{
typedef std::independent_bits_engine<std::ranlux48, 64, unsigned long long> E;
E e1(3);
e1();
E e2(5);
e2 = e1;
assert(e1 == e2);
assert(e1() == e2());
E::result_type k = e1();
assert(e1 != e2);
assert(e2() == k);
assert(e1 == e2);
}
int main()
{
test1();
test2();
}

View File

@@ -0,0 +1,54 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <random>
// template<class Engine, size_t w, class UIntType>
// class independent_bits_engine
// independent_bits_engine(const independent_bits_engine&);
#include <random>
#include <cassert>
void
test1()
{
typedef std::independent_bits_engine<std::ranlux24, 32, unsigned> E;
E e1;
e1();
E e2 = e1;
assert(e1 == e2);
assert(e1() == e2());
E::result_type k = e1();
assert(e1 != e2);
assert(e2() == k);
assert(e1 == e2);
}
void
test2()
{
typedef std::independent_bits_engine<std::ranlux48, 64, unsigned long long> E;
E e1;
e1();
E e2 = e1;
assert(e1 == e2);
assert(e1() == e2());
E::result_type k = e1();
assert(e1 != e2);
assert(e2() == k);
assert(e1 == e2);
}
int main()
{
test1();
test2();
}

View File

@@ -0,0 +1,29 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <random>
// template<class Engine, size_t w, class UIntType>
// class independent_bits_engine
// explicit independent_bits_engine(const Engine& e);
#include <random>
#include <cassert>
int main()
{
{
typedef std::mt19937 Engine;
typedef std::independent_bits_engine<Engine, 24, unsigned> Adaptor;
Engine e;
Adaptor a(e);
assert(a.base() == e);
}
}

View File

@@ -0,0 +1,30 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <random>
// template<class Engine, size_t w, class UIntType>
// class independent_bits_engine
// explicit independent_bits_engine(const Engine& e);
#include <random>
#include <cassert>
int main()
{
{
typedef std::mt19937 Engine;
typedef std::independent_bits_engine<Engine, 24, unsigned> Adaptor;
Engine e;
Engine e0 = e;
Adaptor a(std::move(e0));
assert(a.base() == e);
}
}

View File

@@ -0,0 +1,51 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <random>
// template<class Engine, size_t w, class UIntType>
// class independent_bits_engine
// explicit independent_bits_engine(result_type s = default_seed);
#include <random>
#include <sstream>
#include <cassert>
void
test1()
{
const char* a = "15136306 8587749 2346244 16479026 15515802 9510553 "
"16090340 14501685 13839944 10789678 11581259 9590790 5840316 5953700 "
"13398366 8134459 16629731 6851902 15583892 1317475 4231148 9092691 "
"5707268 2355175 0 0";
std::independent_bits_engine<std::ranlux24, 32, unsigned> e1(0);
std::ostringstream os;
os << e1;
assert(os.str() == a);
}
void
test2()
{
const char* a = "10880375256626 126660097854724 33643165434010 "
"78293780235492 179418984296008 96783156950859 238199764491708 "
"34339434557790 155299155394531 29014415493780 209265474179052 "
"263777435457028 0 0";
std::independent_bits_engine<std::ranlux48, 64, unsigned long long> e1(0);
std::ostringstream os;
os << e1;
assert(os.str() == a);
}
int main()
{
test1();
test2();
}

View File

@@ -0,0 +1,55 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <random>
// template<class Engine, size_t w, class UIntType>
// class independent_bits_engine
// template<class Sseq> explicit independent_bits_engine(Sseq& q);
#include <random>
#include <sstream>
#include <cassert>
void
test1()
{
const char* a = "13604817 711567 9760686 13278398 3323440 175548 5553651 "
"3028863 10748297 2216688 275779 14778841 14438394 9483441 4229545 "
"14657301 12636508 15978210 1653340 1718567 9272421 14302862 7940348 "
"889045 0 0";
unsigned as[] = {3, 5, 7};
std::seed_seq sseq(as, as+3);
std::independent_bits_engine<std::ranlux24, 32, unsigned> e1(sseq);
std::ostringstream os;
os << e1;
assert(os.str() == a);
}
void
test2()
{
const char* a = "241408498702289 172342669275054 191026374555184 "
"61020585639411 231929771458953 142769679250755 198672786411514 "
"183712717244841 227473912549724 62843577252444 68782400568421 "
"159248704678140 0 0";
unsigned as[] = {3, 5, 7};
std::seed_seq sseq(as, as+3);
std::independent_bits_engine<std::ranlux48, 64, unsigned long long> e1(sseq);
std::ostringstream os;
os << e1;
assert(os.str() == a);
}
int main()
{
test1();
test2();
}

View File

@@ -0,0 +1,42 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <random>
// template<class Engine, size_t w, class UIntType>
// class independent_bits_engine
// explicit independent_bits_engine();
#include <random>
#include <cassert>
void
test1()
{
std::independent_bits_engine<std::ranlux24, 32, unsigned> e1;
std::independent_bits_engine<std::ranlux24, 32, unsigned> e2(std::ranlux24_base::default_seed);
assert(e1 == e2);
assert(e1() == 2066486613);
}
void
test2()
{
std::independent_bits_engine<std::ranlux48, 64, unsigned long long> e1;
std::independent_bits_engine<std::ranlux48, 64, unsigned long long> e2(std::ranlux48_base::default_seed);
assert(e1 == e2);
assert(e1() == 18223106896348967647ull);
}
int main()
{
test1();
test2();
}

View File

@@ -0,0 +1,52 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <random>
// template<class Engine, size_t w, class UIntType>
// class independent_bits_engine
// void discard(unsigned long long z);
#include <random>
#include <cassert>
void
test1()
{
std::independent_bits_engine<std::ranlux24, 32, unsigned> e1;
std::independent_bits_engine<std::ranlux24, 32, unsigned> e2 = e1;
assert(e1 == e2);
e1.discard(3);
assert(e1 != e2);
e2();
e2();
e2();
assert(e1 == e2);
}
void
test2()
{
std::independent_bits_engine<std::ranlux48, 64, unsigned long long> e1;
std::independent_bits_engine<std::ranlux48, 64, unsigned long long> e2 = e1;
assert(e1 == e2);
e1.discard(3);
assert(e1 != e2);
e2();
e2();
e2();
assert(e1 == e2);
}
int main()
{
test1();
test2();
}

View File

@@ -0,0 +1,141 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <random>
// template<class Engine, size_t w, class UIntType>
// class independent_bits_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:
#ifdef _LIBCPP_HAS_NO_CONSTEXPR
// Workaround for lack of constexpr in C++03
static const result_type _Min = Min;
static const result_type _Max = Max;
#endif
static _LIBCPP_CONSTEXPR result_type min() {return Min;}
static _LIBCPP_CONSTEXPR result_type max() {return Max;}
explicit rand1(result_type sd = Min) : x_(sd)
{
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::independent_bits_engine<rand1<unsigned, 0, 10>, 16, unsigned> E;
E e;
assert(e() == 6958);
}
void
test2()
{
typedef std::independent_bits_engine<rand1<unsigned, 0, 100>, 16, unsigned> E;
E e;
assert(e() == 66);
}
void
test3()
{
typedef std::independent_bits_engine<rand1<unsigned, 0, 0xFFFFFFFF>, 32, unsigned> E;
E e(5);
assert(e() == 5);
}
void
test4()
{
typedef std::independent_bits_engine<rand1<unsigned, 0, 0xFFFFFFFF>, 7, unsigned> E;
E e(129);
assert(e() == 1);
}
void
test5()
{
typedef std::independent_bits_engine<rand1<unsigned, 2, 3>, 1, unsigned> E;
E e(6);
assert(e() == 1);
}
void
test6()
{
typedef std::independent_bits_engine<rand1<unsigned, 2, 3>, 11, unsigned> E;
E e(6);
assert(e() == 1365);
}
void
test7()
{
typedef std::independent_bits_engine<rand1<unsigned, 2, 3>, 32, unsigned> E;
E e(6);
assert(e() == 2863311530u);
}
void
test8()
{
typedef std::independent_bits_engine<std::mt19937, 64, unsigned long long> E;
E e(6);
assert(e() == 16470362623952407241ull);
}
int main()
{
test1();
test2();
test3();
test4();
test5();
test6();
test7();
test8();
}

View File

@@ -0,0 +1,63 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <random>
// template<class Engine, size_t w, class UIntType>
// class independent_bits_engine
// template <class charT, class traits,
// class Engine, size_t w, class UIntType>
// basic_ostream<charT, traits>&
// operator<<(basic_ostream<charT, traits>& os,
// const independent_bits_engine<Engine, w, UIntType>& x);
//
// template <class charT, class traits,
// class Engine, size_t w, class UIntType>
// basic_istream<charT, traits>&
// operator>>(basic_istream<charT, traits>& is,
// independent_bits_engine<Engine, w, UIntType>& x);
#include <random>
#include <sstream>
#include <cassert>
void
test1()
{
typedef std::independent_bits_engine<std::ranlux24, 32, unsigned> E;
E e1;
e1.discard(100);
std::ostringstream os;
os << e1;
std::istringstream is(os.str());
E e2;
is >> e2;
assert(e1 == e2);
}
void
test2()
{
typedef std::independent_bits_engine<std::ranlux48, 64, unsigned long long> E;
E e1;
e1.discard(100);
std::ostringstream os;
os << e1;
std::istringstream is(os.str());
E e2;
is >> e2;
assert(e1 == e2);
}
int main()
{
test1();
test2();
}

View File

@@ -0,0 +1,83 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <random>
// template<class Engine, size_t w, class UIntType>
// class independent_bits_engine
// {
// public:
// // types
// typedef UIntType result_type;
#include <random>
#include <type_traits>
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:
#ifdef _LIBCPP_HAS_NO_CONSTEXPR
// Workaround for lack of constexpr in C++03
static const result_type _Min = Min;
static const result_type _Max = Max;
#endif
static _LIBCPP_CONSTEXPR result_type min() {return Min;}
static _LIBCPP_CONSTEXPR 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()
{
static_assert((std::is_same<
std::independent_bits_engine<rand1<unsigned long, 0, 10>, 16, unsigned>::result_type,
unsigned>::value), "");
}
void
test2()
{
static_assert((std::is_same<
std::independent_bits_engine<rand1<unsigned long, 0, 10>, 16, unsigned long long>::result_type,
unsigned long long>::value), "");
}
int main()
{
test1();
test2();
}

View File

@@ -0,0 +1,50 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <random>
// template<class Engine, size_t w, class UIntType>
// class independent_bits_engine
// void seed(result_type s = default_seed);
#include <random>
#include <cassert>
void
test1()
{
for (int s = 0; s < 20; ++s)
{
typedef std::independent_bits_engine<std::ranlux24, 32, unsigned> E;
E e1(s);
E e2;
e2.seed(s);
assert(e1 == e2);
}
}
void
test2()
{
for (int s = 0; s < 20; ++s)
{
typedef std::independent_bits_engine<std::ranlux48, 64, unsigned long long> E;
E e1(s);
E e2;
e2.seed(s);
assert(e1 == e2);
}
}
int main()
{
test1();
test2();
}

View File

@@ -0,0 +1,48 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <random>
// template<class Engine, size_t w, class UIntType>
// class independent_bits_engine
// template<class Sseq> void seed(Sseq& q);
#include <random>
#include <cassert>
void
test1()
{
unsigned a[] = {3, 5, 7};
std::seed_seq sseq(a, a+3);
std::independent_bits_engine<std::ranlux24, 32, unsigned> e1;
std::independent_bits_engine<std::ranlux24, 32, unsigned> e2(sseq);
assert(e1 != e2);
e1.seed(sseq);
assert(e1 == e2);
}
void
test2()
{
unsigned a[] = {3, 5, 7};
std::seed_seq sseq(a, a+3);
std::independent_bits_engine<std::ranlux48, 64, unsigned long long> e1;
std::independent_bits_engine<std::ranlux48, 64, unsigned long long> e2(sseq);
assert(e1 != e2);
e1.seed(sseq);
assert(e1 == e2);
}
int main()
{
test1();
test2();
}

View File

@@ -0,0 +1,47 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <random>
// template<class Engine, size_t w, class UIntType>
// class independent_bits_engine
// {
// public:
// // types
// typedef UIntType result_type;
//
// // engine characteristics
// static constexpr result_type min() { return 0; }
// static constexpr result_type max() { return 2^w - 1; }
#include <random>
#include <type_traits>
#include <cassert>
void
test1()
{
typedef std::independent_bits_engine<std::ranlux24, 32, unsigned> E;
/*static_*/assert((E::min() == 0)/*, ""*/);
/*static_*/assert((E::max() == 0xFFFFFFFF)/*, ""*/);
}
void
test2()
{
typedef std::independent_bits_engine<std::ranlux48, 64, unsigned long long> E;
/*static_*/assert((E::min() == 0)/*, ""*/);
/*static_*/assert((E::max() == 0xFFFFFFFFFFFFFFFFull)/*, ""*/);
}
int main()
{
test1();
test2();
}

View File

@@ -0,0 +1,39 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <random>
// template<class Engine, size_t k>
// class shuffle_order_engine
// shuffle_order_engine& operator=(const shuffle_order_engine&);
#include <random>
#include <cassert>
void
test1()
{
typedef std::knuth_b E;
E e1(2);
e1();
E e2(5);
e2 = e1;
assert(e1 == e2);
assert(e1() == e2());
E::result_type k = e1();
assert(e1 != e2);
assert(e2() == k);
assert(e1 == e2);
}
int main()
{
test1();
}

View File

@@ -0,0 +1,38 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <random>
// template<class Engine, size_t k>
// class shuffle_order_engine
// shuffle_order_engine(const shuffle_order_engine&);
#include <random>
#include <cassert>
void
test1()
{
typedef std::knuth_b E;
E e1;
e1();
E e2 = e1;
assert(e1 == e2);
assert(e1() == e2());
E::result_type k = e1();
assert(e1 != e2);
assert(e2() == k);
assert(e1 == e2);
}
int main()
{
test1();
}

View File

@@ -0,0 +1,31 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <random>
// template<class Engine, size_t k>
// class shuffle_order_engine
// explicit shuffle_order_engine(const Engine& e);
#include <random>
#include <cassert>
int main()
{
{
typedef std::minstd_rand0 Engine;
typedef std::knuth_b Adaptor;
Engine e;
Adaptor a(e);
for (unsigned k = 0; k <= Adaptor::table_size; ++k)
e();
assert(a.base() == e);
}
}

View File

@@ -0,0 +1,32 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <random>
// template<class Engine, size_t k>
// class shuffle_order_engine
// explicit shuffle_order_engine(const Engine& e);
#include <random>
#include <cassert>
int main()
{
{
typedef std::minstd_rand0 Engine;
typedef std::knuth_b Adaptor;
Engine e;
Engine e0 = e;
Adaptor a(std::move(e0));
for (unsigned k = 0; k <= Adaptor::table_size; ++k)
e();
assert(a.base() == e);
}
}

View File

@@ -0,0 +1,76 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <random>
// template<class Engine, size_t k>
// class shuffle_order_engine
// explicit shuffle_order_engine(result_type s = default_seed);
#include <random>
#include <sstream>
#include <cassert>
void
test1()
{
const char* a = "1771550148 168070 677268843 1194115201 1259501992 "
"703671065 407145426 1010275440 1693606898 1702877348 745024267 "
"1793193459 416963415 664975744 742430420 1148079870 637806795 "
"1527921388 165317290 1791337459 1435426120 375508442 1863429808 "
"1910758855 653618747 991426424 578291095 1974930990 1157900898 "
"343583572 25567821 221638147 1335692731 1341167826 1019292670 "
"774852571 606325389 700907908 1211405961 1955012967 1403137269 "
"1010152376 1772753897 486628401 1145807831 1106352968 1560917450 "
"679350398 1819071734 1561434646 781928982 1427964481 1669276942 "
"811199786 1608612146 1272705739 1428231253 1857946652 2097152784 "
"197742477 1300609030 99924397 97128425 349867255 408729299 1860625187 "
"2018133942 1420442476 1948474080 1025729457 1583749330 15184745 "
"1806938869 1655319056 296727307 638820415 1383963552 880037807 "
"1075545360 1321008721 1507631161 597371974 544717293 340756290 "
"1899563128 1465595994 634440068 777915521 545718511 2135841687 "
"1902073804 712854586 135760289 1095544109 285050585 1956649285 "
"987446484 259432572 891434194 1488577086 330596852 801096775 "
"1458514382 1872871416 1682074633 1153627723 1538775345 51662594 "
"709823970 739804705 2114844452 1188863267 1037076781 1172179215 "
"1948572574 533634468 902793804 1283497773 273836696 315894151 "
"653420473 1954002600 1601768276 64415940 306945492 577163950 "
"210874151 813838307 857078006 1737226413 376658679 1868110244 "
"1117951768 1080937173 1746896638 1842856729 1883887269 2141922362 "
"1020763473 1872318475 978729834 1935067665 1189895487 1205729145 "
"1034046923 1788963337 188263312 898072753 1393688555 1119406056 "
"1900835472 1375045132 1312008157 559007303 2142269543 413383599 "
"628550348 573639243 1100665718 464587168 65992084 1027393936 "
"1641360472 1918007189 69800406 609352380 35938117 569027612 902394793 "
"1019770837 221470752 669768613 1839284764 1979413630 1335703733 "
"1526078440 1403144959 1139398206 753967943 1785700701 1187714882 "
"1063522909 1123137582 192083544 680202567 1109090588 327456556 "
"1709233078 191596027 1076438936 1306955024 1530346852 127901445 "
"8455468 377129974 1199230721 1336700752 1103107597 703058228 "
"844612202 530372344 1910850558 47387421 1871435357 1168551137 "
"1101007744 1918050856 803711675 309982095 73743043 301259382 "
"1647477295 1644236294 859823662 638826571 1487427444 335916581 "
"15468904 140348241 895842081 410006250 1847504174 536600445 "
"1359845362 1400027760 288242141 1910039802 1453396858 1761991428 "
"2137921913 357210187 1414819544 1933136424 943782705 841706193 "
"1081202962 1919045067 333546776 988345562 337850989 314809455 "
"1750287624 853099962 1450233962 142805884 1399258689 247367726 "
"2128513937 1151147433 654730608 351121428 12778440 18876380 "
"1575222551 587014441 411835569 380613902 1771550148";
std::knuth_b e1(10);
std::ostringstream os;
os << e1;
assert(os.str() == a);
}
int main()
{
test1();
}

View File

@@ -0,0 +1,79 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <random>
// template<class Engine, size_t k>
// class shuffle_order_engine
// template<class Sseq> explicit shuffle_order_engine(Sseq& q);
#include <random>
#include <sstream>
#include <cassert>
void
test1()
{
const char* a = "1894661934 884942216 1899568837 1561547157 525417712 "
"242729120 1476874187 1208468883 1983666902 1953485886 1507290666 "
"1317123450 632390874 696850315 1734917114 218976032 1690682513 "
"1944862534 456017951 2072049961 1348874775 1700965693 828093387 "
"2071522749 1077957279 1055942061 413360419 238964088 475007126 "
"1248050783 1516729632 1044035134 9617501 580065782 1737324341 "
"2022534575 219953662 941840747 415472792 1381878747 200458524 "
"1852054372 1849850586 1318041283 1026024576 101363422 660501483 "
"705453438 298717379 1873705814 673416290 868766340 614560427 "
"1668238166 532360730 969915708 1972423626 1966307090 97417947 "
"920896215 588041576 495024338 522400288 1068491480 878048146 "
"1995051285 17282737 560668414 2143274709 127339385 1299331283 "
"99667038 66663006 1566161755 773555006 272986904 1065825536 "
"1168683925 1185292013 1144552919 1489883454 811887358 279732868 "
"628609193 1562647158 1833265343 1742736292 639398211 357562689 "
"896869717 501615326 1775469607 1032409784 43371928 955037563 "
"1023543663 1354331571 1071539244 562210166 138213162 1518791327 "
"1335204647 1727874626 2114964448 1058152392 1055171537 348065433 "
"190278003 399246038 1389247438 1639480282 382424917 2144508195 "
"1531185764 1342593547 1359065400 1176108308 1412845568 968776497 "
"5573525 1332437854 323541262 329396230 2097079291 1110029273 "
"1071549822 739994612 1011644107 1074473050 478563727 894301674 "
"290189565 280656618 1121689914 1630931232 579945916 1870220126 "
"71516543 1535179528 1893792038 1107650479 1893348357 93154853 "
"138035708 683805596 1535656875 1326628479 1469623399 1751042846 "
"661214234 1947241260 1780560187 690441964 1403944207 1687457460 "
"1428487938 1877084153 1618585041 1383427538 461185097 869443256 "
"1254069404 1739961370 1245924391 138197640 1257913073 1915996843 "
"641653536 1755587965 1889101622 1732723706 2009073422 1611621773 "
"315899200 738279016 94909546 1711873548 1620302377 181922632 "
"1704446343 1345319468 2076463060 357902023 157605314 1025175647 "
"865799248 138769064 124418006 1591838311 675218651 1096276609 "
"1858759850 732186041 769493777 735387805 894450150 638142050 "
"720101232 1671055379 636619387 898507955 118193981 63865192 "
"1787942091 204050966 2100684950 1580797970 1951284753 1020070334 "
"960149537 1041144801 823914651 558983501 1742229329 708805658 "
"804904097 1023665826 1260041465 1180659188 590074436 301564006 "
"324841922 714752380 1967212989 290476911 815113546 815183409 "
"1989370850 1182975807 870784323 171062356 1711897606 2024645183 "
"1333203966 314683764 1785282634 603713754 1904315050 1874254109 "
"1298675767 1967311508 1946285744 753588304 1847558969 1457540010 "
"528986741 97857407 1864449494 1868752281 1171249392 1353422942 "
"832597170 457192338 335135800 1925268166 1845956613 296546482 "
"1894661934";
unsigned as[] = {3, 5, 7};
std::seed_seq sseq(as, as+3);
std::knuth_b e1(sseq);
std::ostringstream os;
os << e1;
assert(os.str() == a);
}
int main()
{
test1();
}

View File

@@ -0,0 +1,32 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <random>
// template<class Engine, size_t k>
// class shuffle_order_engine
// explicit shuffle_order_engine();
#include <random>
#include <cassert>
void
test1()
{
std::knuth_b e1;
std::knuth_b e2(std::minstd_rand0::default_seed);
assert(e1 == e2);
assert(e1() == 152607844u);
}
int main()
{
test1();
}

View File

@@ -0,0 +1,37 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <random>
// template<class Engine, size_t k>
// class shuffle_order_engine
// void discard(unsigned long long z);
#include <random>
#include <cassert>
void
test1()
{
std::knuth_b e1;
std::knuth_b e2 = e1;
assert(e1 == e2);
e1.discard(3);
assert(e1 != e2);
e2();
e2();
e2();
assert(e1 == e2);
}
int main()
{
test1();
}

View File

@@ -0,0 +1,93 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. 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:
#ifdef _LIBCPP_HAS_NO_CONSTEXPR
// Workaround for lack of constexpr in C++03
static const result_type _Min = Min;
static const result_type _Max = Max;
#endif
static _LIBCPP_CONSTEXPR result_type min() {return Min;}
static _LIBCPP_CONSTEXPR result_type max() {return Max;}
explicit rand1(result_type sd = Min) : x_(sd)
{
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();
}

View File

@@ -0,0 +1,48 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <random>
// template<class Engine, size_t k>
// class shuffle_order_engine
// template <class charT, class traits,
// class Engine, size_t k>
// basic_ostream<charT, traits>&
// operator<<(basic_ostream<charT, traits>& os,
// const shuffle_order_engine<Engine, k>& x);
//
// template <class charT, class traits,
// class Engine, size_t k>
// basic_istream<charT, traits>&
// operator>>(basic_istream<charT, traits>& is,
// shuffle_order_engine<Engine, k>& x);
#include <random>
#include <sstream>
#include <cassert>
void
test1()
{
typedef std::knuth_b E;
E e1;
e1.discard(100);
std::ostringstream os;
os << e1;
std::istringstream is(os.str());
E e2;
is >> e2;
assert(e1 == e2);
}
int main()
{
test1();
}

View File

@@ -0,0 +1,83 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <random>
// template<class Engine, size_t k>
// class shuffle_order_engine
// {
// public:
// // types
// typedef typename Engine::result_type result_type;
#include <random>
#include <type_traits>
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:
#ifdef _LIBCPP_HAS_NO_CONSTEXPR
// Workaround for lack of constexpr in C++03
static const result_type _Min = Min;
static const result_type _Max = Max;
#endif
static _LIBCPP_CONSTEXPR result_type min() {return Min;}
static _LIBCPP_CONSTEXPR 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()
{
static_assert((std::is_same<
std::shuffle_order_engine<rand1<unsigned long, 0, 10>, 16>::result_type,
unsigned long>::value), "");
}
void
test2()
{
static_assert((std::is_same<
std::shuffle_order_engine<rand1<unsigned long long, 0, 10>, 16>::result_type,
unsigned long long>::value), "");
}
int main()
{
test1();
test2();
}

View File

@@ -0,0 +1,36 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <random>
// template<class Engine, size_t k>
// class shuffle_order_engine
// void seed(result_type s = default_seed);
#include <random>
#include <cassert>
void
test1()
{
for (int s = 0; s < 20; ++s)
{
typedef std::knuth_b E;
E e1(s);
E e2;
e2.seed(s);
assert(e1 == e2);
}
}
int main()
{
test1();
}

View File

@@ -0,0 +1,35 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <random>
// template<class Engine, size_t k>
// class shuffle_order_engine
// template<class Sseq> void seed(Sseq& q);
#include <random>
#include <cassert>
void
test1()
{
unsigned a[] = {3, 5, 7};
std::seed_seq sseq(a, a+3);
std::knuth_b e1;
std::knuth_b e2(sseq);
assert(e1 != e2);
e1.seed(sseq);
assert(e1 == e2);
}
int main()
{
test1();
}

View File

@@ -0,0 +1,44 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <random>
// template<class Engine, size_t k>
// class shuffle_order_engine
// {
// public:
// // types
// typedef typename Engine::result_type result_type;
//
// // engine characteristics
// static constexpr size_t table_size = k;
// static constexpr result_type min() { return Engine::min; }
// static constexpr result_type max() { return Engine::max; }
#include <random>
#include <type_traits>
#include <cassert>
template <class _Tp>
void where(const _Tp &) {}
void
test1()
{
typedef std::knuth_b E;
static_assert(E::table_size == 256, "");
/*static_*/assert((E::min() == 1)/*, ""*/);
/*static_*/assert((E::max() == 2147483646)/*, ""*/);
where(E::table_size);
}
int main()
{
test1();
}

View File

@@ -0,0 +1,85 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <random>
// class random_device;
// explicit random_device(const string& token = implementation-defined);
// For the following ctors, the standard states: "The semantics and default
// value of the token parameter are implementation-defined". Implementations
// therefore aren't required to accept any string, but the default shouldn't
// throw.
#include <random>
#include <cassert>
#include <unistd.h>
bool is_valid_random_device(const std::string &token) {
#if defined(_WIN32)
return true;
#elif defined(_LIBCPP_USING_NACL_RANDOM)
return token == "/dev/urandom";
#else // !defined(_WIN32) && !defined(_LIBCPP_USING_NACL_RANDOM)
// Not an exhaustive list: they're the only tokens that are tested below.
return token == "/dev/urandom" || token == "/dev/random";
#endif // defined(_WIN32) || defined(_LIBCPP_USING_NACL_RANDOM)
}
void check_random_device_valid(const std::string &token) {
std::random_device r(token);
}
void check_random_device_invalid(const std::string &token) {
try {
std::random_device r(token);
assert(false);
} catch (const std::system_error &e) {
}
}
int main() {
{ std::random_device r; }
{
int ec;
ec = close(STDIN_FILENO);
assert(!ec);
ec = close(STDOUT_FILENO);
assert(!ec);
ec = close(STDERR_FILENO);
assert(!ec);
std::random_device r;
}
{
std::string token = "wrong file";
if (is_valid_random_device(token))
check_random_device_valid(token);
else
check_random_device_invalid(token);
}
{
std::string token = "/dev/urandom";
if (is_valid_random_device(token))
check_random_device_valid(token);
else
check_random_device_invalid(token);
}
{
std::string token = "/dev/random";
if (is_valid_random_device(token))
check_random_device_valid(token);
else
check_random_device_invalid(token);
}
}

View File

@@ -0,0 +1,23 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <random>
// class random_device;
// double entropy() const;
#include <random>
#include <cassert>
int main()
{
std::random_device r;
double e = r.entropy();
}

View File

@@ -0,0 +1,35 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <random>
// class random_device;
// result_type operator()();
#include <random>
#include <cassert>
int main()
{
{
std::random_device r;
std::random_device::result_type e = r();
}
try
{
std::random_device r("/dev/null");
r();
assert(false);
}
catch (const std::system_error& e)
{
}
}

View File

@@ -0,0 +1,12 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
int main()
{
}

View File

@@ -0,0 +1,12 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
int main()
{
}

View File

@@ -0,0 +1,33 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <random>
// class bernoulli_distribution
// bernoulli_distribution& operator=(const bernoulli_distribution&);
#include <random>
#include <cassert>
void
test1()
{
typedef std::bernoulli_distribution D;
D d1(0.75);
D d2;
assert(d1 != d2);
d2 = d1;
assert(d1 == d2);
}
int main()
{
test1();
}

View File

@@ -0,0 +1,31 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <random>
// class bernoulli_distribution
// bernoulli_distribution(const bernoulli_distribution&);
#include <random>
#include <cassert>
void
test1()
{
typedef std::bernoulli_distribution D;
D d1(0.75);
D d2 = d1;
assert(d1 == d2);
}
int main()
{
test1();
}

View File

@@ -0,0 +1,36 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <random>
// class bernoulli_distribution
// explicit bernoulli_distribution(double p = 0.5);
#include <random>
#include <cassert>
int main()
{
{
typedef std::bernoulli_distribution D;
D d;
assert(d.p() == 0.5);
}
{
typedef std::bernoulli_distribution D;
D d(0);
assert(d.p() == 0);
}
{
typedef std::bernoulli_distribution D;
D d(0.75);
assert(d.p() == 0.75);
}
}

View File

@@ -0,0 +1,28 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <random>
// class bernoulli_distribution
// explicit bernoulli_distribution(const param_type& parm);
#include <random>
#include <cassert>
int main()
{
{
typedef std::bernoulli_distribution D;
typedef D::param_type P;
P p(0.25);
D d(p);
assert(d.p() == 0.25);
}
}

View File

@@ -0,0 +1,36 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <random>
// class bernoulli_distribution
// bool operator=(const bernoulli_distribution& x,
// const bernoulli_distribution& y);
// bool operator!(const bernoulli_distribution& x,
// const bernoulli_distribution& y);
#include <random>
#include <cassert>
int main()
{
{
typedef std::bernoulli_distribution D;
D d1(.25);
D d2(.25);
assert(d1 == d2);
}
{
typedef std::bernoulli_distribution D;
D d1(.28);
D d2(.25);
assert(d1 != d2);
}
}

View File

@@ -0,0 +1,103 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <random>
// class bernoulli_distribution
// template<class _URNG> result_type operator()(_URNG& g);
#include <random>
#include <numeric>
#include <vector>
#include <cassert>
template <class T>
inline
T
sqr(T x)
{
return x * x;
}
int main()
{
{
typedef std::bernoulli_distribution D;
typedef std::minstd_rand G;
G g;
D d(.75);
const int N = 100000;
std::vector<D::result_type> u;
for (int i = 0; i < N; ++i)
u.push_back(d(g));
double mean = std::accumulate(u.begin(), u.end(),
double(0)) / u.size();
double var = 0;
double skew = 0;
double kurtosis = 0;
for (int i = 0; i < u.size(); ++i)
{
double d = (u[i] - mean);
double d2 = sqr(d);
var += d2;
skew += d * d2;
kurtosis += d2 * d2;
}
var /= u.size();
double dev = std::sqrt(var);
skew /= u.size() * dev * var;
kurtosis /= u.size() * var * var;
kurtosis -= 3;
double x_mean = d.p();
double x_var = d.p()*(1-d.p());
double x_skew = (1 - 2 * d.p())/std::sqrt(x_var);
double x_kurtosis = (6 * sqr(d.p()) - 6 * d.p() + 1)/x_var;
assert(std::abs((mean - x_mean) / x_mean) < 0.01);
assert(std::abs((var - x_var) / x_var) < 0.01);
assert(std::abs((skew - x_skew) / x_skew) < 0.01);
assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.02);
}
{
typedef std::bernoulli_distribution D;
typedef std::minstd_rand G;
G g;
D d(.25);
const int N = 100000;
std::vector<D::result_type> u;
for (int i = 0; i < N; ++i)
u.push_back(d(g));
double mean = std::accumulate(u.begin(), u.end(),
double(0)) / u.size();
double var = 0;
double skew = 0;
double kurtosis = 0;
for (int i = 0; i < u.size(); ++i)
{
double d = (u[i] - mean);
double d2 = sqr(d);
var += d2;
skew += d * d2;
kurtosis += d2 * d2;
}
var /= u.size();
double dev = std::sqrt(var);
skew /= u.size() * dev * var;
kurtosis /= u.size() * var * var;
kurtosis -= 3;
double x_mean = d.p();
double x_var = d.p()*(1-d.p());
double x_skew = (1 - 2 * d.p())/std::sqrt(x_var);
double x_kurtosis = (6 * sqr(d.p()) - 6 * d.p() + 1)/x_var;
assert(std::abs((mean - x_mean) / x_mean) < 0.01);
assert(std::abs((var - x_var) / x_var) < 0.01);
assert(std::abs((skew - x_skew) / x_skew) < 0.01);
assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.02);
}
}

View File

@@ -0,0 +1,107 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <random>
// class bernoulli_distribution
// template<class _URNG> result_type operator()(_URNG& g, const param_type& parm);
#include <random>
#include <numeric>
#include <vector>
#include <cassert>
template <class T>
inline
T
sqr(T x)
{
return x * x;
}
int main()
{
{
typedef std::bernoulli_distribution D;
typedef D::param_type P;
typedef std::minstd_rand G;
G g;
D d(.75);
P p(.25);
const int N = 100000;
std::vector<D::result_type> u;
for (int i = 0; i < N; ++i)
u.push_back(d(g, p));
double mean = std::accumulate(u.begin(), u.end(),
double(0)) / u.size();
double var = 0;
double skew = 0;
double kurtosis = 0;
for (int i = 0; i < u.size(); ++i)
{
double d = (u[i] - mean);
double d2 = sqr(d);
var += d2;
skew += d * d2;
kurtosis += d2 * d2;
}
var /= u.size();
double dev = std::sqrt(var);
skew /= u.size() * dev * var;
kurtosis /= u.size() * var * var;
kurtosis -= 3;
double x_mean = p.p();
double x_var = p.p()*(1-p.p());
double x_skew = (1 - 2 * p.p())/std::sqrt(x_var);
double x_kurtosis = (6 * sqr(p.p()) - 6 * p.p() + 1)/x_var;
assert(std::abs((mean - x_mean) / x_mean) < 0.01);
assert(std::abs((var - x_var) / x_var) < 0.01);
assert(std::abs((skew - x_skew) / x_skew) < 0.01);
assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.02);
}
{
typedef std::bernoulli_distribution D;
typedef D::param_type P;
typedef std::minstd_rand G;
G g;
D d(.25);
P p(.75);
const int N = 100000;
std::vector<D::result_type> u;
for (int i = 0; i < N; ++i)
u.push_back(d(g, p));
double mean = std::accumulate(u.begin(), u.end(),
double(0)) / u.size();
double var = 0;
double skew = 0;
double kurtosis = 0;
for (int i = 0; i < u.size(); ++i)
{
double d = (u[i] - mean);
double d2 = sqr(d);
var += d2;
skew += d * d2;
kurtosis += d2 * d2;
}
var /= u.size();
double dev = std::sqrt(var);
skew /= u.size() * dev * var;
kurtosis /= u.size() * var * var;
kurtosis -= 3;
double x_mean = p.p();
double x_var = p.p()*(1-p.p());
double x_skew = (1 - 2 * p.p())/std::sqrt(x_var);
double x_kurtosis = (6 * sqr(p.p()) - 6 * p.p() + 1)/x_var;
assert(std::abs((mean - x_mean) / x_mean) < 0.01);
assert(std::abs((var - x_var) / x_var) < 0.01);
assert(std::abs((skew - x_skew) / x_skew) < 0.01);
assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.02);
}
}

View File

@@ -0,0 +1,28 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <random>
// class bernoulli_distribution
// param_type param() const;
#include <random>
#include <cassert>
int main()
{
{
typedef std::bernoulli_distribution D;
typedef D::param_type P;
P p(.125);
D d(p);
assert(d.param() == p);
}
}

View File

@@ -0,0 +1,40 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <random>
// class bernoulli_distribution
// template <class charT, class traits>
// basic_ostream<charT, traits>&
// operator<<(basic_ostream<charT, traits>& os,
// const bernoulli_distribution& x);
//
// template <class charT, class traits>
// basic_istream<charT, traits>&
// operator>>(basic_istream<charT, traits>& is,
// bernoulli_distribution& x);
#include <random>
#include <sstream>
#include <cassert>
int main()
{
{
typedef std::bernoulli_distribution D;
D d1(.25);
std::ostringstream os;
os << d1;
std::istringstream is(os.str());
D d2;
is >> d2;
assert(d1 == d2);
}
}

View File

@@ -0,0 +1,26 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <random>
// class bernoulli_distribution
// result_type max() const;
#include <random>
#include <cassert>
int main()
{
{
typedef std::bernoulli_distribution D;
D d(.25);
assert(d.max() == true);
}
}

View File

@@ -0,0 +1,26 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <random>
// class bernoulli_distribution
// result_type min() const;
#include <random>
#include <cassert>
int main()
{
{
typedef std::bernoulli_distribution D;
D d(.5);
assert(d.min() == false);
}
}

View File

@@ -0,0 +1,30 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <random>
// class bernoulli_distribution
// {
// class param_type;
#include <random>
#include <limits>
#include <cassert>
int main()
{
{
typedef std::bernoulli_distribution D;
typedef D::param_type param_type;
param_type p0(.7);
param_type p;
p = p0;
assert(p.p() == .7);
}
}

View File

@@ -0,0 +1,29 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <random>
// class bernoulli_distribution
// {
// class param_type;
#include <random>
#include <limits>
#include <cassert>
int main()
{
{
typedef std::bernoulli_distribution D;
typedef D::param_type param_type;
param_type p0(.125);
param_type p = p0;
assert(p.p() == .125);
}
}

View File

@@ -0,0 +1,34 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <random>
// class bernoulli_distribution
// {
// class param_type;
#include <random>
#include <limits>
#include <cassert>
int main()
{
{
typedef std::bernoulli_distribution D;
typedef D::param_type param_type;
param_type p;
assert(p.p() == 0.5);
}
{
typedef std::bernoulli_distribution D;
typedef D::param_type param_type;
param_type p(0.25);
assert(p.p() == 0.25);
}
}

View File

@@ -0,0 +1,36 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <random>
// class bernoulli_distribution
// {
// class param_type;
#include <random>
#include <limits>
#include <cassert>
int main()
{
{
typedef std::bernoulli_distribution D;
typedef D::param_type param_type;
param_type p1(0.75);
param_type p2(0.75);
assert(p1 == p2);
}
{
typedef std::bernoulli_distribution D;
typedef D::param_type param_type;
param_type p1(0.75);
param_type p2(0.5);
assert(p1 != p2);
}
}

View File

@@ -0,0 +1,27 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <random>
// class bernoulli_distribution
// {
// class param_type;
#include <random>
#include <type_traits>
int main()
{
{
typedef std::bernoulli_distribution D;
typedef D::param_type param_type;
typedef param_type::distribution_type distribution_type;
static_assert((std::is_same<D, distribution_type>::value), "");
}
}

View File

@@ -0,0 +1,29 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <random>
// class bernoulli_distribution
// void param(const param_type& parm);
#include <random>
#include <cassert>
int main()
{
{
typedef std::bernoulli_distribution D;
typedef D::param_type P;
P p(0.25);
D d(0.75);
d.param(p);
assert(d.param() == p);
}
}

View File

@@ -0,0 +1,26 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <random>
// class bernoulli_distribution
// {
// typedef bool result_type;
#include <random>
#include <type_traits>
int main()
{
{
typedef std::bernoulli_distribution D;
typedef D::result_type result_type;
static_assert((std::is_same<result_type, bool>::value), "");
}
}

View File

@@ -0,0 +1,34 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <random>
// template<class IntType = int>
// class binomial_distribution
// binomial_distribution& operator=(const binomial_distribution&);
#include <random>
#include <cassert>
void
test1()
{
typedef std::binomial_distribution<> D;
D d1(2, 0.75);
D d2;
assert(d1 != d2);
d2 = d1;
assert(d1 == d2);
}
int main()
{
test1();
}

View File

@@ -0,0 +1,32 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <random>
// template<class IntType = int>
// class binomial_distribution
// binomial_distribution(const binomial_distribution&);
#include <random>
#include <cassert>
void
test1()
{
typedef std::binomial_distribution<> D;
D d1(2, 0.75);
D d2 = d1;
assert(d1 == d2);
}
int main()
{
test1();
}

View File

@@ -0,0 +1,40 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <random>
// template<class IntType = int>
// class binomial_distribution
// explicit binomial_distribution(IntType t = 1, double p = 0.5);
#include <random>
#include <cassert>
int main()
{
{
typedef std::binomial_distribution<> D;
D d;
assert(d.t() == 1);
assert(d.p() == 0.5);
}
{
typedef std::binomial_distribution<> D;
D d(3);
assert(d.t() == 3);
assert(d.p() == 0.5);
}
{
typedef std::binomial_distribution<> D;
D d(3, 0.75);
assert(d.t() == 3);
assert(d.p() == 0.75);
}
}

View File

@@ -0,0 +1,30 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <random>
// template<class IntType = int>
// class binomial_distribution
// explicit binomial_distribution(const param_type& parm);
#include <random>
#include <cassert>
int main()
{
{
typedef std::binomial_distribution<> D;
typedef D::param_type P;
P p(5, 0.25);
D d(p);
assert(d.t() == 5);
assert(d.p() == 0.25);
}
}

View File

@@ -0,0 +1,43 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <random>
// template<class IntType = int>
// class binomial_distribution
// bool operator=(const binomial_distribution& x,
// const binomial_distribution& y);
// bool operator!(const binomial_distribution& x,
// const binomial_distribution& y);
#include <random>
#include <cassert>
int main()
{
{
typedef std::binomial_distribution<> D;
D d1(3, .25);
D d2(3, .25);
assert(d1 == d2);
}
{
typedef std::binomial_distribution<> D;
D d1(3, .28);
D d2(3, .25);
assert(d1 != d2);
}
{
typedef std::binomial_distribution<> D;
D d1(3, .25);
D d2(4, .25);
assert(d1 != d2);
}
}

View File

@@ -0,0 +1,475 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// REQUIRES: long_tests
// <random>
// template<class IntType = int>
// class binomial_distribution
// template<class _URNG> result_type operator()(_URNG& g);
#include <random>
#include <numeric>
#include <vector>
#include <cassert>
template <class T>
inline
T
sqr(T x)
{
return x * x;
}
int main()
{
{
typedef std::binomial_distribution<> D;
typedef std::mt19937_64 G;
G g;
D d(5, .75);
const int N = 1000000;
std::vector<D::result_type> u;
for (int i = 0; i < N; ++i)
{
D::result_type v = d(g);
assert(d.min() <= v && v <= d.max());
u.push_back(v);
}
double mean = std::accumulate(u.begin(), u.end(),
double(0)) / u.size();
double var = 0;
double skew = 0;
double kurtosis = 0;
for (int i = 0; i < u.size(); ++i)
{
double d = (u[i] - mean);
double d2 = sqr(d);
var += d2;
skew += d * d2;
kurtosis += d2 * d2;
}
var /= u.size();
double dev = std::sqrt(var);
skew /= u.size() * dev * var;
kurtosis /= u.size() * var * var;
kurtosis -= 3;
double x_mean = d.t() * d.p();
double x_var = x_mean*(1-d.p());
double x_skew = (1-2*d.p()) / std::sqrt(x_var);
double x_kurtosis = (1-6*d.p()*(1-d.p())) / x_var;
assert(std::abs((mean - x_mean) / x_mean) < 0.01);
assert(std::abs((var - x_var) / x_var) < 0.01);
assert(std::abs((skew - x_skew) / x_skew) < 0.01);
assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.04);
}
{
typedef std::binomial_distribution<> D;
typedef std::mt19937 G;
G g;
D d(30, .03125);
const int N = 100000;
std::vector<D::result_type> u;
for (int i = 0; i < N; ++i)
{
D::result_type v = d(g);
assert(d.min() <= v && v <= d.max());
u.push_back(v);
}
double mean = std::accumulate(u.begin(), u.end(),
double(0)) / u.size();
double var = 0;
double skew = 0;
double kurtosis = 0;
for (int i = 0; i < u.size(); ++i)
{
double d = (u[i] - mean);
double d2 = sqr(d);
var += d2;
skew += d * d2;
kurtosis += d2 * d2;
}
var /= u.size();
double dev = std::sqrt(var);
skew /= u.size() * dev * var;
kurtosis /= u.size() * var * var;
kurtosis -= 3;
double x_mean = d.t() * d.p();
double x_var = x_mean*(1-d.p());
double x_skew = (1-2*d.p()) / std::sqrt(x_var);
double x_kurtosis = (1-6*d.p()*(1-d.p())) / x_var;
assert(std::abs((mean - x_mean) / x_mean) < 0.01);
assert(std::abs((var - x_var) / x_var) < 0.01);
assert(std::abs((skew - x_skew) / x_skew) < 0.01);
assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.01);
}
{
typedef std::binomial_distribution<> D;
typedef std::mt19937 G;
G g;
D d(40, .25);
const int N = 100000;
std::vector<D::result_type> u;
for (int i = 0; i < N; ++i)
{
D::result_type v = d(g);
assert(d.min() <= v && v <= d.max());
u.push_back(v);
}
double mean = std::accumulate(u.begin(), u.end(),
double(0)) / u.size();
double var = 0;
double skew = 0;
double kurtosis = 0;
for (int i = 0; i < u.size(); ++i)
{
double d = (u[i] - mean);
double d2 = sqr(d);
var += d2;
skew += d * d2;
kurtosis += d2 * d2;
}
var /= u.size();
double dev = std::sqrt(var);
skew /= u.size() * dev * var;
kurtosis /= u.size() * var * var;
kurtosis -= 3;
double x_mean = d.t() * d.p();
double x_var = x_mean*(1-d.p());
double x_skew = (1-2*d.p()) / std::sqrt(x_var);
double x_kurtosis = (1-6*d.p()*(1-d.p())) / x_var;
assert(std::abs((mean - x_mean) / x_mean) < 0.01);
assert(std::abs((var - x_var) / x_var) < 0.01);
assert(std::abs((skew - x_skew) / x_skew) < 0.03);
assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.3);
}
{
typedef std::binomial_distribution<> D;
typedef std::mt19937 G;
G g;
D d(40, 0);
const int N = 100000;
std::vector<D::result_type> u;
for (int i = 0; i < N; ++i)
{
D::result_type v = d(g);
assert(d.min() <= v && v <= d.max());
u.push_back(v);
}
double mean = std::accumulate(u.begin(), u.end(),
double(0)) / u.size();
double var = 0;
double skew = 0;
double kurtosis = 0;
for (int i = 0; i < u.size(); ++i)
{
double d = (u[i] - mean);
double d2 = sqr(d);
var += d2;
skew += d * d2;
kurtosis += d2 * d2;
}
var /= u.size();
double dev = std::sqrt(var);
// In this case:
// skew computes to 0./0. == nan
// kurtosis computes to 0./0. == nan
// x_skew == inf
// x_kurtosis == inf
// These tests are commented out because UBSan warns about division by 0
// skew /= u.size() * dev * var;
// kurtosis /= u.size() * var * var;
// kurtosis -= 3;
double x_mean = d.t() * d.p();
double x_var = x_mean*(1-d.p());
// double x_skew = (1-2*d.p()) / std::sqrt(x_var);
// double x_kurtosis = (1-6*d.p()*(1-d.p())) / x_var;
assert(mean == x_mean);
assert(var == x_var);
// assert(skew == x_skew);
// assert(kurtosis == x_kurtosis);
}
{
typedef std::binomial_distribution<> D;
typedef std::mt19937 G;
G g;
D d(40, 1);
const int N = 100000;
std::vector<D::result_type> u;
for (int i = 0; i < N; ++i)
{
D::result_type v = d(g);
assert(d.min() <= v && v <= d.max());
u.push_back(v);
}
double mean = std::accumulate(u.begin(), u.end(),
double(0)) / u.size();
double var = 0;
double skew = 0;
double kurtosis = 0;
for (int i = 0; i < u.size(); ++i)
{
double d = (u[i] - mean);
double d2 = sqr(d);
var += d2;
skew += d * d2;
kurtosis += d2 * d2;
}
var /= u.size();
double dev = std::sqrt(var);
// In this case:
// skew computes to 0./0. == nan
// kurtosis computes to 0./0. == nan
// x_skew == -inf
// x_kurtosis == inf
// These tests are commented out because UBSan warns about division by 0
// skew /= u.size() * dev * var;
// kurtosis /= u.size() * var * var;
// kurtosis -= 3;
double x_mean = d.t() * d.p();
double x_var = x_mean*(1-d.p());
// double x_skew = (1-2*d.p()) / std::sqrt(x_var);
// double x_kurtosis = (1-6*d.p()*(1-d.p())) / x_var;
assert(mean == x_mean);
assert(var == x_var);
// assert(skew == x_skew);
// assert(kurtosis == x_kurtosis);
}
{
typedef std::binomial_distribution<> D;
typedef std::mt19937 G;
G g;
D d(400, 0.5);
const int N = 100000;
std::vector<D::result_type> u;
for (int i = 0; i < N; ++i)
{
D::result_type v = d(g);
assert(d.min() <= v && v <= d.max());
u.push_back(v);
}
double mean = std::accumulate(u.begin(), u.end(),
double(0)) / u.size();
double var = 0;
double skew = 0;
double kurtosis = 0;
for (int i = 0; i < u.size(); ++i)
{
double d = (u[i] - mean);
double d2 = sqr(d);
var += d2;
skew += d * d2;
kurtosis += d2 * d2;
}
var /= u.size();
double dev = std::sqrt(var);
skew /= u.size() * dev * var;
kurtosis /= u.size() * var * var;
kurtosis -= 3;
double x_mean = d.t() * d.p();
double x_var = x_mean*(1-d.p());
double x_skew = (1-2*d.p()) / std::sqrt(x_var);
double x_kurtosis = (1-6*d.p()*(1-d.p())) / x_var;
assert(std::abs((mean - x_mean) / x_mean) < 0.01);
assert(std::abs((var - x_var) / x_var) < 0.01);
assert(std::abs(skew - x_skew) < 0.01);
assert(std::abs(kurtosis - x_kurtosis) < 0.01);
}
{
typedef std::binomial_distribution<> D;
typedef std::mt19937 G;
G g;
D d(1, 0.5);
const int N = 100000;
std::vector<D::result_type> u;
for (int i = 0; i < N; ++i)
{
D::result_type v = d(g);
assert(d.min() <= v && v <= d.max());
u.push_back(v);
}
double mean = std::accumulate(u.begin(), u.end(),
double(0)) / u.size();
double var = 0;
double skew = 0;
double kurtosis = 0;
for (int i = 0; i < u.size(); ++i)
{
double d = (u[i] - mean);
double d2 = sqr(d);
var += d2;
skew += d * d2;
kurtosis += d2 * d2;
}
var /= u.size();
double dev = std::sqrt(var);
skew /= u.size() * dev * var;
kurtosis /= u.size() * var * var;
kurtosis -= 3;
double x_mean = d.t() * d.p();
double x_var = x_mean*(1-d.p());
double x_skew = (1-2*d.p()) / std::sqrt(x_var);
double x_kurtosis = (1-6*d.p()*(1-d.p())) / x_var;
assert(std::abs((mean - x_mean) / x_mean) < 0.01);
assert(std::abs((var - x_var) / x_var) < 0.01);
assert(std::abs(skew - x_skew) < 0.01);
assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.01);
}
{
const int N = 100000;
std::mt19937 gen1;
std::mt19937 gen2;
std::binomial_distribution<> dist1(5, 0.1);
std::binomial_distribution<unsigned> dist2(5, 0.1);
for(int i = 0; i < N; ++i)
assert(dist1(gen1) == dist2(gen2));
}
{
typedef std::binomial_distribution<> D;
typedef std::mt19937 G;
G g;
D d(0, 0.005);
const int N = 100000;
std::vector<D::result_type> u;
for (int i = 0; i < N; ++i)
{
D::result_type v = d(g);
assert(d.min() <= v && v <= d.max());
u.push_back(v);
}
double mean = std::accumulate(u.begin(), u.end(),
double(0)) / u.size();
double var = 0;
double skew = 0;
double kurtosis = 0;
for (int i = 0; i < u.size(); ++i)
{
double d = (u[i] - mean);
double d2 = sqr(d);
var += d2;
skew += d * d2;
kurtosis += d2 * d2;
}
var /= u.size();
double dev = std::sqrt(var);
// In this case:
// skew computes to 0./0. == nan
// kurtosis computes to 0./0. == nan
// x_skew == inf
// x_kurtosis == inf
// These tests are commented out because UBSan warns about division by 0
// skew /= u.size() * dev * var;
// kurtosis /= u.size() * var * var;
// kurtosis -= 3;
double x_mean = d.t() * d.p();
double x_var = x_mean*(1-d.p());
// double x_skew = (1-2*d.p()) / std::sqrt(x_var);
// double x_kurtosis = (1-6*d.p()*(1-d.p())) / x_var;
assert(mean == x_mean);
assert(var == x_var);
// assert(skew == x_skew);
// assert(kurtosis == x_kurtosis);
}
{
typedef std::binomial_distribution<> D;
typedef std::mt19937 G;
G g;
D d(0, 0);
const int N = 100000;
std::vector<D::result_type> u;
for (int i = 0; i < N; ++i)
{
D::result_type v = d(g);
assert(d.min() <= v && v <= d.max());
u.push_back(v);
}
double mean = std::accumulate(u.begin(), u.end(),
double(0)) / u.size();
double var = 0;
double skew = 0;
double kurtosis = 0;
for (int i = 0; i < u.size(); ++i)
{
double d = (u[i] - mean);
double d2 = sqr(d);
var += d2;
skew += d * d2;
kurtosis += d2 * d2;
}
var /= u.size();
double dev = std::sqrt(var);
// In this case:
// skew computes to 0./0. == nan
// kurtosis computes to 0./0. == nan
// x_skew == inf
// x_kurtosis == inf
// These tests are commented out because UBSan warns about division by 0
// skew /= u.size() * dev * var;
// kurtosis /= u.size() * var * var;
// kurtosis -= 3;
double x_mean = d.t() * d.p();
double x_var = x_mean*(1-d.p());
// double x_skew = (1-2*d.p()) / std::sqrt(x_var);
// double x_kurtosis = (1-6*d.p()*(1-d.p())) / x_var;
assert(mean == x_mean);
assert(var == x_var);
// assert(skew == x_skew);
// assert(kurtosis == x_kurtosis);
}
{
typedef std::binomial_distribution<> D;
typedef std::mt19937 G;
G g;
D d(0, 1);
const int N = 100000;
std::vector<D::result_type> u;
for (int i = 0; i < N; ++i)
{
D::result_type v = d(g);
assert(d.min() <= v && v <= d.max());
u.push_back(v);
}
double mean = std::accumulate(u.begin(), u.end(),
double(0)) / u.size();
double var = 0;
double skew = 0;
double kurtosis = 0;
for (int i = 0; i < u.size(); ++i)
{
double d = (u[i] - mean);
double d2 = sqr(d);
var += d2;
skew += d * d2;
kurtosis += d2 * d2;
}
var /= u.size();
double dev = std::sqrt(var);
// In this case:
// skew computes to 0./0. == nan
// kurtosis computes to 0./0. == nan
// x_skew == -inf
// x_kurtosis == inf
// These tests are commented out because UBSan warns about division by 0
// skew /= u.size() * dev * var;
// kurtosis /= u.size() * var * var;
// kurtosis -= 3;
double x_mean = d.t() * d.p();
double x_var = x_mean*(1-d.p());
// double x_skew = (1-2*d.p()) / std::sqrt(x_var);
// double x_kurtosis = (1-6*d.p()*(1-d.p())) / x_var;
assert(mean == x_mean);
assert(var == x_var);
// assert(skew == x_skew);
// assert(kurtosis == x_kurtosis);
}
}

View File

@@ -0,0 +1,160 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// REQUIRES: long_tests
// <random>
// template<class IntType = int>
// class binomial_distribution
// template<class _URNG> result_type operator()(_URNG& g, const param_type& parm);
#include <random>
#include <numeric>
#include <vector>
#include <cassert>
template <class T>
inline
T
sqr(T x)
{
return x * x;
}
int main()
{
{
typedef std::binomial_distribution<> D;
typedef D::param_type P;
typedef std::mt19937_64 G;
G g;
D d(16, .75);
P p(5, .75);
const int N = 1000000;
std::vector<D::result_type> u;
for (int i = 0; i < N; ++i)
{
D::result_type v = d(g, p);
assert(0 <= v && v <= p.t());
u.push_back(v);
}
double mean = std::accumulate(u.begin(), u.end(),
double(0)) / u.size();
double var = 0;
double skew = 0;
double kurtosis = 0;
for (int i = 0; i < u.size(); ++i)
{
double d = (u[i] - mean);
double d2 = sqr(d);
var += d2;
skew += d * d2;
kurtosis += d2 * d2;
}
var /= u.size();
double dev = std::sqrt(var);
skew /= u.size() * dev * var;
kurtosis /= u.size() * var * var;
kurtosis -= 3;
double x_mean = p.t() * p.p();
double x_var = x_mean*(1-p.p());
double x_skew = (1-2*p.p()) / std::sqrt(x_var);
double x_kurtosis = (1-6*p.p()*(1-p.p())) / x_var;
assert(std::abs((mean - x_mean) / x_mean) < 0.01);
assert(std::abs((var - x_var) / x_var) < 0.01);
assert(std::abs((skew - x_skew) / x_skew) < 0.01);
assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.04);
}
{
typedef std::binomial_distribution<> D;
typedef D::param_type P;
typedef std::mt19937 G;
G g;
D d(16, .75);
P p(30, .03125);
const int N = 100000;
std::vector<D::result_type> u;
for (int i = 0; i < N; ++i)
{
D::result_type v = d(g, p);
assert(0 <= v && v <= p.t());
u.push_back(v);
}
double mean = std::accumulate(u.begin(), u.end(),
double(0)) / u.size();
double var = 0;
double skew = 0;
double kurtosis = 0;
for (int i = 0; i < u.size(); ++i)
{
double d = (u[i] - mean);
double d2 = sqr(d);
var += d2;
skew += d * d2;
kurtosis += d2 * d2;
}
var /= u.size();
double dev = std::sqrt(var);
skew /= u.size() * dev * var;
kurtosis /= u.size() * var * var;
kurtosis -= 3;
double x_mean = p.t() * p.p();
double x_var = x_mean*(1-p.p());
double x_skew = (1-2*p.p()) / std::sqrt(x_var);
double x_kurtosis = (1-6*p.p()*(1-p.p())) / x_var;
assert(std::abs((mean - x_mean) / x_mean) < 0.01);
assert(std::abs((var - x_var) / x_var) < 0.01);
assert(std::abs((skew - x_skew) / x_skew) < 0.01);
assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.01);
}
{
typedef std::binomial_distribution<> D;
typedef D::param_type P;
typedef std::mt19937 G;
G g;
D d(16, .75);
P p(40, .25);
const int N = 1000000;
std::vector<D::result_type> u;
for (int i = 0; i < N; ++i)
{
D::result_type v = d(g, p);
assert(0 <= v && v <= p.t());
u.push_back(v);
}
double mean = std::accumulate(u.begin(), u.end(),
double(0)) / u.size();
double var = 0;
double skew = 0;
double kurtosis = 0;
for (int i = 0; i < u.size(); ++i)
{
double d = (u[i] - mean);
double d2 = sqr(d);
var += d2;
skew += d * d2;
kurtosis += d2 * d2;
}
var /= u.size();
double dev = std::sqrt(var);
skew /= u.size() * dev * var;
kurtosis /= u.size() * var * var;
kurtosis -= 3;
double x_mean = p.t() * p.p();
double x_var = x_mean*(1-p.p());
double x_skew = (1-2*p.p()) / std::sqrt(x_var);
double x_kurtosis = (1-6*p.p()*(1-p.p())) / x_var;
assert(std::abs((mean - x_mean) / x_mean) < 0.01);
assert(std::abs((var - x_var) / x_var) < 0.01);
assert(std::abs((skew - x_skew) / x_skew) < 0.04);
assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.3);
}
}

View File

@@ -0,0 +1,29 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <random>
// template<class IntType = int>
// class binomial_distribution
// param_type param() const;
#include <random>
#include <cassert>
int main()
{
{
typedef std::binomial_distribution<> D;
typedef D::param_type P;
P p(5, .125);
D d(p);
assert(d.param() == p);
}
}

View File

@@ -0,0 +1,41 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <random>
// template<class IntType = int>
// class binomial_distribution
// template <class charT, class traits>
// basic_ostream<charT, traits>&
// operator<<(basic_ostream<charT, traits>& os,
// const binomial_distribution& x);
//
// template <class charT, class traits>
// basic_istream<charT, traits>&
// operator>>(basic_istream<charT, traits>& is,
// binomial_distribution& x);
#include <random>
#include <sstream>
#include <cassert>
int main()
{
{
typedef std::binomial_distribution<> D;
D d1(7, .25);
std::ostringstream os;
os << d1;
std::istringstream is(os.str());
D d2;
is >> d2;
assert(d1 == d2);
}
}

View File

@@ -0,0 +1,27 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <random>
// template<class IntType = int>
// class binomial_distribution
// result_type max() const;
#include <random>
#include <cassert>
int main()
{
{
typedef std::binomial_distribution<> D;
D d(4, .25);
assert(d.max() == 4);
}
}

View File

@@ -0,0 +1,27 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <random>
// template<class IntType = int>
// class binomial_distribution
// result_type min() const;
#include <random>
#include <cassert>
int main()
{
{
typedef std::binomial_distribution<> D;
D d(4, .5);
assert(d.min() == 0);
}
}

View File

@@ -0,0 +1,32 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <random>
// template<class IntType = int>
// class binomial_distribution
// {
// class param_type;
#include <random>
#include <limits>
#include <cassert>
int main()
{
{
typedef std::binomial_distribution<> D;
typedef D::param_type param_type;
param_type p0(6, .7);
param_type p;
p = p0;
assert(p.t() == 6);
assert(p.p() == .7);
}
}

View File

@@ -0,0 +1,31 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <random>
// template<class IntType = int>
// class binomial_distribution
// {
// class param_type;
#include <random>
#include <limits>
#include <cassert>
int main()
{
{
typedef std::binomial_distribution<> D;
typedef D::param_type param_type;
param_type p0(10, .125);
param_type p = p0;
assert(p.t() == 10);
assert(p.p() == .125);
}
}

View File

@@ -0,0 +1,44 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <random>
// template<class IntType = int>
// class binomial_distribution
// {
// class param_type;
#include <random>
#include <limits>
#include <cassert>
int main()
{
{
typedef std::binomial_distribution<> D;
typedef D::param_type param_type;
param_type p;
assert(p.t() == 1);
assert(p.p() == 0.5);
}
{
typedef std::binomial_distribution<> D;
typedef D::param_type param_type;
param_type p(10);
assert(p.t() == 10);
assert(p.p() == 0.5);
}
{
typedef std::binomial_distribution<> D;
typedef D::param_type param_type;
param_type p(10, 0.25);
assert(p.t() == 10);
assert(p.p() == 0.25);
}
}

View File

@@ -0,0 +1,37 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <random>
// template<class IntType = int>
// class binomial_distribution
// {
// class param_type;
#include <random>
#include <limits>
#include <cassert>
int main()
{
{
typedef std::binomial_distribution<> D;
typedef D::param_type param_type;
param_type p1(3, 0.75);
param_type p2(3, 0.75);
assert(p1 == p2);
}
{
typedef std::binomial_distribution<> D;
typedef D::param_type param_type;
param_type p1(3, 0.75);
param_type p2(3, 0.5);
assert(p1 != p2);
}
}

View File

@@ -0,0 +1,28 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <random>
// template<class IntType = int>
// class binomial_distribution
// {
// class param_type;
#include <random>
#include <type_traits>
int main()
{
{
typedef std::binomial_distribution<> D;
typedef D::param_type param_type;
typedef param_type::distribution_type distribution_type;
static_assert((std::is_same<D, distribution_type>::value), "");
}
}

View File

@@ -0,0 +1,30 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <random>
// template<class IntType = int>
// class binomial_distribution
// void param(const param_type& parm);
#include <random>
#include <cassert>
int main()
{
{
typedef std::binomial_distribution<> D;
typedef D::param_type P;
P p(10, 0.25);
D d(8, 0.75);
d.param(p);
assert(d.param() == p);
}
}

View File

@@ -0,0 +1,32 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <random>
// template<class IntType = int>
// class binomial_distribution
// {
// typedef bool result_type;
#include <random>
#include <type_traits>
int main()
{
{
typedef std::binomial_distribution<> D;
typedef D::result_type result_type;
static_assert((std::is_same<result_type, int>::value), "");
}
{
typedef std::binomial_distribution<long> D;
typedef D::result_type result_type;
static_assert((std::is_same<result_type, long>::value), "");
}
}

View File

@@ -0,0 +1,34 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <random>
// template<class IntType = int>
// class geometric_distribution
// geometric_distribution& operator=(const geometric_distribution&);
#include <random>
#include <cassert>
void
test1()
{
typedef std::geometric_distribution<> D;
D d1(0.75);
D d2;
assert(d1 != d2);
d2 = d1;
assert(d1 == d2);
}
int main()
{
test1();
}

View File

@@ -0,0 +1,32 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <random>
// template<class IntType = int>
// class geometric_distribution
// geometric_distribution(const geometric_distribution&);
#include <random>
#include <cassert>
void
test1()
{
typedef std::geometric_distribution<> D;
D d1(0.75);
D d2 = d1;
assert(d1 == d2);
}
int main()
{
test1();
}

View File

@@ -0,0 +1,32 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <random>
// template<class IntType = int>
// class geometric_distribution
// explicit geometric_distribution(double p = 0.5);
#include <random>
#include <cassert>
int main()
{
{
typedef std::geometric_distribution<> D;
D d;
assert(d.p() == 0.5);
}
{
typedef std::geometric_distribution<> D;
D d(0.75);
assert(d.p() == 0.75);
}
}

View File

@@ -0,0 +1,29 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <random>
// template<class IntType = int>
// class geometric_distribution
// explicit geometric_distribution(const param_type& parm);
#include <random>
#include <cassert>
int main()
{
{
typedef std::geometric_distribution<> D;
typedef D::param_type P;
P p(0.25);
D d(p);
assert(d.p() == 0.25);
}
}

View File

@@ -0,0 +1,37 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <random>
// template<class IntType = int>
// class geometric_distribution
// bool operator=(const geometric_distribution& x,
// const geometric_distribution& y);
// bool operator!(const geometric_distribution& x,
// const geometric_distribution& y);
#include <random>
#include <cassert>
int main()
{
{
typedef std::geometric_distribution<> D;
D d1(.25);
D d2(.25);
assert(d1 == d2);
}
{
typedef std::geometric_distribution<> D;
D d1(.28);
D d2(.25);
assert(d1 != d2);
}
}

View File

@@ -0,0 +1,274 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// REQUIRES: long_tests
// <random>
// template<class IntType = int>
// class geometric_distribution
// template<class _URNG> result_type operator()(_URNG& g);
#include <random>
#include <numeric>
#include <vector>
#include <cassert>
template <class T>
inline
T
sqr(T x)
{
return x * x;
}
int main()
{
{
typedef std::geometric_distribution<> D;
typedef std::mt19937 G;
G g;
D d(.03125);
const int N = 1000000;
std::vector<D::result_type> u;
for (int i = 0; i < N; ++i)
{
D::result_type v = d(g);
assert(d.min() <= v && v <= d.max());
u.push_back(v);
}
double mean = std::accumulate(u.begin(), u.end(),
double(0)) / u.size();
double var = 0;
double skew = 0;
double kurtosis = 0;
for (int i = 0; i < u.size(); ++i)
{
double d = (u[i] - mean);
double d2 = sqr(d);
var += d2;
skew += d * d2;
kurtosis += d2 * d2;
}
var /= u.size();
double dev = std::sqrt(var);
skew /= u.size() * dev * var;
kurtosis /= u.size() * var * var;
kurtosis -= 3;
double x_mean = (1 - d.p()) / d.p();
double x_var = x_mean / d.p();
double x_skew = (2 - d.p()) / std::sqrt((1 - d.p()));
double x_kurtosis = 6 + sqr(d.p()) / (1 - d.p());
assert(std::abs((mean - x_mean) / x_mean) < 0.01);
assert(std::abs((var - x_var) / x_var) < 0.01);
assert(std::abs((skew - x_skew) / x_skew) < 0.01);
assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.01);
}
{
typedef std::geometric_distribution<> D;
typedef std::mt19937 G;
G g;
D d(0.05);
const int N = 1000000;
std::vector<D::result_type> u;
for (int i = 0; i < N; ++i)
{
D::result_type v = d(g);
assert(d.min() <= v && v <= d.max());
u.push_back(v);
}
double mean = std::accumulate(u.begin(), u.end(),
double(0)) / u.size();
double var = 0;
double skew = 0;
double kurtosis = 0;
for (int i = 0; i < u.size(); ++i)
{
double d = (u[i] - mean);
double d2 = sqr(d);
var += d2;
skew += d * d2;
kurtosis += d2 * d2;
}
var /= u.size();
double dev = std::sqrt(var);
skew /= u.size() * dev * var;
kurtosis /= u.size() * var * var;
kurtosis -= 3;
double x_mean = (1 - d.p()) / d.p();
double x_var = x_mean / d.p();
double x_skew = (2 - d.p()) / std::sqrt((1 - d.p()));
double x_kurtosis = 6 + sqr(d.p()) / (1 - d.p());
assert(std::abs((mean - x_mean) / x_mean) < 0.01);
assert(std::abs((var - x_var) / x_var) < 0.01);
assert(std::abs((skew - x_skew) / x_skew) < 0.01);
assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.03);
}
{
typedef std::geometric_distribution<> D;
typedef std::minstd_rand G;
G g;
D d(.25);
const int N = 1000000;
std::vector<D::result_type> u;
for (int i = 0; i < N; ++i)
{
D::result_type v = d(g);
assert(d.min() <= v && v <= d.max());
u.push_back(v);
}
double mean = std::accumulate(u.begin(), u.end(),
double(0)) / u.size();
double var = 0;
double skew = 0;
double kurtosis = 0;
for (int i = 0; i < u.size(); ++i)
{
double d = (u[i] - mean);
double d2 = sqr(d);
var += d2;
skew += d * d2;
kurtosis += d2 * d2;
}
var /= u.size();
double dev = std::sqrt(var);
skew /= u.size() * dev * var;
kurtosis /= u.size() * var * var;
kurtosis -= 3;
double x_mean = (1 - d.p()) / d.p();
double x_var = x_mean / d.p();
double x_skew = (2 - d.p()) / std::sqrt((1 - d.p()));
double x_kurtosis = 6 + sqr(d.p()) / (1 - d.p());
assert(std::abs((mean - x_mean) / x_mean) < 0.01);
assert(std::abs((var - x_var) / x_var) < 0.01);
assert(std::abs((skew - x_skew) / x_skew) < 0.01);
assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.02);
}
{
typedef std::geometric_distribution<> D;
typedef std::mt19937 G;
G g;
D d(0.5);
const int N = 1000000;
std::vector<D::result_type> u;
for (int i = 0; i < N; ++i)
{
D::result_type v = d(g);
assert(d.min() <= v && v <= d.max());
u.push_back(v);
}
double mean = std::accumulate(u.begin(), u.end(),
double(0)) / u.size();
double var = 0;
double skew = 0;
double kurtosis = 0;
for (int i = 0; i < u.size(); ++i)
{
double d = (u[i] - mean);
double d2 = sqr(d);
var += d2;
skew += d * d2;
kurtosis += d2 * d2;
}
var /= u.size();
double dev = std::sqrt(var);
skew /= u.size() * dev * var;
kurtosis /= u.size() * var * var;
kurtosis -= 3;
double x_mean = (1 - d.p()) / d.p();
double x_var = x_mean / d.p();
double x_skew = (2 - d.p()) / std::sqrt((1 - d.p()));
double x_kurtosis = 6 + sqr(d.p()) / (1 - d.p());
assert(std::abs((mean - x_mean) / x_mean) < 0.01);
assert(std::abs((var - x_var) / x_var) < 0.01);
assert(std::abs((skew - x_skew) / x_skew) < 0.01);
assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.02);
}
{
typedef std::geometric_distribution<> D;
typedef std::mt19937 G;
G g;
D d(0.75);
const int N = 1000000;
std::vector<D::result_type> u;
for (int i = 0; i < N; ++i)
{
D::result_type v = d(g);
assert(d.min() <= v && v <= d.max());
u.push_back(v);
}
double mean = std::accumulate(u.begin(), u.end(),
double(0)) / u.size();
double var = 0;
double skew = 0;
double kurtosis = 0;
for (int i = 0; i < u.size(); ++i)
{
double d = (u[i] - mean);
double d2 = sqr(d);
var += d2;
skew += d * d2;
kurtosis += d2 * d2;
}
var /= u.size();
double dev = std::sqrt(var);
skew /= u.size() * dev * var;
kurtosis /= u.size() * var * var;
kurtosis -= 3;
double x_mean = (1 - d.p()) / d.p();
double x_var = x_mean / d.p();
double x_skew = (2 - d.p()) / std::sqrt((1 - d.p()));
double x_kurtosis = 6 + sqr(d.p()) / (1 - d.p());
assert(std::abs((mean - x_mean) / x_mean) < 0.01);
assert(std::abs((var - x_var) / x_var) < 0.01);
assert(std::abs((skew - x_skew) / x_skew) < 0.01);
assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.02);
}
{
typedef std::geometric_distribution<> D;
typedef std::mt19937 G;
G g;
D d(0.96875);
const int N = 1000000;
std::vector<D::result_type> u;
for (int i = 0; i < N; ++i)
{
D::result_type v = d(g);
assert(d.min() <= v && v <= d.max());
u.push_back(v);
}
double mean = std::accumulate(u.begin(), u.end(),
double(0)) / u.size();
double var = 0;
double skew = 0;
double kurtosis = 0;
for (int i = 0; i < u.size(); ++i)
{
double d = (u[i] - mean);
double d2 = sqr(d);
var += d2;
skew += d * d2;
kurtosis += d2 * d2;
}
var /= u.size();
double dev = std::sqrt(var);
skew /= u.size() * dev * var;
kurtosis /= u.size() * var * var;
kurtosis -= 3;
double x_mean = (1 - d.p()) / d.p();
double x_var = x_mean / d.p();
double x_skew = (2 - d.p()) / std::sqrt((1 - d.p()));
double x_kurtosis = 6 + sqr(d.p()) / (1 - d.p());
assert(std::abs((mean - x_mean) / x_mean) < 0.01);
assert(std::abs((var - x_var) / x_var) < 0.01);
assert(std::abs((skew - x_skew) / x_skew) < 0.01);
assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.02);
}
}

View File

@@ -0,0 +1,160 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// REQUIRES: long_tests
// <random>
// template<class IntType = int>
// class geometric_distribution
// template<class _URNG> result_type operator()(_URNG& g, const param_type& parm);
#include <random>
#include <numeric>
#include <vector>
#include <cassert>
template <class T>
inline
T
sqr(T x)
{
return x * x;
}
int main()
{
{
typedef std::geometric_distribution<> D;
typedef D::param_type P;
typedef std::mt19937 G;
G g;
D d(.75);
P p(.03125);
const int N = 1000000;
std::vector<D::result_type> u;
for (int i = 0; i < N; ++i)
{
D::result_type v = d(g, p);
assert(d.min() <= v && v <= d.max());
u.push_back(v);
}
double mean = std::accumulate(u.begin(), u.end(),
double(0)) / u.size();
double var = 0;
double skew = 0;
double kurtosis = 0;
for (int i = 0; i < u.size(); ++i)
{
double d = (u[i] - mean);
double d2 = sqr(d);
var += d2;
skew += d * d2;
kurtosis += d2 * d2;
}
var /= u.size();
double dev = std::sqrt(var);
skew /= u.size() * dev * var;
kurtosis /= u.size() * var * var;
kurtosis -= 3;
double x_mean = (1 - p.p()) / p.p();
double x_var = x_mean / p.p();
double x_skew = (2 - p.p()) / std::sqrt((1 - p.p()));
double x_kurtosis = 6 + sqr(p.p()) / (1 - p.p());
assert(std::abs((mean - x_mean) / x_mean) < 0.01);
assert(std::abs((var - x_var) / x_var) < 0.01);
assert(std::abs((skew - x_skew) / x_skew) < 0.01);
assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.01);
}
{
typedef std::geometric_distribution<> D;
typedef D::param_type P;
typedef std::mt19937 G;
G g;
D d(.75);
P p(.25);
const int N = 1000000;
std::vector<D::result_type> u;
for (int i = 0; i < N; ++i)
{
D::result_type v = d(g, p);
assert(d.min() <= v && v <= d.max());
u.push_back(v);
}
double mean = std::accumulate(u.begin(), u.end(),
double(0)) / u.size();
double var = 0;
double skew = 0;
double kurtosis = 0;
for (int i = 0; i < u.size(); ++i)
{
double d = (u[i] - mean);
double d2 = sqr(d);
var += d2;
skew += d * d2;
kurtosis += d2 * d2;
}
var /= u.size();
double dev = std::sqrt(var);
skew /= u.size() * dev * var;
kurtosis /= u.size() * var * var;
kurtosis -= 3;
double x_mean = (1 - p.p()) / p.p();
double x_var = x_mean / p.p();
double x_skew = (2 - p.p()) / std::sqrt((1 - p.p()));
double x_kurtosis = 6 + sqr(p.p()) / (1 - p.p());
assert(std::abs((mean - x_mean) / x_mean) < 0.01);
assert(std::abs((var - x_var) / x_var) < 0.01);
assert(std::abs((skew - x_skew) / x_skew) < 0.01);
assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.03);
}
{
typedef std::geometric_distribution<> D;
typedef D::param_type P;
typedef std::minstd_rand G;
G g;
D d(.5);
P p(.75);
const int N = 1000000;
std::vector<D::result_type> u;
for (int i = 0; i < N; ++i)
{
D::result_type v = d(g, p);
assert(d.min() <= v && v <= d.max());
u.push_back(v);
}
double mean = std::accumulate(u.begin(), u.end(),
double(0)) / u.size();
double var = 0;
double skew = 0;
double kurtosis = 0;
for (int i = 0; i < u.size(); ++i)
{
double d = (u[i] - mean);
double d2 = sqr(d);
var += d2;
skew += d * d2;
kurtosis += d2 * d2;
}
var /= u.size();
double dev = std::sqrt(var);
skew /= u.size() * dev * var;
kurtosis /= u.size() * var * var;
kurtosis -= 3;
double x_mean = (1 - p.p()) / p.p();
double x_var = x_mean / p.p();
double x_skew = (2 - p.p()) / std::sqrt((1 - p.p()));
double x_kurtosis = 6 + sqr(p.p()) / (1 - p.p());
assert(std::abs((mean - x_mean) / x_mean) < 0.01);
assert(std::abs((var - x_var) / x_var) < 0.01);
assert(std::abs((skew - x_skew) / x_skew) < 0.01);
assert(std::abs((kurtosis - x_kurtosis) / x_kurtosis) < 0.02);
}
}

View File

@@ -0,0 +1,29 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <random>
// template<class IntType = int>
// class geometric_distribution
// param_type param() const;
#include <random>
#include <cassert>
int main()
{
{
typedef std::geometric_distribution<> D;
typedef D::param_type P;
P p(.125);
D d(p);
assert(d.param() == p);
}
}

View File

@@ -0,0 +1,41 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <random>
// template<class IntType = int>
// class geometric_distribution
// template <class charT, class traits>
// basic_ostream<charT, traits>&
// operator<<(basic_ostream<charT, traits>& os,
// const geometric_distribution& x);
//
// template <class charT, class traits>
// basic_istream<charT, traits>&
// operator>>(basic_istream<charT, traits>& is,
// geometric_distribution& x);
#include <random>
#include <sstream>
#include <cassert>
int main()
{
{
typedef std::geometric_distribution<> D;
D d1(.25);
std::ostringstream os;
os << d1;
std::istringstream is(os.str());
D d2;
is >> d2;
assert(d1 == d2);
}
}

View File

@@ -0,0 +1,27 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <random>
// template<class IntType = int>
// class geometric_distribution
// result_type max() const;
#include <random>
#include <cassert>
int main()
{
{
typedef std::geometric_distribution<> D;
D d(.25);
assert(d.max() == std::numeric_limits<int>::max());
}
}

View File

@@ -0,0 +1,27 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <random>
// template<class IntType = int>
// class geometric_distribution
// result_type min() const;
#include <random>
#include <cassert>
int main()
{
{
typedef std::geometric_distribution<> D;
D d(.5);
assert(d.min() == 0);
}
}

View File

@@ -0,0 +1,31 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <random>
// template<class IntType = int>
// class geometric_distribution
// {
// class param_type;
#include <random>
#include <limits>
#include <cassert>
int main()
{
{
typedef std::geometric_distribution<> D;
typedef D::param_type param_type;
param_type p0(.7);
param_type p;
p = p0;
assert(p.p() == .7);
}
}

View File

@@ -0,0 +1,30 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <random>
// template<class IntType = int>
// class geometric_distribution
// {
// class param_type;
#include <random>
#include <limits>
#include <cassert>
int main()
{
{
typedef std::geometric_distribution<> D;
typedef D::param_type param_type;
param_type p0(.125);
param_type p = p0;
assert(p.p() == .125);
}
}

View File

@@ -0,0 +1,35 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <random>
// template<class IntType = int>
// class geometric_distribution
// {
// class param_type;
#include <random>
#include <limits>
#include <cassert>
int main()
{
{
typedef std::geometric_distribution<> D;
typedef D::param_type param_type;
param_type p;
assert(p.p() == 0.5);
}
{
typedef std::geometric_distribution<> D;
typedef D::param_type param_type;
param_type p(0.25);
assert(p.p() == 0.25);
}
}

View File

@@ -0,0 +1,37 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <random>
// template<class IntType = int>
// class geometric_distribution
// {
// class param_type;
#include <random>
#include <limits>
#include <cassert>
int main()
{
{
typedef std::geometric_distribution<> D;
typedef D::param_type param_type;
param_type p1(0.75);
param_type p2(0.75);
assert(p1 == p2);
}
{
typedef std::geometric_distribution<> D;
typedef D::param_type param_type;
param_type p1(0.75);
param_type p2(0.5);
assert(p1 != p2);
}
}

Some files were not shown because too many files have changed in this diff Show More