Skip to content

Commit

Permalink
Add a simple test and fix test naming.
Browse files Browse the repository at this point in the history
  • Loading branch information
fruffy committed Dec 14, 2023
1 parent 6fc151c commit 45194f8
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions test/gtest/ordered_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ limitations under the License.

namespace Test {

TEST(ordered_map, map_equal) {
TEST(OrderedMap, MapEqual) {
ordered_map<unsigned, unsigned> a;
ordered_map<unsigned, unsigned> b;

Expand Down Expand Up @@ -49,7 +49,7 @@ TEST(ordered_map, map_equal) {
EXPECT_TRUE(a == b);
}

TEST(ordered_map, map_not_equal) {
TEST(OrderedMap, MapNotEqual) {
ordered_map<unsigned, unsigned> a;
ordered_map<unsigned, unsigned> b;

Expand Down Expand Up @@ -116,11 +116,11 @@ TEST(ordered_map, map_not_equal) {
EXPECT_TRUE(a != b);
}

TEST(ordered_map, insert_emplace_erase) {
TEST(OrderedMap, InsertEmplaceErase) {
ordered_map<unsigned, unsigned> om;
std::map<unsigned, unsigned> sm;

typename ordered_map<unsigned, unsigned>::const_iterator it = om.end();
auto it = om.end();
for (auto v : {0, 1, 2, 3, 4, 5, 6, 7, 8}) {
sm.emplace(v, 2 * v);
std::pair<unsigned, unsigned> pair{v, 2 * v};
Expand All @@ -134,7 +134,7 @@ TEST(ordered_map, insert_emplace_erase) {
if ((v / 2) % 2 == 0) {
it = om.insert(std::move(pair)).first;
} else {
it = om.emplace(std::move(v), v * 2).first;
it = om.emplace(v, v * 2).first;
}
}
}
Expand All @@ -149,4 +149,18 @@ TEST(ordered_map, insert_emplace_erase) {
EXPECT_TRUE(std::equal(om.begin(), om.end(), sm.begin(), sm.end()));
}

TEST(OrderedMap, ExistingKey) {
ordered_map<int, std::string> myMap{{1, "One"}, {2, "Two"}, {3, "Three"}};

EXPECT_EQ(get(myMap, 1), "One");
EXPECT_EQ(get(myMap, 2), "Two");
EXPECT_EQ(get(myMap, 3), "Three");
}

TEST(OrderedMap, NonExistingKey) {
ordered_map<int, std::string> myMap{{1, "One"}, {2, "Two"}, {3, "Three"}};

EXPECT_EQ(get(myMap, 4), "");
}

} // namespace Test

0 comments on commit 45194f8

Please sign in to comment.