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.
//
//===----------------------------------------------------------------------===//
// <algorithm>
// template <class InputIterator, class Predicate>
// bool
// is_partitioned(InputIterator first, InputIterator last, Predicate pred);
#include <algorithm>
#include <cassert>
#include "test_iterators.h"
struct is_odd
{
bool operator()(const int& i) const {return i & 1;}
};
int main()
{
{
const int ia[] = {1, 2, 3, 4, 5, 6};
assert(!std::is_partitioned(input_iterator<const int*>(std::begin(ia)),
input_iterator<const int*>(std::end(ia)),
is_odd()));
}
{
const int ia[] = {1, 3, 5, 2, 4, 6};
assert( std::is_partitioned(input_iterator<const int*>(std::begin(ia)),
input_iterator<const int*>(std::end(ia)),
is_odd()));
}
{
const int ia[] = {2, 4, 6, 1, 3, 5};
assert(!std::is_partitioned(input_iterator<const int*>(std::begin(ia)),
input_iterator<const int*>(std::end(ia)),
is_odd()));
}
{
const int ia[] = {1, 3, 5, 2, 4, 6, 7};
assert(!std::is_partitioned(input_iterator<const int*>(std::begin(ia)),
input_iterator<const int*>(std::end(ia)),
is_odd()));
}
{
const int ia[] = {1, 3, 5, 2, 4, 6, 7};
assert( std::is_partitioned(input_iterator<const int*>(std::begin(ia)),
input_iterator<const int*>(std::begin(ia)),
is_odd()));
}
}

View File

