Skip to content

Commit 960b849

Browse files
committed
test: add test to cover exception
1 parent 7d347cd commit 960b849

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

others/lru_cache2.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,12 +247,17 @@ static void test() {
247247
assert(cache.capacity() == 5);
248248
assert(!cache.empty());
249249

250-
// test retrieval of all items in the cache
251250
// fetching 1 throws runtime_error
252251
// as 1 was evicted being the least recently used
253252
// when 6 was added
254-
// assert(cache.get(1) == 10);
253+
try {
254+
cache.get(1);
255+
assert(false);
256+
} catch (const std::runtime_error &e) {
257+
std::cout << "Expected - std::runtime_error\n";
258+
}
255259

260+
// test retrieval of all items in the cache
256261
assert(cache.get(-2) == 20);
257262
assert(cache.get(-3) == -30);
258263
assert(cache.get(4) == 40);

0 commit comments

Comments
 (0)