]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
binary_search.cc: Move...
authorBenjamin Kosnik <bkoz@redhat.com>
Sun, 9 Sep 2007 18:56:00 +0000 (18:56 +0000)
committerBenjamin Kosnik <bkoz@gcc.gnu.org>
Sun, 9 Sep 2007 18:56:00 +0000 (18:56 +0000)
2007-09-09  Benjamin Kosnik  <bkoz@redhat.com>

* testsuite/25_algorithms/binary_search.cc: Move...
* testsuite/25_algorithms/binary_search/2.cc: ...here.

* testsuite/25_algorithms/sort.cc: Move...
* testsuite/25_algorithms/sort/1.cc: ...here.
* testsuite/25_algorithms/partial_sort_copy/2.cc: ...here.
* testsuite/25_algorithms/nth_element/3.cc: ...here.
* testsuite/25_algorithms/partial_sort/2.cc: ...here.
* testsuite/25_algorithms/stable_sort/2.cc: ...here.

* testsuite/25_algorithms/min_max.cc: Move...
* testsuite/25_algorithms/min/1.cc: ...here.
* testsuite/25_algorithms/min/2.cc: ...here.
* testsuite/25_algorithms/max/1.cc: ...here.
* testsuite/25_algorithms/max/2.cc: ...here.

From-SVN: r128303

libstdc++-v3/ChangeLog
libstdc++-v3/testsuite/25_algorithms/binary_search/2.cc [moved from libstdc++-v3/testsuite/25_algorithms/binary_search.cc with 99% similarity]
libstdc++-v3/testsuite/25_algorithms/max/1.cc [new file with mode: 0644]
libstdc++-v3/testsuite/25_algorithms/max/2.cc [new file with mode: 0644]
libstdc++-v3/testsuite/25_algorithms/min/1.cc [new file with mode: 0644]
libstdc++-v3/testsuite/25_algorithms/min/2.cc [moved from libstdc++-v3/testsuite/25_algorithms/min_max.cc with 58% similarity]
libstdc++-v3/testsuite/25_algorithms/nth_element/3.cc [new file with mode: 0644]
libstdc++-v3/testsuite/25_algorithms/partial_sort/2.cc [new file with mode: 0644]
libstdc++-v3/testsuite/25_algorithms/partial_sort_copy/2.cc [moved from libstdc++-v3/testsuite/25_algorithms/sort.cc with 54% similarity]
libstdc++-v3/testsuite/25_algorithms/sort/1.cc [new file with mode: 0644]
libstdc++-v3/testsuite/25_algorithms/stable_sort/2.cc [new file with mode: 0644]

index 3faf3ff83b0911a12fffa4a0676982b47bad981b..bbb848c05408f1992c4fe71240c832e23b86a418 100644 (file)
@@ -1,3 +1,21 @@
+2007-09-09  Benjamin Kosnik  <bkoz@redhat.com>
+       
+       * testsuite/25_algorithms/binary_search.cc: Move...
+       * testsuite/25_algorithms/binary_search/2.cc: ...here.
+
+       * testsuite/25_algorithms/sort.cc: Move...      
+       * testsuite/25_algorithms/sort/1.cc: ...here.
+       * testsuite/25_algorithms/partial_sort_copy/2.cc: ...here.
+       * testsuite/25_algorithms/nth_element/3.cc: ...here.
+       * testsuite/25_algorithms/partial_sort/2.cc: ...here.
+       * testsuite/25_algorithms/stable_sort/2.cc: ...here.
+
+       * testsuite/25_algorithms/min_max.cc: Move...
+       * testsuite/25_algorithms/min/1.cc: ...here.
+       * testsuite/25_algorithms/min/2.cc: ...here.
+       * testsuite/25_algorithms/max/1.cc: ...here.
+       * testsuite/25_algorithms/max/2.cc: ...here.
+
 2007-09-09  Joseph Myers  <joseph@codesourcery.com>
 
        * testsuite/lib/libstdc++.exp (v3-build-support): Specify output
similarity index 99%
rename from libstdc++-v3/testsuite/25_algorithms/binary_search.cc
rename to libstdc++-v3/testsuite/25_algorithms/binary_search/2.cc
index 5854f19506546b0e7c4a3c2a60791d4338681c81..66567f23afd89281df9323670f5c8891f2586bb8 100644 (file)
@@ -29,7 +29,6 @@ const int N = sizeof(A) / sizeof(int);
 
 // A comparison, equalivalent to std::greater<int> without the
 // dependency on <functional>.
