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,58 @@
//===----------------------------------------------------------------------===//
//
// 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 UIntType, UIntType a, UIntType c, UIntType m>
// class linear_congruential_engine;
// linear_congruential_engine& operator=(const linear_congruential_engine&);
#include <random>
#include <cassert>
template <class T, T a, T c, T m>
void
test1()
{
typedef std::linear_congruential_engine<T, a, c, m> E;
E e1;
E e2;
assert(e1 == e2);
e1();
e2 = e1;
assert(e1 == e2);
}
template <class T>
void
test()
{
test1<T, 0, 0, 0>();
test1<T, 0, 1, 2>();
test1<T, 1, 1, 2>();
const T M(~0);
test1<T, 0, 0, M>();
test1<T, 0, M-2, M>();
test1<T, 0, M-1, M>();
test1<T, M-2, 0, M>();
test1<T, M-2, M-2, M>();
test1<T, M-2, M-1, M>();
test1<T, M-1, 0, M>();
test1<T, M-1, M-2, M>();
test1<T, M-1, M-1, M>();
}
int main()
{
test<unsigned short>();
test<unsigned int>();
test<unsigned long>();
test<unsigned long long>();
}

View File

@@ -0,0 +1,58 @@
//===----------------------------------------------------------------------===//
//
// 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 UIntType, UIntType a, UIntType c, UIntType m>
// class linear_congruential_engine;
// linear_congruential_engine(const linear_congruential_engine&);
#include <random>
#include <cassert>
template <class T, T a, T c, T m>
void
test1()
{
typedef std::linear_congruential_engine<T, a, c, m> E;
E e1;
E e2 = e1;
assert(e1 == e2);
e1();
e2();
assert(e1 == e2);
}
template <class T>
void
test()
{
test1<T, 0, 0, 0>();
test1<T, 0, 1, 2>();
test1<T, 1, 1, 2>();
const T M(~0);
test1<T, 0, 0, M>();
test1<T, 0, M-2, M>();
test1<T, 0, M-1, M>();
test1<T, M-2, 0, M>();
test1<T, M-2, M-2, M>();
test1<T, M-2, M-1, M>();
test1<T, M-1, 0, M>();
test1<T, M-1, M-2, M>();
test1<T, M-1, M-1, M>();
}
int main()
{
test<unsigned short>();
test<unsigned int>();
test<unsigned long>();
test<unsigned long long>();
}

View File

@@ -0,0 +1,154 @@
//===----------------------------------------------------------------------===//
//
// 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 UIntType, UIntType a, UIntType c, UIntType m>
// class linear_congruential_engine;
// explicit linear_congruential_engine(result_type s = default_seed);
#include <random>
#include <sstream>
#include <cassert>
template <class T>
void
test1()
{
// c % m != 0 && s % m != 0
{
typedef std::linear_congruential_engine<T, 2, 3, 7> E;
E e(5);
std::ostringstream os;
os << e;
assert(os.str() == "5");
}
{
typedef std::linear_congruential_engine<T, 2, 3, 0> E;
E e(5);
std::ostringstream os;
os << e;
assert(os.str() == "5");
}
{
typedef std::linear_congruential_engine<T, 2, 3, 4> E;
E e(5);
std::ostringstream os;
os << e;
assert(os.str() == "1");
}
}
template <class T>
void
test2()
{
// c % m != 0 && s % m == 0
{
typedef std::linear_congruential_engine<T, 2, 3, 7> E;
E e(7);
std::ostringstream os;
os << e;
assert(os.str() == "0");
}
{
typedef std::linear_congruential_engine<T, 2, 3, 0> E;
E e(0);
std::ostringstream os;
os << e;
assert(os.str() == "0");
}
{
typedef std::linear_congruential_engine<T, 2, 3, 4> E;
E e(4);
std::ostringstream os;
os << e;
assert(os.str() == "0");
}
}
template <class T>
void
test3()
{
// c % m == 0 && s % m != 0
{
typedef std::linear_congruential_engine<T, 2, 0, 7> E;
E e(3);
std::ostringstream os;
os << e;
assert(os.str() == "3");
}
{
typedef std::linear_congruential_engine<T, 2, 0, 0> E;
E e(5);
std::ostringstream os;
os << e;
assert(os.str() == "5");
}
{
typedef std::linear_congruential_engine<T, 2, 0, 4> E;
E e(7);
std::ostringstream os;
os << e;
assert(os.str() == "3");
}
}
template <class T>
void
test4()
{
// c % m == 0 && s % m == 0
{
typedef std::linear_congruential_engine<T, 2, 0, 7> E;
E e(7);
std::ostringstream os;
os << e;
assert(os.str() == "1");
}
{
typedef std::linear_congruential_engine<T, 2, 0, 0> E;
E e(0);
std::ostringstream os;
os << e;
assert(os.str() == "1");
}
{
typedef std::linear_congruential_engine<T, 2, 0, 4> E;
E e(8);
std::ostringstream os;
os << e;
assert(os.str() == "1");
}
}
int main()
{
test1<unsigned short>();
test1<unsigned int>();
test1<unsigned long>();
test1<unsigned long long>();
test2<unsigned short>();
test2<unsigned int>();
test2<unsigned long>();
test2<unsigned long long>();
test3<unsigned short>();
test3<unsigned int>();
test3<unsigned long>();
test3<unsigned long long>();
test4<unsigned short>();
test4<unsigned int>();
test4<unsigned long>();
test4<unsigned long long>();
}

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 UIntType, UIntType a, UIntType c, UIntType m>
// class linear_congruential_engine;
// template<class Sseq> explicit linear_congruential_engine(Sseq& q);
#include <random>
#include <cassert>
int main()
{
{
unsigned a[] = {3, 5, 7};
std::seed_seq sseq(a, a+3);
std::linear_congruential_engine<unsigned, 5, 7, 11> e1(sseq);
std::linear_congruential_engine<unsigned, 5, 7, 11> e2(4);
assert(e1 == e2);
}
}

