Add checking for the complexity guarantees in the standard
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@212017 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
81aa3a745c
commit
c8c7abae66
@ -17,6 +17,9 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
|
||||||
|
#include "counting_predicates.hpp"
|
||||||
|
|
||||||
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
@ -34,9 +37,20 @@ void test(unsigned N)
|
|||||||
int* ia = new int [N];
|
int* ia = new int [N];
|
||||||
for (int i = 0; i < N; ++i)
|
for (int i = 0; i < N; ++i)
|
||||||
ia[i] = i;
|
ia[i] = i;
|
||||||
|
{
|
||||||
std::random_shuffle(ia, ia+N);
|
std::random_shuffle(ia, ia+N);
|
||||||
std::make_heap(ia, ia+N, std::greater<int>());
|
std::make_heap(ia, ia+N, std::greater<int>());
|
||||||
assert(std::is_heap(ia, ia+N, std::greater<int>()));
|
assert(std::is_heap(ia, ia+N, std::greater<int>()));
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
binary_counting_predicate<std::greater<int>, int, int> pred ((std::greater<int>()));
|
||||||
|
std::random_shuffle(ia, ia+N);
|
||||||
|
std::make_heap(ia, ia+N, std::ref(pred));
|
||||||
|
assert(pred.count() <= 3*N);
|
||||||
|
assert(std::is_heap(ia, ia+N, pred));
|
||||||
|
}
|
||||||
|
|
||||||
delete [] ia;
|
delete [] ia;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -48,6 +62,8 @@ int main()
|
|||||||
test(3);
|
test(3);
|
||||||
test(10);
|
test(10);
|
||||||
test(1000);
|
test(1000);
|
||||||
|
test(10000);
|
||||||
|
test(100000);
|
||||||
|
|
||||||
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user