Skip to content

Commit

Permalink
test: new tests for count()
Browse files Browse the repository at this point in the history
  • Loading branch information
tearfur committed Feb 21, 2024
1 parent 4900e71 commit dd03342
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
14 changes: 14 additions & 0 deletions test/unit/small_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ TEST_CASE("Small Map") {
{ 3, 3 },
{ 4, 4 }
}));
REQUIRE(a.count(4) == 1);

// NOLINTNEXTLINE(performance-move-const-arg)
auto p = std::make_pair(5, 5);
Expand All @@ -360,6 +361,7 @@ TEST_CASE("Small Map") {
{ 4, 4 },
{ 5, 5 }
}));
REQUIRE(a.count(5) == 1);

REQUIRE(a.erase(5) == 1);
REQUIRE(a.size() == 4);
Expand All @@ -374,6 +376,7 @@ TEST_CASE("Small Map") {
{ 3, 3 },
{ 4, 4 }
}));
REQUIRE(a.count(5) == 0);

a.emplace(5, 5);
REQUIRE(a.back().first == 5);
Expand All @@ -390,6 +393,7 @@ TEST_CASE("Small Map") {
{ 4, 4 },
{ 5, 5 }
}));
REQUIRE(a.count(5) == 1);

a.erase(std::prev(a.end()));
REQUIRE(a.size() == 4);
Expand Down Expand Up @@ -421,6 +425,7 @@ TEST_CASE("Small Map") {
{ 4, 4 },
{ 10, 10 }
}));
REQUIRE(a.count(10) == 1);

REQUIRE(a.erase(10) == 1);
REQUIRE(a.erase(4) == 1);
Expand All @@ -435,6 +440,7 @@ TEST_CASE("Small Map") {
{ 2, 2 },
{ 3, 3 }
}));
REQUIRE(a.count(10) == 0);

std::initializer_list<std::pair<const int, int>> src = {
{ 6, 6 },
Expand Down Expand Up @@ -1535,6 +1541,7 @@ TEST_CASE("Small Multi Map") {
{ 3, 3 },
{ 4, 4 }
}));
REQUIRE(a.count(4) == 1);

// NOLINTNEXTLINE(performance-move-const-arg)
auto p = std::make_pair(5, 5);
Expand All @@ -1553,6 +1560,7 @@ TEST_CASE("Small Multi Map") {
{ 4, 4 },
{ 5, 5 }
}));
REQUIRE(a.count(5) == 1);

REQUIRE(a.erase(5) == 1);
REQUIRE(a.size() == 4);
Expand All @@ -1567,6 +1575,7 @@ TEST_CASE("Small Multi Map") {
{ 3, 3 },
{ 4, 4 }
}));
REQUIRE(a.count(5) == 0);

a.emplace(5, 5);
REQUIRE(a.back().first == 5);
Expand All @@ -1583,6 +1592,7 @@ TEST_CASE("Small Multi Map") {
{ 4, 4 },
{ 5, 5 }
}));
REQUIRE(a.count(5) == 1);

a.erase(std::prev(a.end()));
REQUIRE(a.size() == 4);
Expand Down Expand Up @@ -1614,6 +1624,7 @@ TEST_CASE("Small Multi Map") {
{ 4, 4 },
{ 10, 10 }
}));
REQUIRE(a.count(10) == 1);

REQUIRE(a.erase(10) == 1);
REQUIRE(a.erase(4) == 1);
Expand All @@ -1628,6 +1639,7 @@ TEST_CASE("Small Multi Map") {
{ 2, 2 },
{ 3, 3 }
}));
REQUIRE(a.count(10) == 0);

std::initializer_list<std::pair<const int, int>> src = {
{ 6, 6 },
Expand Down Expand Up @@ -1687,6 +1699,7 @@ TEST_CASE("Small Multi Map") {
{ 7, 7 },
{ 7, 8 }
}));
REQUIRE(a.count(7) == 2);

it = a.erase(a.begin() + 1);
REQUIRE(it == a.begin() + 1);
Expand Down Expand Up @@ -1731,6 +1744,7 @@ TEST_CASE("Small Multi Map") {
{ 1, 1 },
{ 6, 6 }
}));
REQUIRE(a.count(7) == 0);

