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

Side by Side Diff: test/codegen/lib/collection/linked_list_test.dart

Issue 1977003002: Update dart:collection. (Closed) Base URL: https://github.com/dart-lang/dev_compiler.git@master
Patch Set: Created 4 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2013, 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 import 'dart:collection';
6 import "package:expect/expect.dart";
7
8 class MyEntry extends LinkedListEntry<MyEntry> {
9 final int value;
10
11 MyEntry(int this.value);
12
13 String toString() => value.toString();
14 }
15
16
17 testInsert() {
18 // Insert last.
19 var list = new LinkedList<MyEntry>();
20 for (int i = 0; i < 10; i++) {
21 list.add(new MyEntry(i));
22 }
23
24 Expect.equals(10, list.length);
25
26 int i = 0;
27 for (var entry in list) {
28 Expect.equals(i, entry.value);
29 i++;
30 }
31
32 Expect.equals(10, i);
33
34 list.clear();
35
36 // Insert first.
37 for (int i = 0; i < 10; i++) {
38 list.addFirst(new MyEntry(i));
39 }
40
41 Expect.equals(10, list.length);
42
43 i = 10;
44 for (var entry in list) {
45 Expect.equals(--i, entry.value);
46 }
47 Expect.equals(0, i);
48
49 list.clear();
50
51 // Insert after.
52 list.addFirst(new MyEntry(0));
53 for (int i = 1; i < 10; i++) {
54 list.last.insertAfter(new MyEntry(i));
55 }
56
57 Expect.equals(10, list.length);
58
59 i = 0;
60 for (var entry in list) {
61 Expect.equals(i, entry.value);
62 i++;
63 }
64
65 Expect.equals(10, i);
66
67 list.clear();
68
69 // Insert before.
70 list.addFirst(new MyEntry(0));
71 for (int i = 1; i < 10; i++) {
72 list.first.insertBefore(new MyEntry(i));
73 }
74
75 Expect.equals(10, list.length);
76
77 i = 10;
78 for (var entry in list) {
79 Expect.equals(--i, entry.value);
80 }
81 Expect.equals(0, i);
82
83 list.clear();
84 }
85
86
87 testRemove() {
88 var list = new LinkedList<MyEntry>();
89 for (int i = 0; i < 10; i++) {
90 list.add(new MyEntry(i));
91 }
92
93 Expect.equals(10, list.length);
94
95 list.remove(list.skip(5).first);
96
97 Expect.equals(9, list.length);
98
99 int i = 0;
100 for (var entry in list) {
101 if (i == 5) i++;
102 Expect.equals(i, entry.value);
103 i++;
104 }
105
106 Expect.listEquals([0, 1, 2, 3, 4, 6, 7, 8, 9],
107 list.map((e) => e.value).toList());
108
109 for (int i = 0; i < 9; i++) {
110 list.first.unlink();
111 }
112
113 Expect.throws(() => list.first);
114
115 Expect.equals(0, list.length);
116 }
117
118
119 testBadAdd() {
120 var list1 = new LinkedList<MyEntry>();
121 list1.addFirst(new MyEntry(0));
122
123 var list2 = new LinkedList<MyEntry>();
124 Expect.throws(() => list2.addFirst(list1.first));
125
126 Expect.throws(() => new MyEntry(0).unlink());
127 }
128
129 testConcurrentModificationError() {
130
131 test(function(LinkedList ll)) {
132 var ll = new LinkedList<MyEntry>();
133 for (int i = 0; i < 10; i++) {
134 ll.add(new MyEntry(i));
135 }
136 Expect.throws(() => function(ll), (e) => e is ConcurrentModificationError);
137 }
138 test((ll) { for(var x in ll) { ll.remove(x); } });
139 test((ll) { ll.forEach((x) { ll.remove(x); }); });
140 test((ll) { ll.any((x) { ll.remove(x); return false; }); });
141 test((ll) { ll.every((x) { ll.remove(x); return true; }); });
142 test((ll) { ll.fold(0, (x, y) { ll.remove(y); return x; }); });
143 test((ll) { ll.reduce((x, y) { ll.remove(y); return x; }); });
144 test((ll) { ll.where((x) { ll.remove(x); return true; }).forEach((_) {}); });
145 test((ll) { ll.map((x) { ll.remove(x); return x; }).forEach((_) {}); });
146 test((ll) { ll.expand((x) { ll.remove(x); return[x];}).forEach((_) {}); });
147 test((ll) { ll.takeWhile((x) {
148 ll.remove(x); return true;}).forEach((_) {}); });
149 test((ll) { ll.skipWhile((x) {
150 ll.remove(x); return true;}).forEach((_) {}); });
151 test((ll) {
152 bool first = true;
153 ll.firstWhere((x) {
154 ll.remove(x);
155 if (!first) return true;
156 return first = false;
157 });
158 });
159 test((ll) { ll.lastWhere((x) { ll.remove(x); return true;}); });
160 test((ll) {
161 bool first = true;
162 ll.singleWhere((x) {
163 ll.remove(x);
164 if (!first) return false;
165 return !(first = false);
166 });
167 });
168 }
169
170 main() {
171 testInsert();
172 testRemove();
173 testBadAdd();
174 testConcurrentModificationError();
175 }
OLDNEW
« no previous file with comments | « test/codegen/lib/collection/hash_set_test.dart ('k') | tool/input_sdk/lib/collection/hash_map.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698