fe413112f8
2001-08-06 Phil Edwards <pme@sources.redhat.com> * acinclude.m4 (GLIBCPP_CONFIGURE_TESTSUITE): New macro, calls... (GLIBCPP_CHECK_SETRLIMIT): ...this new macro, which also uses... (GLIBCPP_CHECK_SETRLIMIT_ancilliary): ...this new macro. * configure.in (AM_CONFIG_HEADER): Also generate testsuite_hooks.h. Call GLIBCPP_CONFIGURE_TESTSUITE. * aclocal.m4: Regenerate. * config.h.in: Regenerate. * configure: Regenerate. * testsuite/lib/libstdc++-v3-dg.exp: Download new header instead of old header. * testsuite_flags.in: Add build dir's testsuite to INCLUDES. * testsuite/debug_assert.h: Removed; contents merged into... * testsuite/testsuite_hooks.h.in: ...here. New file. * testsuite/17_intro/header_ciso646.cc: No longer include debug_assert.h, include testsuite_hooks.h instead. * testsuite/17_intro/header_fstream.cc: Likewise. * testsuite/17_intro/header_iomanip.cc: Likewise. * testsuite/17_intro/header_ios.cc: Likewise. * testsuite/17_intro/header_iosfwd.cc: Likewise. * testsuite/17_intro/header_iostream.cc: Likewise. * testsuite/17_intro/header_istream.cc: Likewise. * testsuite/17_intro/header_ostream.cc: Likewise. * testsuite/17_intro/header_sstream.cc: Likewise. * testsuite/17_intro/header_streambuf.cc: Likewise. * testsuite/18_support/numeric_limits.cc: Likewise. * testsuite/19_diagnostics/stdexceptions.cc: Likewise. * testsuite/20_util/allocator_members.cc: Likewise. * testsuite/20_util/auto_ptr.cc: Likewise. * testsuite/20_util/pairs.cc: Likewise. * testsuite/21_strings/append.cc: Likewise. * testsuite/21_strings/capacity.cc: Likewise. * testsuite/21_strings/char_traits_requirements.cc: Likewise. * testsuite/21_strings/compare.cc: Likewise. * testsuite/21_strings/ctor_copy_dtor.cc: Likewise. Also set up call to (disabled) __set_testsuite_memlimit() wrapper. * testsuite/21_strings/element_access.cc: Likewise. * testsuite/21_strings/find.cc: Likewise. * testsuite/21_strings/insert.cc: Likewise. Also set up call to (disabled) __set_testsuite_memlimit() wrapper. * testsuite/21_strings/inserters_extractors.cc: Likewise. * testsuite/21_strings/invariants.cc: Likewise. * testsuite/21_strings/nonmember.cc: Likewise. * testsuite/21_strings/operations.cc: Likewise. * testsuite/21_strings/replace.cc: Likewise. * testsuite/21_strings/rfind.cc: Likewise. * testsuite/21_strings/substr.cc: Likewise. * testsuite/22_locale/codecvt_char_char.cc: Likewise. * testsuite/22_locale/codecvt_unicode_char.cc: Likewise. * testsuite/22_locale/codecvt_unicode_wchar_t.cc: Likewise. * testsuite/22_locale/codecvt_wchar_t_char.cc: Likewise. * testsuite/22_locale/ctor_copy_dtor.cc: Likewise. * testsuite/22_locale/ctype_char_members.cc: Likewise. * testsuite/22_locale/ctype_wchar_t_members.cc: Likewise. * testsuite/22_locale/facet.cc: Likewise. * testsuite/22_locale/global_templates.cc: Likewise. * testsuite/22_locale/members.cc: Likewise. * testsuite/22_locale/numpunct_byname.cc: Likewise. * testsuite/22_locale/numpunct_char_members.cc: Likewise. * testsuite/22_locale/operators.cc: Likewise. * testsuite/22_locale/static_members.cc: Likewise. * testsuite/23_containers/bitset_ctor.cc: Likewise. * testsuite/23_containers/bitset_members.cc: Likewise. * testsuite/23_containers/bitset_shift.cc: Likewise. * testsuite/23_containers/vector_capacity.cc: Likewise. * testsuite/23_containers/vector_ctor.cc: Likewise. * testsuite/23_containers/vector_element_access.cc: Likewise. * testsuite/23_containers/vector_modifiers.cc: Likewise. * testsuite/24_iterators/istreambuf_iterator.cc: Likewise. * testsuite/24_iterators/iterator.cc: Likewise. * testsuite/24_iterators/ostreambuf_iterator.cc: Likewise. * testsuite/25_algorithms/binary_search.cc: Likewise. * testsuite/25_algorithms/copy.cc: Likewise. * testsuite/25_algorithms/heap.cc: Likewise. * testsuite/25_algorithms/lower_bound.cc: Likewise. * testsuite/25_algorithms/min_max.cc: Likewise. * testsuite/25_algorithms/partition.cc: Likewise. * testsuite/25_algorithms/rotate.cc: Likewise. * testsuite/25_algorithms/sort.cc: Likewise. * testsuite/26_numerics/c_math.cc: Likewise. * testsuite/26_numerics/complex_inserters_extractors.cc: Likewise. * testsuite/26_numerics/complex_value.cc: Likewise. * testsuite/27_io/filebuf.cc: Likewise. * testsuite/27_io/filebuf_members.cc: Likewise. * testsuite/27_io/filebuf_virtuals.cc: Likewise. * testsuite/27_io/fpos.cc: Likewise. * testsuite/27_io/fstream_members.cc: Likewise. * testsuite/27_io/ifstream_members.cc: Likewise. * testsuite/27_io/ios_base_callbacks.cc: Likewise. * testsuite/27_io/ios_base_members_static.cc: Likewise. * testsuite/27_io/ios_base_storage.cc: Likewise. * testsuite/27_io/ios_ctor.cc: Likewise. * testsuite/27_io/ios_init.cc: Likewise. * testsuite/27_io/ios_manip_basefield.cc: Likewise. * testsuite/27_io/ios_manip_fmtflags.cc: Likewise. * testsuite/27_io/ios_members.cc: Likewise. * testsuite/27_io/istream_extractor_arith.cc: Likewise. * testsuite/27_io/istream_extractor_char.cc: Likewise. * testsuite/27_io/istream_extractor_other.cc: Likewise. * testsuite/27_io/istream_manip.cc: Likewise. * testsuite/27_io/istream_seeks.cc: Likewise. * testsuite/27_io/istream_sentry.cc: Likewise. * testsuite/27_io/istream_unformatted.cc: Likewise. * testsuite/27_io/istringstream_members.cc: Likewise. * testsuite/27_io/narrow_stream_objects.cc: Likewise. * testsuite/27_io/ofstream_members.cc: Likewise. * testsuite/27_io/ostream_inserter_arith.cc: Likewise. * testsuite/27_io/ostream_inserter_char.cc: Likewise. * testsuite/27_io/ostream_inserter_other.cc: Likewise. * testsuite/27_io/ostream_manip.cc: Likewise. * testsuite/27_io/ostream_seeks.cc: Likewise. * testsuite/27_io/ostream_unformatted.cc: Likewise. * testsuite/27_io/ostringstream_members.cc: Likewise. * testsuite/27_io/streambuf.cc: Likewise. * testsuite/27_io/stringbuf.cc: Likewise. * testsuite/27_io/stringbuf_virtuals.cc: Likewise. * testsuite/27_io/stringstream.cc: Likewise. * testsuite/27_io/stringstream_members.cc: Likewise. * testsuite/27_io/wide_stream_objects.cc: Likewise. From-SVN: r44679
184 lines
4.6 KiB
C++
184 lines
4.6 KiB
C++
// Copyright (C) 2001 Free Software Foundation, Inc.
|
|
//
|
|
// This file is part of the GNU ISO C++ Library. This library is free
|
|
// software; you can redistribute it and/or modify it under the
|
|
// terms of the GNU General Public License as published by the
|
|
// Free Software Foundation; either version 2, or (at your option)
|
|
// any later version.
|
|
|
|
// This library is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU General Public License for more details.
|
|
|
|
// You should have received a copy of the GNU General Public License along
|
|
// with this library; see the file COPYING. If not, write to the Free
|
|
// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
|
// USA.
|
|
|
|
// 25.3.3 [lib.alg.binary.search] Binary search algorithms.
|
|
|
|
#include <algorithm>
|
|
#include <testsuite_hooks.h>
|
|
|
|
bool test = true;
|
|
|
|
const int A[] = {1, 2, 3, 3, 3, 5, 8};
|
|
const int C[] = {8, 5, 3, 3, 3, 2, 1};
|
|
const int N = sizeof(A) / sizeof(int);
|
|
|
|
// A comparison, equalivalent to std::greater<int> without the
|
|
// dependency on <functional>.
|
|
|
|
struct gt
|
|
{
|
|
bool
|
|
operator()(const int& x, const int& y) const
|
|
{ return x > y; }
|
|
};
|
|
|
|
// Each test performs general-case, bookend, not-found condition,
|
|
// and predicate functional checks.
|
|
|
|
// 25.3.3.1 lower_bound, with and without comparison predicate
|
|
void
|
|
test01()
|
|
{
|
|
using std::lower_bound;
|
|
|
|
const int first = A[0];
|
|
const int last = A[N - 1];
|
|
|
|
const int* p = lower_bound(A, A + N, 3);
|
|
VERIFY(p == A + 2);
|
|
|
|
const int* q = lower_bound(A, A + N, first);
|
|
VERIFY(q == A + 0);
|
|
|
|
const int* r = lower_bound(A, A + N, last);
|
|
VERIFY(r == A + N - 1);
|
|
|
|
const int* s = lower_bound(A, A + N, 4);
|
|
VERIFY(s == A + 5);
|
|
|
|
const int* t = lower_bound(C, C + N, 3, gt());
|
|
VERIFY(t == C + 2);
|
|
|
|
const int* u = lower_bound(C, C + N, first, gt());
|
|
VERIFY(u == C + N - 1);
|
|
|
|
const int* v = lower_bound(C, C + N, last, gt());
|
|
VERIFY(v == C + 0);
|
|
|
|
const int* w = lower_bound(C, C + N, 4, gt());
|
|
VERIFY(w == C + 2);
|
|
}
|
|
|
|
// 25.3.3.2 upper_bound, with and without comparison predicate
|
|
void
|
|
test02()
|
|
{
|
|
using std::upper_bound;
|
|
|
|
const int first = A[0];
|
|
const int last = A[N - 1];
|
|
|
|
const int* p = upper_bound(A, A + N, 3);
|
|
VERIFY(p == A + 5);
|
|
|
|
const int* q = upper_bound(A, A + N, first);
|
|
VERIFY(q == A + 1);
|
|
|
|
const int* r = upper_bound(A, A + N, last);
|
|
VERIFY(r == A + N);
|
|
|
|
const int* s = upper_bound(A, A + N, 4);
|
|
VERIFY(s == A + 5);
|
|
|
|
const int* t = upper_bound(C, C + N, 3, gt());
|
|
VERIFY(t == C + 5);
|
|
|
|
const int* u = upper_bound(C, C + N, first, gt());
|
|
VERIFY(u == C + N);
|
|
|
|
const int* v = upper_bound(C, C + N, last, gt());
|
|
VERIFY(v == C + 1);
|
|
|
|
const int* w = upper_bound(C, C + N, 4, gt());
|
|
VERIFY(w == C + 2);
|
|
}
|
|
|
|
// 25.3.3.3 equal_range, with and without comparison predicate
|
|
void
|
|
test03()
|
|
{
|
|
using std::equal_range;
|
|
typedef std::pair<const int*, const int*> Ipair;
|
|
|
|
const int first = A[0];
|
|
const int last = A[N - 1];
|
|
|
|
Ipair p = equal_range(A, A + N, 3);
|
|
VERIFY(p.first == A + 2);
|
|
VERIFY(p.second == A + 5);
|
|
|
|
Ipair q = equal_range(A, A + N, first);
|
|
VERIFY(q.first == A + 0);
|
|
VERIFY(q.second == A + 1);
|
|
|
|
Ipair r = equal_range(A, A + N, last);
|
|
VERIFY(r.first == A + N - 1);
|
|
VERIFY(r.second == A + N);
|
|
|
|
Ipair s = equal_range(A, A + N, 4);
|
|
VERIFY(s.first == A + 5);
|
|
VERIFY(s.second == A + 5);
|
|
|
|
Ipair t = equal_range(C, C + N, 3, gt());
|
|
VERIFY(t.first == C + 2);
|
|
VERIFY(t.second == C + 5);
|
|
|
|
Ipair u = equal_range(C, C + N, first, gt());
|
|
VERIFY(u.first == C + N - 1);
|
|
VERIFY(u.second == C + N);
|
|
|
|
Ipair v = equal_range(C, C + N, last, gt());
|
|
VERIFY(v.first == C + 0);
|
|
VERIFY(v.second == C + 1);
|
|
|
|
Ipair w = equal_range(C, C + N, 4, gt());
|
|
VERIFY(w.first == C + 2);
|
|
VERIFY(w.second == C + 2);
|
|
}
|
|
|
|
// 25.3.3.4 binary_search, with and without comparison predicate
|
|
void
|
|
test04()
|
|
{
|
|
using std::binary_search;
|
|
|
|
const int first = A[0];
|
|
const int last = A[N - 1];
|
|
|
|
VERIFY(binary_search(A, A + N, 5));
|
|
VERIFY(binary_search(A, A + N, first));
|
|
VERIFY(binary_search(A, A + N, last));
|
|
VERIFY(!binary_search(A, A + N, 4));
|
|
|
|
VERIFY(binary_search(C, C + N, 5, gt()));
|
|
VERIFY(binary_search(C, C + N, first, gt()));
|
|
VERIFY(binary_search(C, C + N, last, gt()));
|
|
VERIFY(!binary_search(C, C + N, 4, gt()));
|
|
}
|
|
|
|
int
|
|
main(int argc, char* argv[])
|
|
{
|
|
test01();
|
|
test02();
|
|
test03();
|
|
test04();
|
|
|
|
return !test;
|
|
}
|