Move the <dynarray> tests out of the std/ hierarchy, since it's not really part of the standard any more.

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@231311 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Marshall Clow
2015-03-04 23:09:15 +00:00
parent e917d804db
commit 3b1d283788
12 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,94 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
// dynarray.overview
// const_reference at(size_type n) const;
// reference at(size_type n);
#include <__config>
#if _LIBCPP_STD_VER > 11
#include <experimental/dynarray>
#include <cassert>
#include <algorithm>
#include <complex>
#include <string>
using std::experimental::dynarray;
template <class T>
void dyn_at_fail ( dynarray<T> &dyn, size_t sz ) {
try { dyn.at (sz); }
catch (const std::out_of_range &) { return; }
assert ( false );
}
template <class T>
void dyn_at_fail_const ( const dynarray<T> &dyn, size_t sz ) {
try { dyn.at (sz); }
catch (const std::out_of_range &) { return; }
assert ( false );
}
template <class T>
void dyn_test_const ( const dynarray<T> &dyn, const std::initializer_list<T> &vals ) {
const T *data = dyn.data ();
auto it = vals.begin ();
for ( size_t i = 0; i < dyn.size(); ++i, ++it ) {
assert ( data + i == &dyn.at(i));
assert ( *it == dyn.at(i));
}
dyn_at_fail_const ( dyn, dyn.size ());
dyn_at_fail_const ( dyn, 2*dyn.size ());
dyn_at_fail_const ( dyn, size_t (-1));
}
template <class T>
void dyn_test ( dynarray<T> &dyn, const std::initializer_list<T> &vals ) {
T *data = dyn.data ();
auto it = vals.begin ();
for ( size_t i = 0; i < dyn.size(); ++i, ++it ) {
assert ( data + i == &dyn.at(i));
assert ( *it == dyn.at(i));
}
dyn_at_fail ( dyn, dyn.size ());
dyn_at_fail ( dyn, 2*dyn.size ());
dyn_at_fail ( dyn, size_t (-1));
}
template <class T>
void test ( std::initializer_list<T> vals ) {
typedef dynarray<T> dynA;
dynA d1 ( vals );
dyn_test ( d1, vals );
dyn_test_const ( d1, vals );
}
int main()
{
test ( { 1, 1, 2, 3, 5, 8 } );
test ( { 1., 1., 2., 3., 5., 8. } );
test ( { std::string("1"), std::string("1"), std::string("2"), std::string("3"),
std::string("5"), std::string("8")} );
test<int> ( {} );
test<std::complex<double>> ( {} );
test<std::string> ( {} );
}
#else
int main() {}
#endif

View File