-
 struct gt
 {
     bool
diff --git a/libstdc++-v3/testsuite/25_algorithms/max/1.cc b/libstdc++-v3/testsuite/25_algorithms/max/1.cc
new file mode 100644 (file)
index 0000000..78db439
--- /dev/null
@@ -0,0 +1,44 @@
+// 2000-03-29 sss/bkoz
+
+// Copyright (C) 2000, 2003, 2004, 2005 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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+#include <algorithm>
+#include <functional>
+#include <testsuite_hooks.h>
+
+void test01()
+{
+  bool test __attribute__((unused)) = true;
+
+  const int& x = std::max(1, 2);
+  const int& y = std::max(4, 3);
+  VERIFY( x == 2 );
+  VERIFY( y == 4 );
+
+  const int& xc = std::max(1, 2, std::greater<int>());
+  const int& yc = std::max(4, 3, std::greater<int>());
+  VERIFY( xc == 1 );
+  VERIFY( yc == 3 );
+}
+
+int main()
+{
+  test01();
+  return 0;
+}
diff --git a/libstdc++-v3/testsuite/25_algorithms/max/2.cc b/libstdc++-v3/testsuite/25_algorithms/max/2.cc
new file mode 100644 (file)
index 0000000..2be6b8f
--- /dev/null
@@ -0,0 +1,78 @@
+// 2000-03-29 sss/bkoz
+
+// Copyright (C) 2000, 2003, 2004, 2005 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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+#include <algorithm>
+#include <functional>
+#include <testsuite_hooks.h>
+
+template<typename T> 
+  struct A { static const T a; };
+
+template<typename T>
+const T A<T>::a = T(3);
+
+void test02()
+{
+  bool test __attribute__((unused)) = true;
+
+  VERIFY( 3 == std::max(A<int>::a, 2) );
+  VERIFY( 4 == std::max(A<int>::a, 4) );
+
+  VERIFY( 3u == std::max(A<unsigned int>::a, 2u) );
+  VERIFY( 4u == std::max(A<unsigned int>::a, 4u) );
+
+  VERIFY( 3l == std::max(A<long>::a, 2l) );
+  VERIFY( 4l == std::max(A<long>::a, 4l) );
+
+  VERIFY( 3ul == std::max(A<unsigned long>::a, 2ul) );
+  VERIFY( 4ul == std::max(A<unsigned long>::a, 4ul) );
+
+#ifdef _GLIBCXX_USE_LONG_LONG
+  VERIFY( 3ll == std::max(A<long long>::a, 2ll) );
+  VERIFY( 4ll == std::max(A<long long>::a, 4ll) );
+
+  VERIFY( 3ull == std::max(A<unsigned long long>::a, 2ull) );
+  VERIFY( 4ull == std::max(A<unsigned long long>::a, 4ull) );
+#endif
+
+  VERIFY( short(3) == std::max(A<short>::a, short(2)) );
+  VERIFY( short(4) == std::max(A<short>::a, short(4)) );
+
+  VERIFY( (unsigned short)3 == std::max(A<unsigned short>::a, (unsigned short)2) );
+  VERIFY( (unsigned short)4 == std::max(A<unsigned short>::a, (unsigned short)4) );
+
+  VERIFY( (char)3 == std::max(A<char>::a, (char)2) );
+  VERIFY( (char)4 == std::max(A<char>::a, (char)4) );
+
+  VERIFY( (signed char)3 == std::max(A<signed char>::a, (signed char)2) );
+  VERIFY( (signed char)4 == std::max(A<signed char>::a, (signed char)4) );
+
+  VERIFY( (unsigned char)3 == std::max(A<unsigned char>::a, (unsigned char)2) );
+  VERIFY( (unsigned char)4 == std::max(A<unsigned char>::a, (unsigned char)4) );
+
+  VERIFY( (wchar_t)3 == std::max(A<wchar_t>::a, (wchar_t)2) );
+  VERIFY( (wchar_t)4 == std::max(A<wchar_t>::a, (wchar_t)4) );
+}
+
+int main()
+{
+  test02();
+  return 0;
+}
diff --git a/libstdc++-v3/testsuite/25_algorithms/min/1.cc b/libstdc++-v3/testsuite/25_algorithms/min/1.cc
new file mode 100644 (file)
index 0000000..7ff539d
--- /dev/null
@@ -0,0 +1,44 @@
+// 2000-03-29 sss/bkoz
+
+// Copyright (C) 2000, 2003, 2004, 2005 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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+#include <algorithm>
+#include <functional>
+#include <testsuite_hooks.h>
+
+void test01()
+{
+  bool test __attribute__((unused)) = true;
+
+  const int& z = std::min(1, 2);
+  const int& w = std::min(4, 3);
+  VERIFY( z == 1 );
+  VERIFY( w == 3 );
+
+  const int& zc = std::min(1, 2, std::greater<int>());
+  const int& wc = std::min(4, 3, std::greater<int>());
+  VERIFY( zc == 2 );
+  VERIFY( wc == 4 );
+}
+
+int main()
+{
+  test01();
+  return 0;
+}
similarity index 58%
rename from libstdc++-v3/testsuite/25_algorithms/min_max.cc
rename to libstdc++-v3/testsuite/25_algorithms/min/2.cc
index 8c9bbaa9dccc2952e414bf553fc577d3d5433f49..864462d08251a3ba68c6b76319d776ad6f7f9901 100644 (file)
 #include <functional>
 #include <testsuite_hooks.h>
 
-void test01()
-{
-  bool test __attribute__((unused)) = true;
-
-  const int& x = std::max(1, 2);
-  const int& y = std::max(4, 3);
-  VERIFY( x == 2 );
-  VERIFY( y == 4 );
-
-  const int& xc = std::max(1, 2, std::greater<int>());
-  const int& yc = std::max(4, 3, std::greater<int>());
-  VERIFY( xc == 1 );
-  VERIFY( yc == 3 );
-
-  const int& z = std::min(1, 2);
-  const int& w = std::min(4, 3);
-  VERIFY( z == 1 );
-  VERIFY( w == 3 );
-
-  const int& zc = std::min(1, 2, std::greater<int>());
-  const int& wc = std::min(4, 3, std::greater<int>());
-  VERIFY( zc == 2 );
-  VERIFY( wc == 4 );
-}
-
 template<typename T> 
   struct A { static const T a; };
 
@@ -103,50 +78,10 @@ void test02()
 
   VERIFY( (long double)2 == std::min(A<long double>::a, (long double)2) );
   VERIFY( (long double)3 == std::min(A<long double>::a, (long double)4) );
-
-
-  VERIFY( 3 == std::max(A<int>::a, 2) );
-  VERIFY( 4 == std::max(A<int>::a, 4) );
-
-  VERIFY( 3u == std::max(A<unsigned int>::a, 2u) );
-  VERIFY( 4u == std::max(A<unsigned int>::a, 4u) );
-
-  VERIFY( 3l == std::max(A<long>::a, 2l) );
-  VERIFY( 4l == std::max(A<long>::a, 4l) );
-
-  VERIFY( 3ul == std::max(A<unsigned long>::a, 2ul) );
-  VERIFY( 4ul == std::max(A<unsigned long>::a, 4ul) );
-
-#ifdef _GLIBCXX_USE_LONG_LONG
-  VERIFY( 3ll == std::max(A<long long>::a, 2ll) );
-  VERIFY( 4ll == std::max(A<long long>::a, 4ll) );
-
-  VERIFY( 3ull == std::max(A<unsigned long long>::a, 2ull) );
-  VERIFY( 4ull == std::max(A<unsigned long long>::a, 4ull) );
-#endif
-
-  VERIFY( short(3) == std::max(A<short>::a, short(2)) );
-  VERIFY( short(4) == std::max(A<short>::a, short(4)) );
-
-  VERIFY( (unsigned short)3 == std::max(A<unsigned short>::a, (unsigned short)2) );
-  VERIFY( (unsigned short)4 == std::max(A<unsigned short>::a, (unsigned short)4) );
-
-  VERIFY( (char)3 == std::max(A<char>::a, (char)2) );
-  VERIFY( (char)4 == std::max(A<char>::a, (char)4) );
-
-  VERIFY( (signed char)3 == std::max(A<signed char>::a, (signed char)2) );
-  VERIFY( (signed char)4 == std::max(A<signed char>::a, (signed char)4) );
-
-  VERIFY( (unsigned char)3 == std::max(A<unsigned char>::a, (unsigned char)2) );
-  VERIFY( (unsigned char)4 == std::max(A<unsigned char>::a, (unsigned char)4) );
-
-  VERIFY( (wchar_t)3 == std::max(A<wchar_t>::a, (wchar_t)2) );
-  VERIFY( (wchar_t)4 == std::max(A<wchar_t>::a, (wchar_t)4) );
 }
 
 int main()
 {
-  test01();
   test02();
   return 0;
 }
