Added vector<T>::insert tests suggested by code coverage results
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@221689 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
3f305aefa0
commit
ac23805464
@ -47,6 +47,22 @@ int main()
|
||||
for (++j; j < v.size(); ++j)
|
||||
assert(v[j] == 0);
|
||||
}
|
||||
{
|
||||
std::vector<bool> v(100);
|
||||
while(v.size() < v.capacity()) v.push_back(false);
|
||||
v.pop_back(); v.pop_back();
|
||||
size_t sz = v.size();
|
||||
std::vector<bool>::iterator i = v.insert(v.cbegin() + 10, 5, 1);
|
||||
assert(v.size() == sz + 5);
|
||||
assert(i == v.begin() + 10);
|
||||
int j;
|
||||
for (j = 0; j < 10; ++j)
|
||||
assert(v[j] == 0);
|
||||
for (; j < 15; ++j)
|
||||
assert(v[j] == 1);
|
||||
for (++j; j < v.size(); ++j)
|
||||
assert(v[j] == 0);
|
||||
}
|
||||
#if __cplusplus >= 201103L
|
||||
{
|
||||
std::vector<bool, min_allocator<bool>> v(100);
|
||||
|
@ -45,6 +45,21 @@ int main()
|
||||
for (++j; j < v.size(); ++j)
|
||||
assert(v[j] == 0);
|
||||
}
|
||||
{
|
||||
std::vector<bool> v(100);
|
||||
while(v.size() < v.capacity()) v.push_back(false);
|
||||
v.pop_back(); v.pop_back();
|
||||
size_t sz = v.size();
|
||||
std::vector<bool>::iterator i = v.insert(v.cbegin() + 10, 1);
|
||||
assert(v.size() == sz + 1);
|
||||
assert(i == v.begin() + 10);
|
||||
int j;
|
||||
for (j = 0; j < 10; ++j)
|
||||
assert(v[j] == 0);
|
||||
assert(v[j] == 1);
|
||||
for (++j; j < v.size(); ++j)
|
||||
assert(v[j] == 0);
|
||||
}
|
||||
#if __cplusplus >= 201103L
|
||||
{
|
||||
std::vector<bool, min_allocator<bool>> v(100);
|
||||
|
@ -59,6 +59,42 @@ int main()
|
||||
for (; j < 105; ++j)
|
||||
assert(v[j] == 0);
|
||||
}
|
||||
{
|
||||
std::vector<int> v(100);
|
||||
while(v.size() < v.capacity()) v.push_back(0); // force reallocation
|
||||
size_t sz = v.size();
|
||||
int a[] = {1, 2, 3, 4, 5};
|
||||
const unsigned N = sizeof(a)/sizeof(a[0]);
|
||||
std::vector<int>::iterator i = v.insert(v.cbegin() + 10, forward_iterator<const int*>(a),
|
||||
forward_iterator<const int*>(a+N));
|
||||
assert(v.size() == sz + N);
|
||||
assert(i == v.begin() + 10);
|
||||
int j;
|
||||
for (j = 0; j < 10; ++j)
|
||||
assert(v[j] == 0);
|
||||
for (int k = 0; k < N; ++j, ++k)
|
||||
assert(v[j] == a[k]);
|
||||
for (; j < v.size(); ++j)
|
||||
assert(v[j] == 0);
|
||||
}
|
||||
{
|
||||
std::vector<int> v(100);
|
||||
v.reserve(128); // force no reallocation
|
||||
size_t sz = v.size();
|
||||
int a[] = {1, 2, 3, 4, 5};
|
||||
const unsigned N = sizeof(a)/sizeof(a[0]);
|
||||
std::vector<int>::iterator i = v.insert(v.cbegin() + 10, forward_iterator<const int*>(a),
|
||||
forward_iterator<const int*>(a+N));
|
||||
assert(v.size() == sz + N);
|
||||
assert(i == v.begin() + 10);
|
||||
int j;
|
||||
for (j = 0; j < 10; ++j)
|
||||
assert(v[j] == 0);
|
||||
for (int k = 0; k < N; ++j, ++k)
|
||||
assert(v[j] == a[k]);
|
||||
for (; j < v.size(); ++j)
|
||||
assert(v[j] == 0);
|
||||
}
|
||||
{
|
||||
std::vector<int, stack_allocator<int, 308> > v(100);
|
||||
int a[] = {1, 2, 3, 4, 5};
|
||||
|
@ -37,6 +37,38 @@ int main()
|
||||
for (++j; j < 105; ++j)
|
||||
assert(v[j] == 0);
|
||||
}
|
||||
{
|
||||
std::vector<int> v(100);
|
||||
while(v.size() < v.capacity()) v.push_back(0); // force reallocation
|
||||
size_t sz = v.size();
|
||||
std::vector<int>::iterator i = v.insert(v.cbegin() + 10, 5, 1);
|
||||
assert(v.size() == sz + 5);
|
||||
assert(is_contiguous_container_asan_correct(v));
|
||||
assert(i == v.begin() + 10);
|
||||
int j;
|
||||
for (j = 0; j < 10; ++j)
|
||||
assert(v[j] == 0);
|
||||
for (; j < 15; ++j)
|
||||
assert(v[j] == 1);
|
||||
for (++j; j < v.size(); ++j)
|
||||
assert(v[j] == 0);
|
||||
}
|
||||
{
|
||||
std::vector<int> v(100);
|
||||
v.reserve(128); // force no reallocation
|
||||
size_t sz = v.size();
|
||||
std::vector<int>::iterator i = v.insert(v.cbegin() + 10, 5, 1);
|
||||
assert(v.size() == sz + 5);
|
||||
assert(is_contiguous_container_asan_correct(v));
|
||||
assert(i == v.begin() + 10);
|
||||
int j;
|
||||
for (j = 0; j < 10; ++j)
|
||||
assert(v[j] == 0);
|
||||
for (; j < 15; ++j)
|
||||
assert(v[j] == 1);
|
||||
for (++j; j < v.size(); ++j)
|
||||
assert(v[j] == 0);
|
||||
}
|
||||
{
|
||||
std::vector<int, stack_allocator<int, 300> > v(100);
|
||||
std::vector<int, stack_allocator<int, 300> >::iterator i = v.insert(v.cbegin() + 10, 5, 1);
|
||||
|
@ -36,6 +36,37 @@ int main()
|
||||
for (++j; j < 101; ++j)
|
||||
assert(v[j] == 0);
|
||||
}
|
||||
{
|
||||
std::vector<int> v(100);
|
||||
while(v.size() < v.capacity()) v.push_back(0); // force reallocation
|
||||
size_t sz = v.size();
|
||||
std::vector<int>::iterator i = v.insert(v.cbegin() + 10, 1);
|
||||
assert(v.size() == sz + 1);
|
||||
assert(is_contiguous_container_asan_correct(v));
|
||||
assert(i == v.begin() + 10);
|
||||
int j;
|
||||
for (j = 0; j < 10; ++j)
|
||||
assert(v[j] == 0);
|
||||
assert(v[j] == 1);
|
||||
for (++j; j < v.size(); ++j)
|
||||
assert(v[j] == 0);
|
||||
}
|
||||
{
|
||||
std::vector<int> v(100);
|
||||
while(v.size() < v.capacity()) v.push_back(0);
|
||||
v.pop_back(); v.pop_back(); // force no reallocation
|
||||
size_t sz = v.size();
|
||||
std::vector<int>::iterator i = v.insert(v.cbegin() + 10, 1);
|
||||
assert(v.size() == sz + 1);
|
||||
assert(is_contiguous_container_asan_correct(v));
|
||||
assert(i == v.begin() + 10);
|
||||
int j;
|
||||
for (j = 0; j < 10; ++j)
|
||||
assert(v[j] == 0);
|
||||
assert(v[j] == 1);
|
||||
for (++j; j < v.size(); ++j)
|
||||
assert(v[j] == 0);
|
||||
}
|
||||
{
|
||||
std::vector<int, stack_allocator<int, 300> > v(100);
|
||||
std::vector<int, stack_allocator<int, 300> >::iterator i = v.insert(v.cbegin() + 10, 1);
|
||||
|
Loading…
x
Reference in New Issue
Block a user