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

Unified Diff: tests/lib/collection/linked_list_test.dart

Issue 13459002: Introduce new LinkedList to dart:collection. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 7 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
Index: tests/lib/collection/linked_list_test.dart
diff --git a/tests/lib/collection/linked_list_test.dart b/tests/lib/collection/linked_list_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..b041b598511f8dccbe7df741a481a32ba2311b0b
--- /dev/null
+++ b/tests/lib/collection/linked_list_test.dart
@@ -0,0 +1,126 @@
+// Copyright (c) 2013, 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.
+
+import 'dart:collection';
+
+
Lasse Reichstein Nielsen 2013/05/24 08:42:45 import "package:expect/expect.dart"; and use Expec
Anders Johnsen 2013/06/13 11:14:10 Done.
+class MyEntry extends LinkedListEntry<MyEntry> {
+ final int value;
+
+ MyEntry(int this.value);
+
+ String toString() => value.toString();
+}
+
+
+testInsert() {
+ // Insert last.
+ var list = new LinkedList<MyEntry>();
+ for (int i = 0; i < 10; i++) {
+ list.insertLast(new MyEntry(i));
+ }
+
+ if (list.length != 10) throw "bad length";
+
+ int i = 0;
+ for (var entry in list) {
+ if (entry.value != i++) throw "bad value";
+ }
+
+ if (i != 10) throw "bad length";
+
+ list.clear();
+
+ // Insert first.
+ for (int i = 0; i < 10; i++) {
+ list.insertFirst(new MyEntry(i));
+ }
+
+ if (list.length != 10) throw "bad length";
+
+ i = 10;
+ for (var entry in list) {
+ if (entry.value != --i) throw "bad value";
+ }
+ if (i != 0) throw "bad length";
+
+ list.clear();
+
+ // Insert after.
+ list.insertFirst(new MyEntry(0));
+ for (int i = 1; i < 10; i++) {
+ list.last.insertAfter(new MyEntry(i));
+ }
+
+ if (list.length != 10) throw "bad length";
+
+ i = 0;
+ for (var entry in list) {
+ if (entry.value != i++) throw "bad value";
+ }
+
+ if (i != 10) throw "bad length";
+
+ list.clear();
+
+ // Insert before.
+ list.insertFirst(new MyEntry(0));
+ for (int i = 1; i < 10; i++) {
+ list.first.insertBefore(new MyEntry(i));
+ }
+
+ if (list.length != 10) throw "bad length";
+
+ i = 10;
+ for (var entry in list) {
+ if (entry.value != --i) throw "bad value";
+ }
+ if (i != 0) throw "bad length";
+
+ list.clear();
+}
+
+
+testRemove() {
+ var list = new LinkedList<MyEntry>();
+ for (int i = 0; i < 10; i++) {
+ list.insertLast(new MyEntry(i));
+ }
+
+ if (list.length != 10) throw "bad length";
+
+ list.remove(list.skip(5).first);
+
+ if (list.length != 9) throw "bad length";
+
+ int i = 0;
+ for (var entry in list) {
+ if (i == 5) i++;
+ if (entry.value != i++) throw "bad value";
+ }
+}
+
+
+testBadAdd() {
+ print("here");
+ var list1 = new LinkedList<MyEntry>();
+ list1.insertFirst(new MyEntry(0));
+
+ var list2 = new LinkedList<MyEntry>();
+ bool failed = false;
+ try {
+ list2.insertFirst(list1.first);
+ } on StateError catch (e) {
+ print(e);
+ failed = true;
+ }
+ if (!failed) throw "fail expected";
+}
+
Lasse Reichstein Nielsen 2013/05/24 08:42:45 Test concurrent modification throws for all iterat
Anders Johnsen 2013/06/13 11:14:10 Done.
+
+main() {
+ testInsert();
+ testRemove();
+ testBadAdd();
+}

Powered by Google App Engine
This is Rietveld 408576698