diff --git a/libstdc++-v3/testsuite/25_algorithms/nth_element/3.cc b/libstdc++-v3/testsuite/25_algorithms/nth_element/3.cc
new file mode 100644 (file)
index 0000000..f1f94bb
--- /dev/null
@@ -0,0 +1,87 @@
+// 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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 25.3.1 algorithms, sort()
+
+#include <algorithm>
+#include <testsuite_hooks.h>
+
+bool test __attribute__((unused)) = true;
+
+const int A[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20};
+const int B[] = {10, 20, 1, 11, 2, 12, 3, 13, 4, 14, 5, 15, 6, 16, 7, 17, 8, 18, 9, 19};
+const int C[] = {20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1};
+const int N = sizeof(A) / sizeof(int);
+const int logN = 3; // ln(N) rounded up
+const int P = 7;
+
+// comparison predicate for stable_sort: order by rightmost digit
+struct CompLast
+{
+  bool
+  operator()(const int x, const int y)
+  { return x % 10 < y % 10; }
+};
+
+// This functor has the equivalent functionality of std::geater<>,
+// but there is no dependency on <functional> and it also tracks the
+// number of invocations since creation.
+class Gt
+{
+public:
+  static int count() { return itsCount; }
+  static void reset() { itsCount = 0; }
+  
+  bool
+  operator()(const int& x, const int& y)
+  {
+    ++itsCount;
+    return x > y; 
+  }
+
+private:
+    static int itsCount;
+};
+
+int Gt::itsCount = 0;
+
+// 25.3.2 nth_element()
+void
+test05()
+{
+    using std::nth_element;
+
+    int s1[N];
+    std::copy(B, B + N, s1);
+    VERIFY(std::equal(s1, s1 + N, B));
+
+    int* pn = s1 + (N / 2) - 1;
+    nth_element(s1, pn, s1 + N);
+    for (const int* i = pn; i < s1 + N; ++i) VERIFY(!(*i < *pn));
+
+    CompLast pred;
+    nth_element(s1, pn, s1 + N, pred);
+    for (const int* i = pn; i < s1 + N; ++i) VERIFY(!pred(*i, *pn));
+}
+
+int
+main()
+{
+  test05();
+  return 0;
+}
diff --git a/libstdc++-v3/testsuite/25_algorithms/partial_sort/2.cc b/libstdc++-v3/testsuite/25_algorithms/partial_sort/2.cc
new file mode 100644 (file)
index 0000000..b60a03e
--- /dev/null
@@ -0,0 +1,85 @@
+// 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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 25.3.1 algorithms, sort()
+
+#include <algorithm>
+#include <testsuite_hooks.h>
+
+bool test __attribute__((unused)) = true;
+
+const int A[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20};
+const int B[] = {10, 20, 1, 11, 2, 12, 3, 13, 4, 14, 5, 15, 6, 16, 7, 17, 8, 18, 9, 19};
+const int C[] = {20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1};
+const int N = sizeof(A) / sizeof(int);
+const int logN = 3; // ln(N) rounded up
+const int P = 7;
+
+// comparison predicate for stable_sort: order by rightmost digit
+struct CompLast
+{
+  bool
+  operator()(const int x, const int y)
+  { return x % 10 < y % 10; }
+};
+
+// This functor has the equivalent functionality of std::geater<>,
+// but there is no dependency on <functional> and it also tracks the
+// number of invocations since creation.
+class Gt
+{
+public:
+  static int count() { return itsCount; }
+  static void reset() { itsCount = 0; }
+  
+  bool
+  operator()(const int& x, const int& y)
+  {
+    ++itsCount;
+    return x > y; 
+  }
+
+private:
+    static int itsCount;
+};
+
+int Gt::itsCount = 0;
+
+// 25.3.1.3 partial_sort()
+void
+test03()
+{
+    int s1[N];
+    std::copy(B, B + N, s1);
+    VERIFY(std::equal(s1, s1 + N, B));
+
+    std::partial_sort(s1, s1 + P, s1 + N);
+    VERIFY(std::equal(s1, s1 + P, A));
+
+    Gt gt;
+    gt.reset();
+    std::partial_sort(s1, s1 + P, s1 + N, gt);
+    VERIFY(std::equal(s1, s1 + P, C));
+}
+
+int
+main()
+{
+  test03();
+  return 0;
+}
similarity index 54%
rename from libstdc++-v3/testsuite/25_algorithms/sort.cc
rename to libstdc++-v3/testsuite/25_algorithms/partial_sort_copy/2.cc
index 6ca01ef74150d2396cee476d8ea8f9b5f6a3ad8f..e21ace07ee2d1d7f80d5ccefee745708241e0863 100644 (file)
@@ -33,9 +33,9 @@ const int P = 7;
 // comparison predicate for stable_sort: order by rightmost digit
 struct CompLast
 {
-    bool
-    operator()(const int x, const int y)
-    { return x % 10 < y % 10; }
+  bool
+  operator()(const int x, const int y)
+  { return x % 10 < y % 10; }
 };
 
 // This functor has the equivalent functionality of std::geater<>,
