s0146
All checks were successful
ci/woodpecker/push/deploy Pipeline was successful
ci/woodpecker/push/test Pipeline was successful

This commit is contained in:
2023-03-18 08:40:30 +08:00
parent a99d75b44c
commit bef47e10bf
5 changed files with 270 additions and 0 deletions

26
tests/s0146_lru_cache.cpp Normal file
View File

@@ -0,0 +1,26 @@
#include "s0146_lru_cache.hpp"
#include <gtest/gtest.h>
TEST(Problem146, Case1) {
LRUCache *lru = new LRUCache(2);
lru->put(1, 1);
lru->put(2, 2);
EXPECT_EQ(lru->get(1), 1);
lru->put(3, 3);
EXPECT_EQ(lru->get(2), -1);
lru->put(4, 4);
EXPECT_EQ(lru->get(1), -1);
EXPECT_EQ(lru->get(3), 3);
EXPECT_EQ(lru->get(4), 4);
}
TEST(Problem146, Case2) {
LRUCache *lru = new LRUCache(2);
lru->put(2, 1);
lru->put(1, 1);
lru->put(2, 3);
lru->put(4, 1);
EXPECT_EQ(lru->get(1), -1);
EXPECT_EQ(lru->get(2), 3);
}