Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(240)

Side by Side Diff: pkg/analysis_server/test/index/lru_cache_test.dart

Issue 365193004: Move Index and IndexStore implementations into Engine. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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('LRUCache', () {
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_notGet() {
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_evict_notPut() {
51 List<int> evictedKeys = new List<int>();
52 List<String> evictedValues = new List<String>();
53 cache = new LRUCache<int, String>(3, (int key, String value) {
54 evictedKeys.add(key);
55 evictedValues.add(value);
56 });
57 // fill
58 cache.put(1, 'A');
59 cache.put(2, 'B');
60 cache.put(3, 'C');
61 // put '1' and '3'
62 cache.put(1, 'AA');
63 cache.put(3, 'CC');
64 // put '4', evict '2'
65 cache.put(4, 'D');
66 expect(cache.get(1), 'AA');
67 expect(cache.get(2), isNull);
68 expect(cache.get(3), 'CC');
69 expect(cache.get(4), 'D');
70 // check eviction listener
71 expect(evictedKeys, contains(2));
72 expect(evictedValues, contains('B'));
73 }
74
75 void test_putGet() {
76 // fill
77 cache.put(1, 'A');
78 cache.put(2, 'B');
79 cache.put(3, 'C');
80 // check
81 expect(cache.get(1), 'A');
82 expect(cache.get(2), 'B');
83 expect(cache.get(3), 'C');
84 expect(cache.get(4), isNull);
85 }
86
87 void test_remove() {
88 cache.put(1, 'A');
89 cache.put(2, 'B');
90 cache.put(3, 'C');
91 // remove
92 cache.remove(1);
93 cache.remove(3);
94 // check
95 expect(cache.get(1), isNull);
96 expect(cache.get(2), 'B');
97 expect(cache.get(3), isNull);
98 }
99 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698