@@ -44,15 +44,15 @@ struct CompLast
 class Gt
 {
 public:
-    static int count() { return itsCount; }
-    static void reset() { itsCount = 0; }
-
-    bool
-    operator()(const int& x, const int& y)
-    {
-        ++itsCount;
-        return x > y; 
-    }
+  static int count() { return itsCount; }
+  static void reset() { itsCount = 0; }
+  
+  bool
+  operator()(const int& x, const int& y)
+  {
+    ++itsCount;
+    return x > y; 
+  }
 
 private:
     static int itsCount;
@@ -61,61 +61,6 @@ private:
 int Gt::itsCount = 0;
 
 
-// 25.3.1.1 sort()
-void
-test01()
-{
-    int s1[N];
-    std::copy(B, B + N, s1);
-    VERIFY(std::equal(s1, s1 + N, B));
-
-    std::sort(s1, s1 + N);
-    VERIFY(std::equal(s1, s1 + N, A));
-
-    Gt gt;
-    gt.reset();
-    std::sort(s1, s1 + N, gt);
-    VERIFY(std::equal(s1, s1 + N, C));
-}
-
-// 25.3.1.2 stable_sort()
-void
-test02()
-{
-    int s1[N];
-    std::copy(A, A + N, s1);
-    VERIFY(std::equal(s1, s1 + N, A));
-
-    std::stable_sort(s1, s1 + N, CompLast());
-    VERIFY(std::equal(s1, s1 + N, B));
-
-    std::stable_sort(s1, s1 + N);
-    VERIFY(std::equal(s1, s1 + N, A));
-
-    Gt gt;
-    gt.reset();
-    std::stable_sort(s1, s1 + N, gt);
-    VERIFY(std::equal(s1, s1 + N, C));
-    VERIFY(gt.count() <= N * logN * logN);
-}
-
-// 25.3.1.3 partial_sort()
-void
-test03()
-{
-    int s1[N];
-    std::copy(B, B + N, s1);
-    VERIFY(std::equal(s1, s1 + N, B));
-
-    std::partial_sort(s1, s1 + P, s1 + N);
-    VERIFY(std::equal(s1, s1 + P, A));
-
-    Gt gt;
-    gt.reset();
-    std::partial_sort(s1, s1 + P, s1 + N, gt);
-    VERIFY(std::equal(s1, s1 + P, C));
-}
-
 // 25.3.1.4 partial_sort_copy()
 void
 test04()
@@ -139,33 +84,9 @@ test04()
     VERIFY(std::equal(s2, partial_sort_copy(s1, s1 + N, s2, s2 + 2*N), A));
 }
 
