You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
cache2.insert(500, "five hundred"); //inserts at addr = 0
117
136
cache2.insert(510, "five hundred and ten"); //inserts at addr = 472
@@ -124,6 +143,82 @@ class LRUCacheTestApp final : public nbl::application_templates::MonoSystemMonoL
124
143
cache2.print(m_logger);
125
144
cache2.insert(++i, "key is 112");
126
145
146
+
// Grow test - try growing the cache
147
+
m_logger->log("Growing test");
148
+
auto previousState = cache2.getState();
149
+
// Grow cache
150
+
assert(cache2.grow(10));
151
+
// Cache state should be the same
152
+
assert(cache2.getState() == previousState);
153
+
cache2.print(m_logger);
154
+
cache2.insert(++i, "key is 113");
155
+
cache2.insert(++i, "key is 114");
156
+
cache2.insert(++i, "key is 115");
157
+
cache2.insert(++i, "key is 116");
158
+
cache2.insert(++i, "key is 117");
159
+
cache2.print(m_logger);
160
+
// Should evict key 52
161
+
cache2.insert(++i, "key is 118");
162
+
cache2.print(m_logger);
163
+
constauto latestState = cache2.getState();
164
+
assert(latestState == "{21, key is 21}, {22, key is 22}, {23, key is 23}, {112, key is 112}, {113, key is 113}, {114, key is 114}, {115, key is 115}, {116, key is 116}, {117, key is 117}, {118, key is 118}");
165
+
// Invalid grow should fail
166
+
assert(!cache2.grow(5));
167
+
assert(!cache2.grow(10));
168
+
// Call a bunch of grows that shouldn't fail and some others that should
169
+
for (auto i = 1u; i < 50; i++)
170
+
{
171
+
assert(cache2.grow(50 * i));
172
+
assert(!cache2.grow(25 * i));
173
+
assert(!cache2.grow(50 * i));
174
+
assert(cache2.getState() == latestState);
175
+
}
176
+
177
+
// Single element cache test - checking for edge cases
178
+
ResizableLRUCache<int, std::string> cache3(1u);
179
+
cache3.insert(0, "foo");
180
+
cache3.insert(1, "bar");
181
+
cache3.clear();
182
+
183
+
// Besides the disposal function that gets called when evicting, we need to check that the Cache properly destroys all resident `Key,Value` pairs when destroyed
0 commit comments