• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright 2019 The TensorFlow Authors. All Rights Reserved.
2 
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
6 
7     http://www.apache.org/licenses/LICENSE-2.0
8 
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License.
14 ==============================================================================*/
15 
16 #include "tensorflow/compiler/tf2tensorrt/utils/trt_lru_cache.h"
17 
18 #include "tensorflow/core/platform/test.h"
19 
20 namespace tensorflow {
21 namespace tensorrt {
22 
TEST(LRUCacheTest,Basic)23 TEST(LRUCacheTest, Basic) {
24   LRUCache<int, int, std::hash<int>> cache;
25   cache.reserve(2);
26   // Insert 10
27   cache.emplace(10, 100);
28   EXPECT_EQ(cache.size(), 1);
29   EXPECT_EQ(cache.count(10), 1);
30   EXPECT_EQ(cache.at(10), 100);
31   EXPECT_EQ(cache.count(100), 0);
32   // Insert 20
33   cache.emplace(20, 200);
34   EXPECT_EQ(cache.size(), 2);
35   EXPECT_EQ(cache.count(10), 1);
36   EXPECT_EQ(cache.count(20), 1);
37   EXPECT_EQ(cache.at(10), 100);
38   EXPECT_EQ(cache.at(20), 200);
39   EXPECT_EQ(cache.count(100), 0);
40   EXPECT_EQ(cache.count(200), 0);
41   // Insert 30, Evicting 10
42   cache.emplace(30, 300);
43   EXPECT_EQ(cache.count(10), 0);
44   EXPECT_EQ(cache.count(20), 1);
45   EXPECT_EQ(cache.count(30), 1);
46   // Touch 20
47   cache.at(20);
48   // Insert 40, Evicting 30
49   cache.emplace(40, 400);
50   EXPECT_EQ(cache.count(10), 0);
51   EXPECT_EQ(cache.count(20), 1);
52   EXPECT_EQ(cache.count(30), 0);
53   EXPECT_EQ(cache.count(40), 1);
54 }
55 
56 }  // namespace tensorrt
57 }  // namespace tensorflow
58