[libcxx] r207232 - Added some tests for equal elements in min_element and max_element. Bug #19547 was invalid, but we weren't testing that case

Marshall Clow mclow.lists at gmail.com
Fri Apr 25 08:50:54 PDT 2014


Author: marshall
Date: Fri Apr 25 10:50:54 2014
New Revision: 207232

URL: http://llvm.org/viewvc/llvm-project?rev=207232&view=rev
Log:
Added some tests for equal elements in min_element and max_element. Bug #19547 was invalid, but we weren't testing that case

Modified:
    libcxx/trunk/test/algorithms/alg.sorting/alg.min.max/max_element_comp.pass.cpp
    libcxx/trunk/test/algorithms/alg.sorting/alg.min.max/min_element_comp.pass.cpp

Modified: libcxx/trunk/test/algorithms/alg.sorting/alg.min.max/max_element_comp.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/algorithms/alg.sorting/alg.min.max/max_element_comp.pass.cpp?rev=207232&r1=207231&r2=207232&view=diff
==============================================================================
--- libcxx/trunk/test/algorithms/alg.sorting/alg.min.max/max_element_comp.pass.cpp (original)
+++ libcxx/trunk/test/algorithms/alg.sorting/alg.min.max/max_element_comp.pass.cpp Fri Apr 25 10:50:54 2014
@@ -58,10 +58,28 @@ test()
     test<Iter>(1000);
 }
 
+template <class Iter, class Pred>
+void test_eq0(Iter first, Iter last, Pred p)
+{
+    assert(first == std::max_element(first, last, p));
+}
+
+void test_eq()
+{
+    const size_t N = 10;
+    int* a = new int[N];
+    for (int i = 0; i < N; ++i)
+        a[i] = 10; // all the same
+    test_eq0(a, a+N, std::less<int>());
+    test_eq0(a, a+N, std::greater<int>());
+    delete [] a;
+}
+
 int main()
 {
     test<forward_iterator<const int*> >();
     test<bidirectional_iterator<const int*> >();
     test<random_access_iterator<const int*> >();
     test<const int*>();
+    test_eq();
 }

Modified: libcxx/trunk/test/algorithms/alg.sorting/alg.min.max/min_element_comp.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/algorithms/alg.sorting/alg.min.max/min_element_comp.pass.cpp?rev=207232&r1=207231&r2=207232&view=diff
==============================================================================
--- libcxx/trunk/test/algorithms/alg.sorting/alg.min.max/min_element_comp.pass.cpp (original)
+++ libcxx/trunk/test/algorithms/alg.sorting/alg.min.max/min_element_comp.pass.cpp Fri Apr 25 10:50:54 2014
@@ -58,10 +58,28 @@ test()
     test<Iter>(1000);
 }
 
+template <class Iter, class Pred>
+void test_eq0(Iter first, Iter last, Pred p)
+{
+    assert(first == std::min_element(first, last, p));
+}
+
+void test_eq()
+{
+    const size_t N = 10;
+    int* a = new int[N];
+    for (int i = 0; i < N; ++i)
+        a[i] = 10; // all the same
+    test_eq0(a, a+N, std::less<int>());
+    test_eq0(a, a+N, std::greater<int>());
+    delete [] a;
+}
+
 int main()
 {
     test<forward_iterator<const int*> >();
     test<bidirectional_iterator<const int*> >();
     test<random_access_iterator<const int*> >();
     test<const int*>();
+    test_eq();
 }





More information about the cfe-commits mailing list