@@ -0,0 +1,108 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
// dynarray.overview
// iterator begin() noexcept;
// const_iterator begin() const noexcept;
// const_iterator cbegin() const noexcept;
// iterator end() noexcept;
// const_iterator end() const noexcept;
// const_iterator cend() const noexcept;
//
// reverse_iterator rbegin() noexcept;
// const_reverse_iterator rbegin() const noexcept;
// const_reverse_iterator crbegin() const noexcept;
// reverse_iterator rend() noexcept;
// const_reverse_iterator rend() const noexcept;
// const_reverse_iterator crend() const noexcept;
#include <__config>
#if _LIBCPP_STD_VER > 11
#include <experimental/dynarray>
#include <cassert>
#include <algorithm>
#include <complex>
#include <string>
using std::experimental::dynarray;
template <class T>
void dyn_test_const ( const dynarray<T> &dyn ) {
const T *data = dyn.data ();
assert ( data == &*dyn.begin ());
assert ( data == &*dyn.cbegin ());
assert ( data + dyn.size() - 1 == &*dyn.rbegin ());
assert ( data + dyn.size() - 1 == &*dyn.crbegin ());
assert ( dyn.size () == std::distance ( dyn.begin(), dyn.end()));
assert ( dyn.size () == std::distance ( dyn.cbegin(), dyn.cend()));
assert ( dyn.size () == std::distance ( dyn.rbegin(), dyn.rend()));
assert ( dyn.size () == std::distance ( dyn.crbegin(), dyn.crend()));
assert ( dyn.begin () == dyn.cbegin ());
assert ( &*dyn.begin () == &*dyn.cbegin ());
assert ( dyn.rbegin () == dyn.crbegin ());
assert ( &*dyn.rbegin () == &*dyn.crbegin ());
assert ( dyn.end () == dyn.cend ());
assert ( dyn.rend () == dyn.crend ());
}
template <class T>
void dyn_test ( dynarray<T> &dyn ) {
T *data = dyn.data ();
assert ( data == &*dyn.begin ());
assert ( data == &*dyn.cbegin ());
assert ( data + dyn.size() - 1 == &*dyn.rbegin ());
assert ( data + dyn.size() - 1 == &*dyn.crbegin ());
assert ( dyn.size () == std::distance ( dyn.begin(), dyn.end()));
assert ( dyn.size () == std::distance ( dyn.cbegin(), dyn.cend()));
assert ( dyn.size () == std::distance ( dyn.rbegin(), dyn.rend()));
assert ( dyn.size () == std::distance ( dyn.crbegin(), dyn.crend()));
assert ( dyn.begin () == dyn.cbegin ());
assert ( &*dyn.begin () == &*dyn.cbegin ());
assert ( dyn.rbegin () == dyn.crbegin ());
assert ( &*dyn.rbegin () == &*dyn.crbegin ());
assert ( dyn.end () == dyn.cend ());
assert ( dyn.rend () == dyn.crend ());
}
template <class T>
void test ( const T &val ) {
typedef dynarray<T> dynA;
dynA d1 ( 4 );
dyn_test ( d1 );
dyn_test_const ( d1 );
dynA d2 ( 7, val );
dyn_test ( d2 );
dyn_test_const ( d2 );
}
int main()
{
test<int> ( 14 );
test<double> ( 14.0 );
test<std::complex<double>> ( std::complex<double> ( 14, 0 ));
test<std::string> ( "fourteen" );
}
#else
int main() {}
#endif

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.
//
//===----------------------------------------------------------------------===//
// dynarray.overview
// size_type size() const noexcept;
// size_type max_size() const noexcept;
// bool empty() const noexcept;
#include <__config>
#if _LIBCPP_STD_VER > 11
#include <experimental/dynarray>
#include <cassert>
#include <algorithm>
#include <complex>
#include <string>
using std::experimental::dynarray;
template <class T>
void dyn_test ( const dynarray<T> &dyn, size_t sz ) {
assert ( dyn.size () == sz );
assert ( dyn.max_size () == sz );
assert ( dyn.empty () == ( sz == 0 ));
}
template <class T>
void test ( std::initializer_list<T> vals ) {
typedef dynarray<T> dynA;
dynA d1 ( vals );
dyn_test ( d1, vals.size ());
}
int main()
{
test ( { 1, 1, 2, 3, 5, 8 } );
test ( { 1., 1., 2., 3., 5., 8. } );
test ( { std::string("1"), std::string("1"), std::string("2"), std::string("3"),
std::string("5"), std::string("8")} );
test<int> ( {} );
test<std::complex<double>> ( {} );
test<std::string> ( {} );
}
#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.
//
//===----------------------------------------------------------------------===//
// dynarray.overview
// reference front();
// const_reference front() const;
// reference back();
// const_reference back() const;
#include <__config>
#if _LIBCPP_STD_VER > 11
#include <experimental/dynarray>
#include <cassert>
#include <algorithm>
#include <complex>
#include <string>
using std::experimental::dynarray;
template <class T>
void dyn_test_const ( const dynarray<T> &dyn ) {
const T *data = dyn.data ();
assert ( *data == dyn.front ());
assert ( *(data + dyn.size() - 1 ) == dyn.back ());
}
template <class T>
void dyn_test ( dynarray<T> &dyn ) {
T *data = dyn.data ();
assert ( *data == dyn.front ());
assert ( *(data + dyn.size() - 1 ) == dyn.back ());
}
template <class T>
void test ( const T &val ) {
typedef dynarray<T> dynA;
dynA d1 ( 4 );
dyn_test ( d1 );
dyn_test_const ( d1 );
dynA d2 ( 7, val );
dyn_test ( d2 );
dyn_test_const ( d2 );
}
int main()
{
test<int> ( 14 );
test<double> ( 14.0 );
test<std::complex<double>> ( std::complex<double> ( 14, 0 ));
test<std::string> ( "fourteen" );
}
#else
int main() {}
#endif

View File

@@ -0,0 +1,71 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
// dynarray.overview
// const_reference at(size_type n) const;
// reference at(size_type n);
#include <__config>
#if _LIBCPP_STD_VER > 11
#include <experimental/dynarray>
#include <cassert>
#include <algorithm>
#include <complex>
#include <string>
using std::experimental::dynarray;
template <class T>
void dyn_test_const ( const dynarray<T> &dyn, const std::initializer_list<T> &vals ) {
const T *data = dyn.data ();
auto it = vals.begin ();
for ( size_t i = 0; i < dyn.size(); ++i, ++it ) {
assert ( data + i == &dyn[i]);
assert ( *it == dyn[i]);
}
}
template <class T>
void dyn_test ( dynarray<T> &dyn, const std::initializer_list<T> &vals ) {
T *data = dyn.data ();
auto it = vals.begin ();
for ( size_t i = 0; i < dyn.size(); ++i, ++it ) {
assert ( data + i == &dyn[i]);
assert ( *it == dyn[i]);
}
}
template <class T>
void test ( std::initializer_list<T> vals ) {
typedef dynarray<T> dynA;
dynA d1 ( vals );
dyn_test ( d1, vals );
dyn_test_const ( d1, vals );
}
int main()
{
test ( { 1, 1, 2, 3, 5, 8 } );
test ( { 1., 1., 2., 3., 5., 8. } );
test ( { std::string("1"), std::string("1"), std::string("2"), std::string("3"),
std::string("5"), std::string("8")} );
test<int> ( {} );
test<std::complex<double>> ( {} );
test<std::string> ( {} );
}
#else
int main() {}
#endif