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

Unified Diff: packages/analyzer/test/src/util/lru_map_test.dart

Issue 1400473008: Roll Observatory packages and add a roll script (Closed) Base URL: git@github.com:dart-lang/observatory_pub_packages.git@master
Patch Set: Created 5 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « packages/analyzer/test/src/util/asserts_test.dart ('k') | packages/analyzer/test/src/util/test_all.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: packages/analyzer/test/src/util/lru_map_test.dart
diff --git a/packages/analyzer/test/src/util/lru_map_test.dart b/packages/analyzer/test/src/util/lru_map_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..ef580a0d4322eef140dcc7592200ddcd0008f83a
--- /dev/null
+++ b/packages/analyzer/test/src/util/lru_map_test.dart
@@ -0,0 +1,96 @@
+// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+library test.src.util.lru_map;
+
+import 'package:analyzer/src/util/lru_map.dart';
+import 'package:unittest/unittest.dart';
+
+import '../../reflective_tests.dart';
+import '../../utils.dart';
+
+main() {
+ initializeTestEnvironment();
+ runReflectiveTests(_LRUCacheTest);
+}
+
+@reflectiveTest
+class _LRUCacheTest {
+ LRUMap<int, String> cache = new LRUMap<int, String>(3);
+
+ void test_evict_notGet() {
+ List<int> evictedKeys = new List<int>();
+ List<String> evictedValues = new List<String>();
+ cache = new LRUMap<int, String>(3, (int key, String value) {
+ evictedKeys.add(key);
+ evictedValues.add(value);
+ });
+ // fill
+ cache.put(1, 'A');
+ cache.put(2, 'B');
+ cache.put(3, 'C');
+ // access '1' and '3'
+ cache.get(1);
+ cache.get(3);
+ // put '4', evict '2'
+ cache.put(4, 'D');
+ expect(cache.get(1), 'A');
+ expect(cache.get(2), isNull);
+ expect(cache.get(3), 'C');
+ expect(cache.get(4), 'D');
+ // check eviction listener
+ expect(evictedKeys, contains(2));
+ expect(evictedValues, contains('B'));
+ }
+
+ void test_evict_notPut() {
+ List<int> evictedKeys = new List<int>();
+ List<String> evictedValues = new List<String>();
+ cache = new LRUMap<int, String>(3, (int key, String value) {
+ evictedKeys.add(key);
+ evictedValues.add(value);
+ });
+ // fill
+ cache.put(1, 'A');
+ cache.put(2, 'B');
+ cache.put(3, 'C');
+ // put '1' and '3'
+ cache.put(1, 'AA');
+ cache.put(3, 'CC');
+ // put '4', evict '2'
+ cache.put(4, 'D');
+ expect(cache.get(1), 'AA');
+ expect(cache.get(2), isNull);
+ expect(cache.get(3), 'CC');
+ expect(cache.get(4), 'D');
+ // check eviction listener
+ expect(evictedKeys, contains(2));
+ expect(evictedValues, contains('B'));
+ }
+
+ void test_putGet() {
+ // fill
+ cache.put(1, 'A');
+ cache.put(2, 'B');
+ cache.put(3, 'C');
+ // check
+ expect(cache.get(1), 'A');
+ expect(cache.get(2), 'B');
+ expect(cache.get(3), 'C');
+ expect(cache.get(4), isNull);
+ }
+
+ void test_remove() {
+ cache.put(1, 'A');
+ cache.put(2, 'B');
+ cache.put(3, 'C');
+ // remove
+ cache.remove(1);
+ cache.remove(3);
+ // check
+ expect(cache.get(1), isNull);
+ expect(cache.get(2), 'B');
+ expect(cache.get(3), isNull);
+ }
+}
« no previous file with comments | « packages/analyzer/test/src/util/asserts_test.dart ('k') | packages/analyzer/test/src/util/test_all.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698