moveable.cc: Fix and extend.

2007-10-11  Paolo Carlini  <pcarlini@suse.de>

	* testsuite/25_algorithms/heap/moveable.cc: Fix and extend.

From-SVN: r129231
This commit is contained in:
Paolo Carlini 2007-10-11 10:04:55 +00:00 committed by Paolo Carlini
parent 1ef40d6b95
commit a6bda7d08b
2 changed files with 59 additions and 33 deletions

View File

@ -1,3 +1,7 @@
2007-10-11 Paolo Carlini <pcarlini@suse.de>
* testsuite/25_algorithms/heap/moveable.cc: Fix and extend.
2007-10-11 Danny Smith <dannysmith@users.sourceforge.net> 2007-10-11 Danny Smith <dannysmith@users.sourceforge.net>
PR libstdc++/33578 PR libstdc++/33578

View File

@ -34,82 +34,104 @@ using __gnu_test::random_access_iterator_wrapper;
using __gnu_test::rvalstruct; using __gnu_test::rvalstruct;
typedef test_container<rvalstruct, random_access_iterator_wrapper> container; typedef test_container<rvalstruct, random_access_iterator_wrapper> container;
typedef test_container<int, random_access_iterator_wrapper> container_ref;
bool test __attribute__((unused)) = true; bool test __attribute__((unused)) = true;
void void
check_make(int* array, int length) check_make(int* array, int length)
{ {
rvalstruct makeheap[9]; rvalstruct makeheap[9];
int makeheap_ref[9];
std::copy(array, array + length, makeheap); std::copy(array, array + length, makeheap);
std::copy(array, array + length, makeheap_ref);
container makecon(makeheap, makeheap + length); container makecon(makeheap, makeheap + length);
container_ref makecon_ref(makeheap_ref, makeheap_ref + length);
std::make_heap(makecon.begin(), makecon.end()); std::make_heap(makecon.begin(), makecon.end());
VERIFY(std::__is_heap(makecon.begin(), makecon.end())); std::make_heap(makecon_ref.begin(), makecon_ref.end());
for(int z = 0; z < length; ++z) for (int z = 0; z < length; ++z)
VERIFY(makeheap[z].valid); VERIFY( makeheap[z] == makeheap_ref[z] );
VERIFY( std::__is_heap(makecon.begin(), makecon.end()) );
for (int z = 0; z < length; ++z)
VERIFY( makeheap[z].valid );
} }
void void
check_pop(int* array, int length) check_pop(int* array, int length)
{ {
rvalstruct popheap[9]; rvalstruct popheap[9];
std::copy(array, array + length, popheap); int popheap_ref[9];
std::copy(array, array + length, popheap);
std::copy(array, array + length, popheap_ref);
container popcon(popheap, popheap + length); container popcon(popheap, popheap + length);
container_ref popcon_ref(popheap_ref, popheap_ref + length);
std::pop_heap(popcon.begin(), popcon.end()); std::pop_heap(popcon.begin(), popcon.end());
VERIFY(std::__is_heap(popheap, popheap + length - 1)); std::pop_heap(popcon_ref.begin(), popcon_ref.end());
for(int z = 0; z < length; ++z) for (int z = 0; z < length; ++z)
VERIFY(popheap[z].val <= popheap[length-1].val && popheap[z].valid); VERIFY( popheap[z] == popheap_ref[z] );
VERIFY( (std::__is_heap(popheap, popheap + length - 1)) );
for (int z = 0; z < length; ++z)
VERIFY( popheap[z].val <= popheap[length-1].val && popheap[z].valid );
} }
void void
check_sort(int* array, int length) check_sort(int* array, int length)
{ {
rvalstruct sortheap[9]; rvalstruct sortheap[9];
std::copy(array, array + length, sortheap); int sortheap_ref[9];
std::copy(array, array + length, sortheap);
std::copy(array, array + length, sortheap_ref);
container sortcon(sortheap, sortheap + length); container sortcon(sortheap, sortheap + length);
container_ref sortcon_ref(sortheap_ref, sortheap_ref + length);
std::sort_heap(sortcon.begin(), sortcon.end()); std::sort_heap(sortcon.begin(), sortcon.end());
for(int z = 0; z < length - 1; ++z) std::sort_heap(sortcon_ref.begin(), sortcon_ref.end());
VERIFY(sortheap[z].val <= sortheap[z + 1].val && sortheap[z].valid); for (int z = 0; z < length; ++z)
VERIFY(sortheap[length - 1].valid); VERIFY( sortheap[z] == sortheap_ref[z] );
for (int z = 0; z < length - 1; ++z)
VERIFY( sortheap[z].val <= sortheap[z + 1].val && sortheap[z].valid );
VERIFY( sortheap[length - 1].valid );
} }
void void
check_push(int* array, int pushval, int length) check_push(int* array, int pushval, int length)
{ {
rvalstruct pushheap[10]; rvalstruct pushheap[10];
int pushheap_ref[10];
std::copy(array, array + length, pushheap); std::copy(array, array + length, pushheap);
std::copy(array, array + length, pushheap_ref);
pushheap[length] = pushval; pushheap[length] = pushval;
container pushcon(pushheap, pushheap + length); pushheap_ref[length] = pushval;
container pushcon(pushheap, pushheap + length + 1);
container_ref pushcon_ref(pushheap_ref, pushheap_ref + length + 1);
std::push_heap(pushcon.begin(), pushcon.end()); std::push_heap(pushcon.begin(), pushcon.end());
VERIFY(std::__is_heap(pushheap, pushheap + length)); std::push_heap(pushcon_ref.begin(), pushcon_ref.end());
for(int z = 0; z < length ; ++z) for (int z = 0; z < length + 1; ++z)
VERIFY(pushheap[z].valid); VERIFY( pushheap[z] == pushheap_ref[z] );
VERIFY( std::__is_heap(pushheap, pushheap + length + 1) );
for (int z = 0; z < length + 1; ++z)
VERIFY( pushheap[z].valid );
} }
void void
test01() test01()
{ {
int array[9]; int array[9];
for(int i = 1; i < 9; ++i) for (int i = 1; i < 9; ++i)
{
for(int z = 0; z < i; ++z)
array[i] = i;
while(std::next_permutation(array, array + i))
{ {
check_make(array, i); for(int z = 0; z < i; ++z)
if(std::__is_heap(array, array + i)) array[z] = z;
{ while (std::next_permutation(array, array + i))
check_pop(array, i); {
check_sort(array, i); check_make(array, i);
for(int pushval = -1; pushval <= i; ++pushval) if (std::__is_heap(array, array + i))
{ {
check_push(array, pushval, i); check_pop(array, i);
} check_sort(array, i);
} for (int pushval = -1; pushval <= i; ++pushval)
check_push(array, pushval, i);
}
}
} }
}
} }
int int