a.clear();
// NOLINTNEXTLINE(readability-container-size-empty)
Expand Down
12 changes: 12 additions & 0 deletions test/unit/small_set.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ TEST_CASE("Small Set") {
REQUIRE(a.capacity() == 5);
REQUIRE_FALSE(a.empty());
REQUIRE(equal_il(a, { 1, 2, 3, 4 }));
REQUIRE(a.count(4) == 1);

// NOLINTNEXTLINE(performance-move-const-arg)
int p = 5;
Expand All @@ -246,13 +247,15 @@ TEST_CASE("Small Set") {
REQUIRE(a.capacity() == 5);
REQUIRE_FALSE(a.empty());
REQUIRE(equal_il(a, { 1, 2, 3, 4, 5 }));
REQUIRE(a.count(5) == 1);

REQUIRE(a.erase(5) == 1);
REQUIRE(a.size() == 4);
REQUIRE(a.max_size() > 5);
REQUIRE(a.capacity() == 5);
REQUIRE_FALSE(a.empty());
REQUIRE(equal_il(a, { 1, 2, 3, 4 }));
REQUIRE(a.count(5) == 0);

a.emplace(5);
REQUIRE(a.back() == 5);
Expand All @@ -261,6 +264,7 @@ TEST_CASE("Small Set") {
REQUIRE(a.capacity() == 5);
REQUIRE_FALSE(a.empty());
REQUIRE(equal_il(a, { 1, 2, 3, 4, 5 }));
REQUIRE(a.count(5) == 1);

a.erase(std::prev(a.end()));
REQUIRE(a.size() == 4);
Expand All @@ -277,6 +281,7 @@ TEST_CASE("Small Set") {
REQUIRE(a.capacity() == 5);
REQUIRE_FALSE(a.empty());
REQUIRE(equal_il(a, { 1, 2, 3, 4, 10 }));
REQUIRE(a.count(10) == 1);

REQUIRE(a.erase(10) == 1);
REQUIRE(a.erase(4) == 1);
Expand All @@ -285,6 +290,7 @@ TEST_CASE("Small Set") {
REQUIRE(a.capacity() == 5);
REQUIRE_FALSE(a.empty());
REQUIRE(equal_il(a, { 1, 2, 3 }));
REQUIRE(a.count(10) == 0);

std::initializer_list<int> src = { 6, 5, 7 };
a.insert(src.begin(), src.end());
Expand Down Expand Up @@ -887,6 +893,7 @@ TEST_CASE("Small Multi Set") {
REQUIRE(a.capacity() == 5);
REQUIRE_FALSE(a.empty());
REQUIRE(equal_il(a, { 1, 2, 3, 4, 4 }));
REQUIRE(a.count(4) == 2);

// NOLINTNEXTLINE(performance-move-const-arg)
int p = 5;
Expand All @@ -897,13 +904,15 @@ TEST_CASE("Small Multi Set") {
REQUIRE(a.capacity() >= 6);
REQUIRE_FALSE(a.empty());
REQUIRE(equal_il(a, { 1, 2, 3, 4, 4, 5 }));
REQUIRE(a.count(5) == 1);

REQUIRE(a.erase(5) == 1);
REQUIRE(a.size() == 5);
REQUIRE(a.max_size() > 5);
REQUIRE(a.capacity() >= 5);
REQUIRE_FALSE(a.empty());
REQUIRE(equal_il(a, { 1, 2, 3, 4, 4 }));
REQUIRE(a.count(5) == 0);

a.emplace(5);
REQUIRE(a.back() == 5);
Expand All @@ -912,6 +921,7 @@ TEST_CASE("Small Multi Set") {
REQUIRE(a.capacity() >= 6);
REQUIRE_FALSE(a.empty());
REQUIRE(equal_il(a, { 1, 2, 3, 4, 4, 5 }));
REQUIRE(a.count(5) == 1);

a.erase(std::prev(a.end()));
REQUIRE(a.size() == 5);
Expand All @@ -928,6 +938,7 @@ TEST_CASE("Small Multi Set") {
REQUIRE(a.capacity() >= 6);
REQUIRE_FALSE(a.empty());
REQUIRE(equal_il(a, { 1, 2, 3, 4, 4, 10 }));
REQUIRE(a.count(10) == 1);

REQUIRE(a.erase(10) == 1);
REQUIRE(a.erase(4) == 2);
Expand All @@ -936,6 +947,7 @@ TEST_CASE("Small Multi Set") {
REQUIRE(a.capacity() >= 5);
REQUIRE_FALSE(a.empty());
REQUIRE(equal_il(a, { 1, 2, 3 }));
REQUIRE(a.count(4) == 0);

std::initializer_list<int> src = { 6, 5, 7 };
a.insert(src.begin(), src.end());
Expand Down

0 comments on commit dd03342

Please sign in to comment.