27 lines
535 B
C++
27 lines
535 B
C++
#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);
|
|
}
|