8#include <framework/core/MRUCache.h>
9#include <gtest/gtest.h>
21 cache.insert(
"foo",
"bar");
23 EXPECT_FALSE(cache.retrieve(
"foobar", result));
24 EXPECT_EQ(result,
"boo");
25 EXPECT_TRUE(cache.retrieve(
"foo", result));
26 EXPECT_EQ(result,
"bar");
33 for (
int i = 0; i < 10; ++i) {
37 EXPECT_EQ(cache.size(), 5u);
39 for (
int i = 9; i >= 5; --i) {
40 EXPECT_EQ(it->first, i);
41 EXPECT_EQ(it->second, -i);
45 EXPECT_TRUE(cache.retrieve(5, var));
46 EXPECT_EQ(cache.begin()->first, 5);
47 EXPECT_EQ(cache.begin()->second, -5);
50 EXPECT_EQ(cache.size(), 0u);
52 EXPECT_FALSE(cache.retrieve(5, var));
62 EXPECT_EQ(cache.size(), 1u);
63 EXPECT_TRUE(cache.retrieve(1, var));
66 EXPECT_EQ(cache.size(), 1u);
67 EXPECT_TRUE(cache.retrieve(1, var));
77 EXPECT_EQ(cache.getHits(), 0u);
78 EXPECT_EQ(cache.getMisses(), 0u);
79 EXPECT_EQ(cache.getOverflows(), 0u);
81 cache.retrieve(0, var);
82 EXPECT_EQ(cache.getMisses(), 1u);
83 cache.retrieve(0, var);
84 EXPECT_EQ(cache.getMisses(), 2u);
87 EXPECT_EQ(cache.getOverflows(), 0u);
89 EXPECT_EQ(cache.getOverflows(), 1u);
91 EXPECT_EQ(cache.getOverflows(), 2u);
93 cache.retrieve(0, var);
94 EXPECT_EQ(cache.getHits(), 1u);
95 cache.retrieve(0, var);
96 EXPECT_EQ(cache.getHits(), 2u);
99 EXPECT_EQ(cache.getHits(), 0u);
100 EXPECT_EQ(cache.getMisses(), 0u);
101 EXPECT_EQ(cache.getOverflows(), 0u);
Class implementing a generic Most Recently Used cache.
container_type::const_iterator iterator
iterator over all cached items, sorted by access: most recent used first
Abstract base class for different kinds of events.