| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 library test.index.lru_cache; |
| 6 |
| 7 import 'package:analysis_server/src/index/lru_cache.dart'; |
| 8 import 'package:unittest/unittest.dart'; |
| 9 |
| 10 import '../reflective_tests.dart'; |
| 11 |
| 12 |
| 13 main() { |
| 14 groupSep = ' | '; |
| 15 group('FixedStringCodecTest', () { |
| 16 runReflectiveTests(_LRUCacheTest); |
| 17 }); |
| 18 } |
| 19 |
| 20 |
| 21 @ReflectiveTestCase() |
| 22 class _LRUCacheTest { |
| 23 LRUCache<int, String> cache = new LRUCache<int, String>(3); |
| 24 |
| 25 void test_evict() { |
| 26 List<int> evictedKeys = new List<int>(); |
| 27 List<String> evictedValues = new List<String>(); |
| 28 cache = new LRUCache<int, String>(3, (int key, String value) { |
| 29 evictedKeys.add(key); |
| 30 evictedValues.add(value); |
| 31 }); |
| 32 // fill |
| 33 cache.put(1, 'A'); |
| 34 cache.put(2, 'B'); |
| 35 cache.put(3, 'C'); |
| 36 // access '1' and '3' |
| 37 cache.get(1); |
| 38 cache.get(3); |
| 39 // put '4', evict '2' |
| 40 cache.put(4, 'D'); |
| 41 expect(cache.get(1), 'A'); |
| 42 expect(cache.get(2), isNull); |
| 43 expect(cache.get(3), 'C'); |
| 44 expect(cache.get(4), 'D'); |
| 45 // check eviction listener |
| 46 expect(evictedKeys, contains(2)); |
| 47 expect(evictedValues, contains('B')); |
| 48 } |
| 49 |
| 50 void test_putGet() { |
| 51 // fill |
| 52 cache.put(1, 'A'); |
| 53 cache.put(2, 'B'); |
| 54 cache.put(3, 'C'); |
| 55 // check |
| 56 expect(cache.get(1), 'A'); |
| 57 expect(cache.get(2), 'B'); |
| 58 expect(cache.get(3), 'C'); |
| 59 expect(cache.get(4), isNull); |
| 60 } |
| 61 |
| 62 void test_remove() { |
| 63 cache.put(1, 'A'); |
| 64 cache.put(2, 'B'); |
| 65 cache.put(3, 'C'); |
| 66 // remove |
| 67 cache.remove(1); |
| 68 cache.remove(3); |
| 69 // check |
| 70 expect(cache.get(1), isNull); |
| 71 expect(cache.get(2), 'B'); |
| 72 expect(cache.get(3), isNull); |
| 73 } |
| 74 } |
| OLD | NEW |