View File

@@ -0,0 +1,57 @@
//===----------------------------------------------------------------------===//
//
// 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 UIntType, UIntType a, UIntType c, UIntType m>
// class linear_congruential_engine;
// linear_congruential_engine();
#include <random>
#include <cassert>
template <class T, T a, T c, T m>
void
test1()
{
typedef std::linear_congruential_engine<T, a, c, m> LCE;
typedef typename LCE::result_type result_type;
LCE e1;
LCE e2;
e2.seed();
assert(e1 == e2);
}
template <class T>
void
test()
{
test1<T, 0, 0, 0>();
test1<T, 0, 1, 2>();
test1<T, 1, 1, 2>();
const T M(~0);
test1<T, 0, 0, M>();
test1<T, 0, M-2, M>();
test1<T, 0, M-1, M>();
test1<T, M-2, 0, M>();
test1<T, M-2, M-2, M>();
test1<T, M-2, M-1, M>();
test1<T, M-1, 0, M>();
test1<T, M-1, M-2, M>();
test1<T, M-1, M-1, M>();
}
int main()
{
test<unsigned short>();
test<unsigned int>();
test<unsigned long>();
test<unsigned long long>();
}

View File

@@ -0,0 +1,73 @@
//===----------------------------------------------------------------------===//
//
// 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 UIntType, UIntType a, UIntType c, UIntType m>
// class linear_congruential_engine;
// void discard(unsigned long long z);
#include <random>
#include <cassert>
template <class T>
void
rand0()
{
typedef std::linear_congruential_engine<T, 16807, 0, 2147483647> E;
E e;
e.discard(9999);
assert(e() == 1043618065);
}
template <class T>
void
rand()
{
typedef std::linear_congruential_engine<T, 48271, 0, 2147483647> E;
E e;
e.discard(9999);
assert(e() == 399268537);
}
template <class T>
void
other()
{
typedef std::linear_congruential_engine<T, 48271, 123465789, 2147483647> E;
E e1;
E e2;
assert(e1 == e2);
e1.discard(1);
assert(e1 != e2);
e2();
assert(e1 == e2);
e1.discard(3);
assert(e1 != e2);
e2();
e2();
e2();
assert(e1 == e2);
}
int main()
{
rand0<unsigned int>();
rand0<unsigned long>();
rand0<unsigned long long>();
rand<unsigned int>();
rand<unsigned long>();
rand<unsigned long long>();
other<unsigned int>();
other<unsigned long>();
other<unsigned long long>();
}

View File