-// 25.3.2 nth_element()
-void
-test05()
-{
-    using std::nth_element;
-
-    int s1[N];
-    std::copy(B, B + N, s1);
-    VERIFY(std::equal(s1, s1 + N, B));
-
-    int* pn = s1 + (N / 2) - 1;
-    nth_element(s1, pn, s1 + N);
-    for (const int* i = pn; i < s1 + N; ++i) VERIFY(!(*i < *pn));
-
-    CompLast pred;
-    nth_element(s1, pn, s1 + N, pred);
-    for (const int* i = pn; i < s1 + N; ++i) VERIFY(!pred(*i, *pn));
-}
-
 int
 main()
 {
-  test01();
-  test02();
-  test03();
   test04();
-  test05();
-  
   return 0;
 }
diff --git a/libstdc++-v3/testsuite/25_algorithms/sort/1.cc b/libstdc++-v3/testsuite/25_algorithms/sort/1.cc
new file mode 100644 (file)
index 0000000..c28db2b
--- /dev/null
@@ -0,0 +1,86 @@
+// 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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 25.3.1 algorithms, sort()
+
+#include <algorithm>
+#include <testsuite_hooks.h>
+
+bool test __attribute__((unused)) = true;
+
+const int A[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20};
+const int B[] = {10, 20, 1, 11, 2, 12, 3, 13, 4, 14, 5, 15, 6, 16, 7, 17, 8, 18, 9, 19};
+const int C[] = {20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1};
+const int N = sizeof(A) / sizeof(int);
+const int logN = 3; // ln(N) rounded up
+const int P = 7;
+
+// comparison predicate for stable_sort: order by rightmost digit
+struct CompLast
+{
+  bool
+  operator()(const int x, const int y)
+  { return x % 10 < y % 10; }
+};
+
+// This functor has the equivalent functionality of std::geater<>,
+// but there is no dependency on <functional> and it also tracks the
+// number of invocations since creation.
+class Gt
+{
+public:
+  static int count() { return itsCount; }
+  static void reset() { itsCount = 0; }
+  
+  bool
+  operator()(const int& x, const int& y)
+  {
+    ++itsCount;
+    return x > y; 
+  }
+
+private:
+    static int itsCount;
+};
+
+int Gt::itsCount = 0;
+
+
+// 25.3.1.1 sort()
+void
+test01()
+{
+    int s1[N];
+    std::copy(B, B + N, s1);
+    VERIFY(std::equal(s1, s1 + N, B));
+
+    std::sort(s1, s1 + N);
+    VERIFY(std::equal(s1, s1 + N, A));
+
+    Gt gt;
+    gt.reset();
+    std::sort(s1, s1 + N, gt);
+    VERIFY(std::equal(s1, s1 + N, C));
+}
+
+int
+main()
+{
+  test01();
+  return 0;
+}
diff --git a/libstdc++-v3/testsuite/25_algorithms/stable_sort/2.cc b/libstdc++-v3/testsuite/25_algorithms/stable_sort/2.cc
new file mode 100644 (file)
index 0000000..3d8299a
--- /dev/null
@@ -0,0 +1,89 @@
+// 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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 25.3.1 algorithms, sort()
+
+#include <algorithm>
+#include <testsuite_hooks.h>
+
+bool test __attribute__((unused)) = true;
+
+const int A[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20};
+const int B[] = {10, 20, 1, 11, 2, 12, 3, 13, 4, 14, 5, 15, 6, 16, 7, 17, 8, 18, 9, 19};
+const int C[] = {20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1};
+const int N = sizeof(A) / sizeof(int);
+const int logN = 3; // ln(N) rounded up
+const int P = 7;
+
+// comparison predicate for stable_sort: order by rightmost digit
+struct CompLast
+{
+  bool
+  operator()(const int x, const int y)
+  { return x % 10 < y % 10; }
+};
+
+// This functor has the equivalent functionality of std::geater<>,
+// but there is no dependency on <functional> and it also tracks the
+// number of invocations since creation.
+class Gt
+{
+public:
+  static int count() { return itsCount; }
+  static void reset() { itsCount = 0; }
+  
+  bool
+  operator()(const int& x, const int& y)
+  {
+    ++itsCount;
+    return x > y; 
+  }
+
+private:
+    static int itsCount;
+};
+
+int Gt::itsCount = 0;
+
+// 25.3.1.2 stable_sort()
+void
+test02()
+{
+    int s1[N];
+    std::copy(A, A + N, s1);
+    VERIFY(std::equal(s1, s1 + N, A));
+
+    std::stable_sort(s1, s1 + N, CompLast());
+    VERIFY(std::equal(s1, s1 + N, B));
+
+    std::stable_sort(s1, s1 + N);
+    VERIFY(std::equal(s1, s1 + N, A));
+
+    Gt gt;
+    gt.reset();
+    std::stable_sort(s1, s1 + N, gt);
+    VERIFY(std::equal(s1, s1 + N, C));
+    VERIFY(gt.count() <= N * logN * logN);
+}
+
+int
+main()
+{
+  test02();
+  return 0;
+}