@@ -0,0 +1,104 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
// <algorithm>
// template<BidirectionalIterator Iter, Predicate<auto, Iter::value_type> Pred>
// requires ShuffleIterator<Iter>
// && CopyConstructible<Pred>
// Iter
// partition(Iter first, Iter last, Pred pred);
#include <algorithm>
#include <cassert>
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
#include <memory>
#endif
#include "test_iterators.h"
struct is_odd
{
bool operator()(const int& i) const {return i & 1;}
};
template <class Iter>
void
test()
{
// check mixed
int ia[] = {1, 2, 3, 4, 5, 6, 7, 8 ,9};
const unsigned sa = sizeof(ia)/sizeof(ia[0]);
Iter r = std::partition(Iter(ia), Iter(ia + sa), is_odd());
assert(base(r) == ia + 5);
for (int* i = ia; i < base(r); ++i)
assert(is_odd()(*i));
for (int* i = base(r); i < ia+sa; ++i)
assert(!is_odd()(*i));
// check empty
r = std::partition(Iter(ia), Iter(ia), is_odd());
assert(base(r) == ia);
// check all false
for (unsigned i = 0; i < sa; ++i)
ia[i] = 2*i;
r = std::partition(Iter(ia), Iter(ia+sa), is_odd());
assert(base(r) == ia);
// check all true
for (unsigned i = 0; i < sa; ++i)
ia[i] = 2*i+1;
r = std::partition(Iter(ia), Iter(ia+sa), is_odd());
assert(base(r) == ia+sa);
// check all true but last
for (unsigned i = 0; i < sa; ++i)
ia[i] = 2*i+1;
ia[sa-1] = 10;
r = std::partition(Iter(ia), Iter(ia+sa), is_odd());
assert(base(r) == ia+sa-1);
for (int* i = ia; i < base(r); ++i)
assert(is_odd()(*i));
for (int* i = base(r); i < ia+sa; ++i)
assert(!is_odd()(*i));
// check all true but first
for (unsigned i = 0; i < sa; ++i)
ia[i] = 2*i+1;
ia[0] = 10;
r = std::partition(Iter(ia), Iter(ia+sa), is_odd());
assert(base(r) == ia+sa-1);
for (int* i = ia; i < base(r); ++i)
assert(is_odd()(*i));
for (int* i = base(r); i < ia+sa; ++i)
assert(!is_odd()(*i));
// check all false but last
for (unsigned i = 0; i < sa; ++i)
ia[i] = 2*i;
ia[sa-1] = 11;
r = std::partition(Iter(ia), Iter(ia+sa), is_odd());
assert(base(r) == ia+1);
for (int* i = ia; i < base(r); ++i)
assert(is_odd()(*i));
for (int* i = base(r); i < ia+sa; ++i)
assert(!is_odd()(*i));
// check all false but first
for (unsigned i = 0; i < sa; ++i)
ia[i] = 2*i;
ia[0] = 11;
r = std::partition(Iter(ia), Iter(ia+sa), is_odd());
assert(base(r) == ia+1);
for (int* i = ia; i < base(r); ++i)
assert(is_odd()(*i));
for (int* i = base(r); i < ia+sa; ++i)
assert(!is_odd()(*i));
}
int main()
{
test<bidirectional_iterator<int*> >();
test<random_access_iterator<int*> >();
test<int*>();
}

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.
//
//===----------------------------------------------------------------------===//
// <algorithm>
// template <class InputIterator, class OutputIterator1,
// class OutputIterator2, class Predicate>
// pair<OutputIterator1, OutputIterator2>
// partition_copy(InputIterator first, InputIterator last,
// OutputIterator1 out_true, OutputIterator2 out_false,
// Predicate pred);
#include <algorithm>
#include <cassert>
#include "test_iterators.h"
struct is_odd
{
bool operator()(const int& i) const {return i & 1;}
};
int main()
{
{
const int ia[] = {1, 2, 3, 4, 6, 8, 5, 7};
int r1[10] = {0};
int r2[10] = {0};
typedef std::pair<output_iterator<int*>, int*> P;
P p = std::partition_copy(input_iterator<const int*>(std::begin(ia)),
input_iterator<const int*>(std::end(ia)),
output_iterator<int*>(r1), r2, is_odd());
assert(p.first.base() == r1 + 4);
assert(r1[0] == 1);
assert(r1[1] == 3);
assert(r1[2] == 5);
assert(r1[3] == 7);
assert(p.second == r2 + 4);
assert(r2[0] == 2);
assert(r2[1] == 4);
assert(r2[2] == 6);
assert(r2[3] == 8);
}
}

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.
//
//===----------------------------------------------------------------------===//
// <algorithm>
// template<class ForwardIterator, class Predicate>
// ForwardIterator
// partition_point(ForwardIterator first, ForwardIterator last, Predicate pred);
#include <algorithm>
#include <cassert>
#include "test_iterators.h"
struct is_odd
{
bool operator()(const int& i) const {return i & 1;}
};
int main()
{
{
const int ia[] = {2, 4, 6, 8, 10};
assert(std::partition_point(forward_iterator<const int*>(std::begin(ia)),
forward_iterator<const int*>(std::end(ia)),
is_odd()) == forward_iterator<const int*>(ia));
}
{
const int ia[] = {1, 2, 4, 6, 8};
assert(std::partition_point(forward_iterator<const int*>(std::begin(ia)),
forward_iterator<const int*>(std::end(ia)),
is_odd()) == forward_iterator<const int*>(ia + 1));
}
{
const int ia[] = {1, 3, 2, 4, 6};
assert(std::partition_point(forward_iterator<const int*>(std::begin(ia)),
forward_iterator<const int*>(std::end(ia)),
is_odd()) == forward_iterator<const int*>(ia + 2));
}
{
const int ia[] = {1, 3, 5, 2, 4, 6};
assert(std::partition_point(forward_iterator<const int*>(std::begin(ia)),
forward_iterator<const int*>(std::end(ia)),
is_odd()) == forward_iterator<const int*>(ia + 3));
}
{
const int ia[] = {1, 3, 5, 7, 2, 4};
assert(std::partition_point(forward_iterator<const int*>(std::begin(ia)),
forward_iterator<const int*>(std::end(ia)),
is_odd()) == forward_iterator<const int*>(ia + 4));
}
{
const int ia[] = {1, 3, 5, 7, 9, 2};
assert(std::partition_point(forward_iterator<const int*>(std::begin(ia)),
forward_iterator<const int*>(std::end(ia)),
is_odd()) == forward_iterator<const int*>(ia + 5));
}
{
const int ia[] = {1, 3, 5, 7, 9, 11};
assert(std::partition_point(forward_iterator<const int*>(std::begin(ia)),
forward_iterator<const int*>(std::end(ia)),
is_odd()) == forward_iterator<const int*>(ia + 6));
}
{
const int ia[] = {1, 3, 5, 2, 4, 6, 7};
assert(std::partition_point(forward_iterator<const int*>(std::begin(ia)),
forward_iterator<const int*>(std::begin(ia)),
is_odd()) == forward_iterator<const int*>(ia));
}
}

View File

@@ -0,0 +1,314 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
// <algorithm>
// template<BidirectionalIterator Iter, Predicate<auto, Iter::value_type> Pred>
// requires ShuffleIterator<Iter>
// && CopyConstructible<Pred>
// Iter
// stable_partition(Iter first, Iter last, Pred pred);
#include <algorithm>
#include <cassert>
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
#include <memory>
#endif
#include "test_iterators.h"
struct is_odd
{
bool operator()(const int& i) const {return i & 1;}
};
struct odd_first
{
bool operator()(const std::pair<int,int>& p) const
{return p.first & 1;}
};
template <class Iter>
void
test()
{
{ // check mixed
typedef std::pair<int,int> P;
P array[] =
{
P(0, 1),
P(0, 2),
P(1, 1),
P(1, 2),
P(2, 1),
P(2, 2),
P(3, 1),
P(3, 2),
P(4, 1),
P(4, 2)
};
const unsigned size = sizeof(array)/sizeof(array[0]);
Iter r = std::stable_partition(Iter(array), Iter(array+size), odd_first());
assert(base(r) == array + 4);
assert(array[0] == P(1, 1));
assert(array[1] == P(1, 2));
assert(array[2] == P(3, 1));
assert(array[3] == P(3, 2));
assert(array[4] == P(0, 1));
assert(array[5] == P(0, 2));
assert(array[6] == P(2, 1));
assert(array[7] == P(2, 2));
assert(array[8] == P(4, 1));
assert(array[9] == P(4, 2));
}
{
typedef std::pair<int,int> P;
P array[] =
{
P(0, 1),
P(0, 2),
P(1, 1),
P(1, 2),
P(2, 1),
P(2, 2),
P(3, 1),
P(3, 2),
P(4, 1),
P(4, 2)
};
const unsigned size = sizeof(array)/sizeof(array[0]);
Iter r = std::stable_partition(Iter(array), Iter(array+size), odd_first());
assert(base(r) == array + 4);
assert(array[0] == P(1, 1));
assert(array[1] == P(1, 2));
assert(array[2] == P(3, 1));
assert(array[3] == P(3, 2));
assert(array[4] == P(0, 1));
assert(array[5] == P(0, 2));
assert(array[6] == P(2, 1));
assert(array[7] == P(2, 2));
assert(array[8] == P(4, 1));
assert(array[9] == P(4, 2));
// check empty
r = std::stable_partition(Iter(array), Iter(array), odd_first());
assert(base(r) == array);
// check one true
r = std::stable_partition(Iter(array), Iter(array+1), odd_first());
assert(base(r) == array+1);
assert(array[0] == P(1, 1));
// check one false
r = std::stable_partition(Iter(array+4), Iter(array+5), odd_first());
assert(base(r) == array+4);
assert(array[4] == P(0, 1));
}
{ // check all false
typedef std::pair<int,int> P;
P array[] =
{
P(0, 1),
P(0, 2),
P(2, 1),
P(2, 2),
P(4, 1),
P(4, 2),
P(6, 1),
P(6, 2),
P(8, 1),
P(8, 2)
};
const unsigned size = sizeof(array)/sizeof(array[0]);
Iter r = std::stable_partition(Iter(array), Iter(array+size), odd_first());
assert(base(r) == array);
assert(array[0] == P(0, 1));
assert(array[1] == P(0, 2));
assert(array[2] == P(2, 1));
assert(array[3] == P(2, 2));
assert(array[4] == P(4, 1));
assert(array[5] == P(4, 2));
assert(array[6] == P(6, 1));
assert(array[7] == P(6, 2));
assert(array[8] == P(8, 1));
assert(array[9] == P(8, 2));
}
{ // check all true
typedef std::pair<int,int> P;
P array[] =
{
P(1, 1),
P(1, 2),
P(3, 1),
P(3, 2),
P(5, 1),
P(5, 2),
P(7, 1),
P(7, 2),
P(9, 1),
P(9, 2)
};
const unsigned size = sizeof(array)/sizeof(array[0]);
Iter r = std::stable_partition(Iter(array), Iter(array+size), odd_first());
assert(base(r) == array + size);
assert(array[0] == P(1, 1));
assert(array[1] == P(1, 2));
assert(array[2] == P(3, 1));
assert(array[3] == P(3, 2));
assert(array[4] == P(5, 1));
assert(array[5] == P(5, 2));
assert(array[6] == P(7, 1));
assert(array[7] == P(7, 2));
assert(array[8] == P(9, 1));
assert(array[9] == P(9, 2));
}
{ // check all false but first true
typedef std::pair<int,int> P;
P array[] =
{
P(1, 1),
P(0, 2),
P(2, 1),
P(2, 2),
P(4, 1),
P(4, 2),
P(6, 1),
P(6, 2),
P(8, 1),
P(8, 2)
};
const unsigned size = sizeof(array)/sizeof(array[0]);
Iter r = std::stable_partition(Iter(array), Iter(array+size), odd_first());
assert(base(r) == array + 1);
assert(array[0] == P(1, 1));
assert(array[1] == P(0, 2));
assert(array[2] == P(2, 1));
assert(array[3] == P(2, 2));
assert(array[4] == P(4, 1));
assert(array[5] == P(4, 2));
assert(array[6] == P(6, 1));
assert(array[7] == P(6, 2));
assert(array[8] == P(8, 1));
assert(array[9] == P(8, 2));
}
{ // check all false but last true
typedef std::pair<int,int> P;
P array[] =
{
P(0, 1),
P(0, 2),
P(2, 1),
P(2, 2),
P(4, 1),
P(4, 2),
P(6, 1),
P(6, 2),
P(8, 1),
P(1, 2)
};
const unsigned size = sizeof(array)/sizeof(array[0]);
Iter r = std::stable_partition(Iter(array), Iter(array+size), odd_first());
assert(base(r) == array + 1);
assert(array[0] == P(1, 2));
assert(array[1] == P(0, 1));
assert(array[2] == P(0, 2));
assert(array[3] == P(2, 1));
assert(array[4] == P(2, 2));
assert(array[5] == P(4, 1));
assert(array[6] == P(4, 2));
assert(array[7] == P(6, 1));
assert(array[8] == P(6, 2));
assert(array[9] == P(8, 1));
}
{ // check all true but first false
typedef std::pair<int,int> P;
P array[] =
{
P(0, 1),
P(1, 2),
P(3, 1),
P(3, 2),
P(5, 1),
P(5, 2),
P(7, 1),
P(7, 2),
P(9, 1),
P(9, 2)
};
const unsigned size = sizeof(array)/sizeof(array[0]);
Iter r = std::stable_partition(Iter(array), Iter(array+size), odd_first());
assert(base(r) == array + size-1);
assert(array[0] == P(1, 2));
assert(array[1] == P(3, 1));
assert(array[2] == P(3, 2));
assert(array[3] == P(5, 1));
assert(array[4] == P(5, 2));
assert(array[5] == P(7, 1));
assert(array[6] == P(7, 2));
assert(array[7] == P(9, 1));
assert(array[8] == P(9, 2));
assert(array[9] == P(0, 1));
}
{ // check all true but last false
typedef std::pair<int,int> P;
P array[] =
{
P(1, 1),
P(1, 2),
P(3, 1),
P(3, 2),
P(5, 1),
P(5, 2),
P(7, 1),
P(7, 2),
P(9, 1),
P(0, 2)
};
const unsigned size = sizeof(array)/sizeof(array[0]);
Iter r = std::stable_partition(Iter(array), Iter(array+size), odd_first());
assert(base(r) == array + size-1);
assert(array[0] == P(1, 1));
assert(array[1] == P(1, 2));
assert(array[2] == P(3, 1));
assert(array[3] == P(3, 2));
assert(array[4] == P(5, 1));
assert(array[5] == P(5, 2));
assert(array[6] == P(7, 1));
assert(array[7] == P(7, 2));
assert(array[8] == P(9, 1));
assert(array[9] == P(0, 2));
}
}
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
struct is_null
{
template <class P>
bool operator()(const P& p) {return p == 0;}
};
template <class Iter>
void
test1()
{
const unsigned size = 5;
std::unique_ptr<int> array[size];
Iter r = std::stable_partition(Iter(array), Iter(array+size), is_null());
}
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
int main()
{
test<bidirectional_iterator<std::pair<int,int>*> >();
test<random_access_iterator<std::pair<int,int>*> >();
test<std::pair<int,int>*>();
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
test1<bidirectional_iterator<std::unique_ptr<int>*> >();
#endif
}