MCPcopy Create free account
hub / github.com/bytedance/bolt / TEST

Function TEST

bolt/common/caching/tests/SimpleLRUCacheTest.cpp:50–85  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

48} // namespace
49
50TEST(SimpleLRUCache, basicCaching) {
51 SimpleLRUCache<int, int> cache(1000);
52
53 EXPECT_FALSE(cache.get(1).has_value());
54 EXPECT_FALSE(cache.get(2).has_value());
55
56 verifyCacheStats(cache.getStats(), 1000, 0, 0, 2);
57
58 int firstValue = 11;
59 ASSERT_TRUE(cache.add(1, firstValue));
60 auto value = cache.get(1);
61 ASSERT_EQ(value, std::make_optional(11));
62
63 int secondValue = 22;
64 ASSERT_TRUE(cache.add(2, secondValue));
65
66 verifyCacheStats(cache.getStats(), 1000, 2, 1, 3);
67
68 value = cache.get(1);
69 ASSERT_EQ(value, std::make_optional(11));
70
71 value = cache.get(2);
72 ASSERT_EQ(value, std::make_optional(22));
73
74 value = cache.get(1);
75 ASSERT_EQ(value, std::make_optional(11));
76
77 value = cache.get(2);
78 ASSERT_EQ(value, std::make_optional(22));
79 verifyCacheStats(cache.getStats(), 1000, 2, 5, 7);
80
81 cache.clear();
82 verifyCacheStats(cache.getStats(), 1000, 0, 5, 7);
83 EXPECT_FALSE(cache.get(1).has_value());
84 EXPECT_FALSE(cache.get(2).has_value());
85}
86
87TEST(SimpleLRUCache, eviction) {
88 SimpleLRUCache<int, int> cache(1000);

Callers

nothing calls this directly

Calls 6

has_valueMethod · 0.80
verifyCacheStatsFunction · 0.70
getMethod · 0.45
getStatsMethod · 0.45
addMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected