Skip to content

Commit

Permalink
fbcode//fb303/test:simple_lru_map_test
Browse files Browse the repository at this point in the history
Reviewed By: cjhawley

Differential Revision: D68272450

fbshipit-source-id: b272749100d5420a64b8148f137fc9275ac6fb3b
  • Loading branch information
generatedunixname89002005287564 authored and facebook-github-bot committed Jan 21, 2025
1 parent bebde3d commit dab4880
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions fb303/test/SimpleLRUMapTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -677,75 +677,75 @@ TEST(SimpleLRUMap, MapGet) {
TEST(SimpleLRUMap, MapGetPtr) {
lru_map lru(2);

auto out = stl::mapGetPtr(as_const(lru), 0);
auto out = folly::get_ptr(as_const(lru), 0);
EXPECT_EQ(nullptr, out);
checkContents(lru, {});

lru.set(0, "0");
checkContents(lru, {{0, "0"}});
out = stl::mapGetPtr(as_const(lru), 0);
out = folly::get_ptr(as_const(lru), 0);
EXPECT_NE(nullptr, out);
EXPECT_EQ("0", *out);
checkContents(lru, {{0, "0"}});

lru.set(1, "1");
checkContents(lru, {{1, "1"}, {0, "0"}});
out = stl::mapGetPtr(as_const(lru), 1);
out = folly::get_ptr(as_const(lru), 1);
EXPECT_NE(nullptr, out);
EXPECT_EQ("1", *out);
checkContents(lru, {{1, "1"}, {0, "0"}});
out = stl::mapGetPtr(as_const(lru), 0);
out = folly::get_ptr(as_const(lru), 0);
EXPECT_NE(nullptr, out);
EXPECT_EQ("0", *out);
checkContents(lru, {{1, "1"}, {0, "0"}});

out = stl::mapGetPtr(as_const(lru), 9);
out = folly::get_ptr(as_const(lru), 9);
EXPECT_EQ(nullptr, out);
checkContents(lru, {{1, "1"}, {0, "0"}});
}

TEST(SimpleLRUMap, MapGetDefault) {
lru_map lru(2);

EXPECT_EQ("x", stl::mapGetDefault(lru, 0, "x"));
EXPECT_EQ("x", folly::get_default(lru, 0, "x"));
checkContents(lru, {});

lru.set(0, "0");
checkContents(lru, {{0, "0"}});
EXPECT_EQ("0", stl::mapGetDefault(lru, 0, "x"));
EXPECT_EQ("0", folly::get_default(lru, 0, "x"));
checkContents(lru, {{0, "0"}});

lru.set(1, "1");
checkContents(lru, {{1, "1"}, {0, "0"}});
EXPECT_EQ("1", stl::mapGetDefault(lru, 1, "x"));
EXPECT_EQ("1", folly::get_default(lru, 1, "x"));
checkContents(lru, {{1, "1"}, {0, "0"}});
EXPECT_EQ("0", stl::mapGetDefault(lru, 0, "x"));
EXPECT_EQ("0", folly::get_default(lru, 0, "x"));
checkContents(lru, {{1, "1"}, {0, "0"}});

EXPECT_EQ("x", stl::mapGetDefault(lru, 9, "x"));
EXPECT_EQ("x", folly::get_default(lru, 9, "x"));
checkContents(lru, {{1, "1"}, {0, "0"}});
}

TEST(SimpleLRUMap, MapGetRefDefault) {
lru_map lru(2);

const std::string x = "x";
EXPECT_EQ("x", stl::mapGetRefDefault(lru, 0, x));
EXPECT_EQ("x", folly::get_ref_default(lru, 0, x));
checkContents(lru, {});

lru.set(0, "0");
checkContents(lru, {{0, "0"}});
EXPECT_EQ("0", stl::mapGetRefDefault(lru, 0, x));
EXPECT_EQ("0", folly::get_ref_default(lru, 0, x));
checkContents(lru, {{0, "0"}});

lru.set(1, "1");
checkContents(lru, {{1, "1"}, {0, "0"}});
EXPECT_EQ("1", stl::mapGetRefDefault(lru, 1, x));
EXPECT_EQ("1", folly::get_ref_default(lru, 1, x));
checkContents(lru, {{1, "1"}, {0, "0"}});
EXPECT_EQ("0", stl::mapGetRefDefault(lru, 0, x));
EXPECT_EQ("0", folly::get_ref_default(lru, 0, x));
checkContents(lru, {{1, "1"}, {0, "0"}});

EXPECT_EQ("x", stl::mapGetRefDefault(lru, 9, x));
EXPECT_EQ("x", folly::get_ref_default(lru, 9, x));
checkContents(lru, {{1, "1"}, {0, "0"}});
}

Expand Down

0 comments on commit dab4880

Please sign in to comment.