Skip to content

Commit 5ef9452

Browse files
committed
add: add missing test cases for lru_cache
1 parent e1117fc commit 5ef9452

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

tests/structures_lru_cache.cpp

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,12 @@ bool is_even(int const& x) {
2323
TEST(util_lru_cache, put_get) {
2424
es::lru_cache<int, int> cache(3);
2525
ASSERT_EQ(cache.size(), 0);
26-
26+
ASSERT_EQ(cache.get(1), nullptr);
27+
int const one = 1;
28+
int const three = 3;
29+
int const seven = 7;
2730
//---------------------------------
28-
cache.put(1, 1);
31+
cache.put(1, one);
2932
cache.put(2, 2);
3033
cache.put(3, 3);
3134

@@ -52,7 +55,7 @@ TEST(util_lru_cache, put_get) {
5255
//---------------------------------
5356
// trigger splice
5457
cache.put(3, 3);
55-
cache.put(3, 3);
58+
cache.put(three, three);
5659
cache.put(4, 4);
5760

5861
ASSERT_EQ(cache.size(), 3);
@@ -62,6 +65,17 @@ TEST(util_lru_cache, put_get) {
6265
ASSERT_EQ(*cache.get(3), 3);
6366
ASSERT_NE(cache.get(4), nullptr);
6467
ASSERT_EQ(*cache.get(4), 4);
68+
//---------------------------------
69+
cache.put(7, seven);
70+
71+
ASSERT_EQ(cache.size(), 3);
72+
ASSERT_EQ(cache.get(2), nullptr);
73+
ASSERT_NE(cache.get(3), nullptr);
74+
ASSERT_EQ(*cache.get(3), 3);
75+
ASSERT_NE(cache.get(4), nullptr);
76+
ASSERT_EQ(*cache.get(4), 4);
77+
ASSERT_NE(cache.get(7), nullptr);
78+
ASSERT_EQ(*cache.get(7), 7);
6579
}
6680

6781
TEST(util_lru_cache, get_update_and_get_remove) {
@@ -82,6 +96,9 @@ TEST(util_lru_cache, get_update_and_get_remove) {
8296
//---------------------------------
8397
ASSERT_EQ(cache.remove_all_matching(is_even), 2);
8498
ASSERT_EQ(cache.size(), 0);
99+
100+
//---------------------------------
101+
ASSERT_EQ(cache.get_update(666, times_2), nullptr);
85102
}
86103

87104
TEST(util_lru_cache, update) {
@@ -103,6 +120,10 @@ TEST(util_lru_cache, update) {
103120
ASSERT_EQ(*cache.get(2), 200);
104121
ASSERT_EQ(*cache.get(4), 4);
105122
ASSERT_EQ(*cache.get(3), 300);
123+
//---------------------------------
124+
*cache.get_mut(3) = 333;
125+
ASSERT_EQ(*cache.get(3), 333);
126+
ASSERT_EQ(cache.get_mut(666), nullptr);
106127
}
107128

108129
TEST(util_lru_cache, remove) {

0 commit comments

Comments
 (0)