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,24 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
// <functional>
// Hashing a struct w/o a defined hash should fail.
#include <functional>
#include <cassert>
#include <type_traits>
struct X {};
int main()
{
X x;
size_t h = std::hash<X>{} ( x );
}

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.
//
//===----------------------------------------------------------------------===//
// <functional>
// make sure that we can hash enumeration values
// Not very portable
#include <__config>
#if _LIBCPP_STD_VER > 11
#include <functional>
#include <cassert>
#include <type_traits>
#include <limits>
enum class Colors { red, orange, yellow, green, blue, indigo, violet };
enum class Cardinals { zero, one, two, three, five=5 };
enum class LongColors : short { red, orange, yellow, green, blue, indigo, violet };
enum class ShortColors : long { red, orange, yellow, green, blue, indigo, violet };
enum class EightBitColors : uint8_t { red, orange, yellow, green, blue, indigo, violet };
enum Fruits { apple, pear, grape, mango, cantaloupe };
template <class T>
void
test()
{
static_assert((std::is_base_of<std::unary_function<T, std::size_t>,
std::hash<T> >::value), "");
typedef typename std::underlying_type<T>::type under_type;
std::hash<T> h1;
std::hash<under_type> h2;
for (int i = 0; i <= 5; ++i)
{
T t(static_cast<T> (i));
if (sizeof(T) <= sizeof(std::size_t))
assert(h1(t) == h2(static_cast<under_type>(i)));
}
}
int main()
{
test<Cardinals>();
test<Colors>();
test<ShortColors>();
test<LongColors>();
test<EightBitColors>();
test<Fruits>();
}
#else
int main () {}
#endif

View File

@@ -0,0 +1,68 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
// <functional>
// template <class T>
// struct hash
// : public unary_function<T, size_t>
// {
// size_t operator()(T val) const;
// };
// Not very portable
#include <functional>
#include <cassert>
#include <type_traits>
#include <limits>
#include <cmath>
template <class T>
void
test()
{
static_assert((std::is_base_of<std::unary_function<T, std::size_t>,
std::hash<T> >::value), "");
std::hash<T> h;
std::size_t t0 = h(0.);
std::size_t tn0 = h(-0.);
std::size_t tp1 = h(0.1);
std::size_t t1 = h(1);
std::size_t tn1 = h(-1);
std::size_t pinf = h(INFINITY);
std::size_t ninf = h(-INFINITY);
assert(t0 == tn0);
assert(t0 != tp1);
assert(t0 != t1);
assert(t0 != tn1);
assert(t0 != pinf);
assert(t0 != ninf);
assert(tp1 != t1);
assert(tp1 != tn1);
assert(tp1 != pinf);
assert(tp1 != ninf);
assert(t1 != tn1);
assert(t1 != pinf);
assert(t1 != ninf);
assert(tn1 != pinf);
assert(tn1 != ninf);
assert(pinf != ninf);
}
int main()
{
test<float>();
test<double>();
test<long double>();
}

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.
//
//===----------------------------------------------------------------------===//
// <functional>
// template <class T>
// struct hash
// : public unary_function<T, size_t>
// {
// size_t operator()(T val) const;
// };
// Not very portable
#include <functional>
#include <cassert>
#include <type_traits>
#include <limits>
template <class T>
void
test()
{
static_assert((std::is_base_of<std::unary_function<T, std::size_t>,
std::hash<T> >::value), "");
std::hash<T> h;
for (int i = 0; i <= 5; ++i)
{
T t(i);
if (sizeof(T) <= sizeof(std::size_t))
assert(h(t) == t);
}
}
int main()
{
test<bool>();
test<char>();
test<signed char>();
test<unsigned char>();
test<char16_t>();
test<char32_t>();
test<wchar_t>();
test<short>();
test<unsigned short>();
test<int>();
test<unsigned int>();
test<long>();
test<unsigned long>();
test<long long>();
test<unsigned long long>();
}

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.
//
//===----------------------------------------------------------------------===//
// <functional>
// template <class T>
// struct hash
// : public unary_function<T, size_t>
// {
// size_t operator()(T val) const;
// };
// Not very portable
#include <functional>
#include <cassert>
#include <type_traits>
#include <limits>
template <class T>
void
test()
{
static_assert((std::is_base_of<std::unary_function<T, std::size_t>,
std::hash<T> >::value), "");
std::hash<T> h;
typedef typename std::remove_pointer<T>::type type;
type i;
type j;
assert(h(&i) != h(&j));
}
int main()
{
test<int*>();
}