[libcxx][test][NFC] Add tests for backward iteration over associative

containers

Add test cases for iteration over the ordered associative container from
end to begin using operator--

Reviewed By: Quuxplusone, rarutyun

Differential Revision: https://reviews.llvm.org/D118114
This commit is contained in:
Ruslan Arutyunyan 2022-02-08 01:02:57 +03:00
parent d28051c4ab
commit 6a929492a6
4 changed files with 128 additions and 0 deletions

View File

@ -77,6 +77,16 @@ int main(int, char**)
i->second = 2.5;
assert(i->second == 2.5);
}
assert(i == m.end());
for (int j = m.size(); j >= 1; --j)
{
--i;
assert(i->first == j);
assert(i->second == 2.5);
i->second = 1;
assert(i->second == 1);
}
assert(i == m.begin());
}
{
typedef std::pair<const int, double> V;
@ -119,6 +129,14 @@ int main(int, char**)
assert(i->first == j);
assert(i->second == 1);
}
assert(i == m.end());
for (int j = m.size(); j >= 1; --j)
{
--i;
assert(i->first == j);
assert(i->second == 1);
}
assert(i == m.begin());
}
#if TEST_STD_VER >= 11
{
@ -164,6 +182,16 @@ int main(int, char**)
i->second = 2.5;
assert(i->second == 2.5);
}
assert(i == m.end());
for (int j = m.size(); j >= 1; --j)
{
--i;
assert(i->first == j);
assert(i->second == 2.5);
i->second = 1;
assert(i->second == 1);
}
assert(i == m.begin());
}
{
typedef std::pair<const int, double> V;
@ -206,6 +234,14 @@ int main(int, char**)
assert(i->first == j);
assert(i->second == 1);
}
assert(i == m.end());
for (int j = m.size(); j >= 1; --j)
{
--i;
assert(i->first == j);
assert(i->second == 1);
}
assert(i == m.begin());
}
#endif
#if TEST_STD_VER > 11

View File

@ -78,6 +78,17 @@ int main(int, char**)
i->second = 2.5;
assert(i->second == 2.5);
}
assert(i == m.end());
for (int j = 8; j >= 1; --j)
for (double d = 1; d <= 2; d += .5)
{
--i;
assert(i->first == j);
assert(i->second == 2.5);
i->second = d;
assert(i->second == d);
}
assert(i == m.begin());
}
{
typedef std::pair<const int, double> V;
@ -121,6 +132,15 @@ int main(int, char**)
assert(i->first == j);
assert(i->second == d);
}
assert(i == m.end());
for (int j = 8; j >= 1; --j)
for (double d = 2; d >= 1; d -= .5)
{
--i;
assert(i->first == j);
assert(i->second == d);
}
assert(i == m.begin());
}
#if TEST_STD_VER >= 11
{
@ -167,6 +187,17 @@ int main(int, char**)
i->second = 2.5;
assert(i->second == 2.5);
}
assert(i == m.end());
for (int j = 8; j >= 1; --j)
for (double d = 1; d <= 2; d += .5)
{
--i;
assert(i->first == j);
assert(i->second == 2.5);
i->second = d;
assert(i->second == d);
}
assert(i == m.begin());
}
{
typedef std::pair<const int, double> V;
@ -210,6 +241,15 @@ int main(int, char**)
assert(i->first == j);
assert(i->second == d);
}
assert(i == m.end());
for (int j = 8; j >= 1; --j)
for (double d = 2; d >= 1; d -= .5)
{
--i;
assert(i->first == j);
assert(i->second == d);
}
assert(i == m.begin());
}
#endif
#if TEST_STD_VER > 11

View File

@ -73,6 +73,13 @@ int main(int, char**)
for (int j = 1; j <= 8; ++j)
for (int n = 0; n < 3; ++n, ++i)
assert(*i == j);
assert(i == m.end());
for (int j = 8; j >= 1; --j)
for (int n = 0; n < 3; ++n) {
--i;
assert(*i == j);
}
assert(i == m.begin());
}
{
typedef int V;
@ -113,6 +120,13 @@ int main(int, char**)
for (int j = 1; j <= 8; ++j)
for (int k = 0; k < 3; ++k, ++i)
assert(*i == j);
assert(i == m.end());
for (int j = 8; j >= 1; --j)
for (int k = 0; k < 3; ++k) {
--i;
assert(*i == j);
}
assert(i == m.begin());
}
#if TEST_STD_VER >= 11
{
@ -154,6 +168,13 @@ int main(int, char**)
for (int j = 1; j <= 8; ++j)
for (int n = 0; n < 3; ++n, ++i)
assert(*i == j);
assert(i == m.end());
for (int j = 8; j >= 1; --j)
for (int n = 0; n < 3; ++n) {
--i;
assert(*i == j);
}
assert(i == m.begin());
}
{
typedef int V;
@ -194,6 +215,13 @@ int main(int, char**)
for (int j = 1; j <= 8; ++j)
for (int k = 0; k < 3; ++k, ++i)
assert(*i == j);
assert(i == m.end());
for (int j = 8; j >= 1; --j)
for (int k = 0; k < 3; ++k) {
--i;
assert(*i == j);
}
assert(i == m.begin());
}
#endif
#if TEST_STD_VER > 11

View File

@ -72,6 +72,12 @@ int main(int, char**)
assert(i == k);
for (int j = 1; static_cast<std::size_t>(j) <= m.size(); ++j, ++i)
assert(*i == j);
assert(i == m.end());
for (int j = m.size(); j >= 1; --j) {
--i;
assert(*i == j);
}
assert(i == m.begin());
}
{
typedef int V;
@ -111,6 +117,12 @@ int main(int, char**)
i = m.begin();
for (int j = 1; static_cast<std::size_t>(j) <= m.size(); ++j, ++i)
assert(*i == j);
assert(i == m.end());
for (int j = m.size(); j >= 1; --j) {
--i;
assert(*i == j);
}
assert(i == m.begin());
}
#if TEST_STD_VER >= 11
{
@ -151,6 +163,12 @@ int main(int, char**)
assert(i == k);
for (int j = 1; static_cast<std::size_t>(j) <= m.size(); ++j, ++i)
assert(*i == j);
assert(i == m.end());
for (int j = m.size(); j >= 1; --j) {
--i;
assert(*i == j);
}
assert(i == m.begin());
}
{
typedef int V;
@ -190,6 +208,12 @@ int main(int, char**)
i = m.begin();
for (int j = 1; static_cast<std::size_t>(j) <= m.size(); ++j, ++i)
assert(*i == j);
assert(i == m.end());
for (int j = m.size(); j >= 1; --j) {
--i;
assert(*i == j);
}
assert(i == m.begin());
}
#endif
#if TEST_STD_VER > 11