@@ -0,0 +1,87 @@
//===----------------------------------------------------------------------===//
//
// 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 UIntType, UIntType a, UIntType c, UIntType m>
// class linear_congruential_engine;
// result_type operator()();
#include <random>
#include <cassert>
template <class T>
void
randu()
{
typedef std::linear_congruential_engine<T, 65539, 0, 2147483648u> E;
E e(1);
assert(e() == 65539);
assert(e() == 393225);
assert(e() == 1769499);
assert(e() == 7077969);
assert(e() == 26542323);
assert(e() == 95552217);
assert(e() == 334432395);
assert(e() == 1146624417);
assert(e() == 1722371299);
assert(e() == 14608041);
assert(e() == 1766175739);
assert(e() == 1875647473);
}
template <class T>
void
minstd()
{
typedef std::linear_congruential_engine<T, 16807, 0, 2147483647> E;
E e(1);
assert(e() == 16807);
assert(e() == 282475249);
assert(e() == 1622650073);
assert(e() == 984943658);
assert(e() == 1144108930);
assert(e() == 470211272);
assert(e() == 101027544);
assert(e() == 1457850878);
assert(e() == 1458777923);
assert(e() == 2007237709);
assert(e() == 823564440);
assert(e() == 1115438165);
}
template <class T>
void
Haldir()
{
typedef std::linear_congruential_engine<T, 16807, 78125, 2147483647> E;
E e(207560540);
assert(e() == 956631177);
assert(e() == 2037688522);
assert(e() == 1509348670);
assert(e() == 1546336451);
assert(e() == 429714088);
assert(e() == 217250280);
}
int main()
{
randu<unsigned int>();
randu<unsigned long>();
randu<unsigned long long>();
minstd<unsigned int>();
minstd<unsigned long>();
minstd<unsigned long long>();
Haldir<unsigned int>();
Haldir<unsigned long>();
Haldir<unsigned long long>();
}

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 UIntType, UIntType a, UIntType c, UIntType m>
// class linear_congruential_engine;
// template <class charT, class traits,
// class UIntType, UIntType a, UIntType c, UIntType m>
// basic_ostream<charT, traits>&
// operator<<(basic_ostream<charT, traits>& os,
// const linear_congruential_engine<UIntType, a, c, m>& x);
//
// template <class charT, class traits,
// class UIntType, UIntType a, UIntType c, UIntType m>
// basic_istream<charT, traits>&
// operator>>(basic_istream<charT, traits>& is,
// linear_congruential_engine<UIntType, a, c, m>& x);
#include <random>
#include <sstream>
#include <cassert>
int main()
{
{
typedef std::linear_congruential_engine<unsigned, 48271, 0, 2147483647> E;
E e1;
e1.discard(100);
std::ostringstream os;
os << e1;
std::istringstream is(os.str());
E e2;
is >> e2;
assert(e1 == e2);
}
}

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 UIntType, UIntType a, UIntType c, UIntType m>
// class linear_congruential_engine
// {
// public:
// // types
// typedef UIntType result_type;
#include <random>
#include <type_traits>
template <class T>
void
test()
{
static_assert((std::is_same<
typename std::linear_congruential_engine<T, 0, 0, 0>::result_type,
T>::value), "");
}
int main()
{
test<unsigned short>();
test<unsigned int>();
test<unsigned long>();
test<unsigned long long>();
}

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 UIntType, UIntType a, UIntType c, UIntType m>
// class linear_congruential_engine;
// void seed(result_type s = default_seed);
#include <random>
#include <cassert>
template <class T>
void
test1()
{
for (int s = 0; s < 20; ++s)
{
typedef std::linear_congruential_engine<T, 2, 3, 7> E;
E e1(s);
E e2;
e2.seed(s);
assert(e1 == e2);
}
}
int main()
{
test1<unsigned short>();
test1<unsigned int>();
test1<unsigned long>();
test1<unsigned long long>();
}

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 UIntType, UIntType a, UIntType c, UIntType m>
// class linear_congruential_engine;
// template<class Sseq> void seed(Sseq& q);
#include <random>
#include <cassert>
int main()
{
{
unsigned a[] = {3, 5, 7};
std::seed_seq sseq(a, a+3);
std::linear_congruential_engine<unsigned, 5, 7, 11> e1;
std::linear_congruential_engine<unsigned, 5, 7, 11> e2(4);
assert(e1 != e2);
e1.seed(sseq);
assert(e1 == e2);
}
{
unsigned a[] = {3, 5, 7, 9, 11};
std::seed_seq sseq(a, a+5);
typedef std::linear_congruential_engine<unsigned long long, 1, 1, 0x200000001ULL> E;
E e1(4309005589);
E e2(sseq);
assert(e1 == e2);
}
}

View File

@@ -0,0 +1,74 @@
//===----------------------------------------------------------------------===//
//
// 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 UIntType, UIntType a, UIntType c, UIntType m>
// class linear_congruential_engine
// {
// public:
// engine characteristics
// static constexpr result_type multiplier = a;
// static constexpr result_type increment = c;
// static constexpr result_type modulus = m;
// static constexpr result_type min() { return c == 0u ? 1u: 0u;}
// static constexpr result_type max() { return m - 1u;}
// static constexpr result_type default_seed = 1u;
#include <random>
#include <type_traits>
#include <cassert>
template <class _Tp>
void where(const _Tp &) {}
template <class T, T a, T c, T m>
void
test1()
{
typedef std::linear_congruential_engine<T, a, c, m> LCE;
typedef typename LCE::result_type result_type;
static_assert((LCE::multiplier == a), "");
static_assert((LCE::increment == c), "");
static_assert((LCE::modulus == m), "");
/*static_*/assert((LCE::min() == (c == 0u ? 1u: 0u))/*, ""*/);
/*static_*/assert((LCE::max() == result_type(m - 1u))/*, ""*/);
static_assert((LCE::default_seed == 1), "");
where(LCE::multiplier);
where(LCE::increment);
where(LCE::modulus);
where(LCE::default_seed);
}
template <class T>
void
test()
{
test1<T, 0, 0, 0>();
test1<T, 0, 1, 2>();
test1<T, 1, 1, 2>();
const T M(~0);
test1<T, 0, 0, M>();
test1<T, 0, M-2, M>();
test1<T, 0, M-1, M>();
test1<T, M-2, 0, M>();
test1<T, M-2, M-2, M>();
test1<T, M-2, M-1, M>();
test1<T, M-1, 0, M>();
test1<T, M-1, M-2, M>();
test1<T, M-1, M-1, M>();
}
int main()
{
test<unsigned short>();
test<unsigned int>();
test<unsigned long>();
test<unsigned long long>();
}