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

Side by Side Diff: tests/corelib_strong/iterable_skip_test.dart

Issue 3000543002: Migrate test block 11 to Dart 2.0. (Closed)
Patch Set: Fix merge problems and update test status with head changes Created 3 years, 4 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
« no previous file with comments | « tests/corelib_strong/iterable_single_where_test.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2012, 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 "package:expect/expect.dart";
6
7 main() {
8 List<int> list1 = <int>[1, 2, 3];
9 List<int> list2 = const <int>[4, 5];
10 List<String> list3 = <String>[];
11 Set<int> set1 = new Set<int>();
12 set1..add(11)..add(12)..add(13);
13 Set set2 = new Set();
14
15 Iterable<int> skip0 = list1.skip(0);
16 Expect.isTrue(skip0 is! List);
17 Iterator<int> it = skip0.iterator;
18 Expect.isNull(it.current);
19 Expect.isTrue(it.moveNext());
20 Expect.equals(1, it.current);
21 Expect.isTrue(it.moveNext());
22 Expect.equals(2, it.current);
23 Expect.isTrue(it.moveNext());
24 Expect.equals(3, it.current);
25 Expect.isFalse(it.moveNext());
26 Expect.isNull(it.current);
27
28 Iterable<int> skip1 = list1.skip(1);
29 Expect.isTrue(skip1 is! List);
30 Expect.isTrue(skip1.skip(2).skip(1) is! List);
31 it = skip1.iterator;
32 Expect.isNull(it.current);
33 Expect.isTrue(it.moveNext());
34 Expect.equals(2, it.current);
35 Expect.isTrue(it.moveNext());
36 Expect.equals(3, it.current);
37 Expect.isFalse(it.moveNext());
38 Expect.isNull(it.current);
39
40 Iterable<int> skip2 = list1.skip(2);
41 Expect.isTrue(skip2 is! List);
42 Expect.isTrue(skip2.skip(2).skip(1) is! List);
43 it = skip2.iterator;
44 Expect.isNull(it.current);
45 Expect.isTrue(it.moveNext());
46 Expect.equals(3, it.current);
47 Expect.isFalse(it.moveNext());
48 Expect.isNull(it.current);
49
50 Iterable<int> skip3 = list1.skip(3);
51 Expect.isTrue(skip3 is! List);
52 Expect.isTrue(skip3.skip(2).skip(1) is! List);
53 it = skip3.iterator;
54 Expect.isNull(it.current);
55 Expect.isFalse(it.moveNext());
56 Expect.isNull(it.current);
57
58 Iterable<int> skip4 = list1.skip(4);
59 Expect.isTrue(skip4 is! List);
60 Expect.isTrue(skip4.skip(2).skip(1) is! List);
61 it = skip4.iterator;
62 Expect.isNull(it.current);
63 Expect.isFalse(it.moveNext());
64 Expect.isNull(it.current);
65
66 skip0 = list1.skip(0);
67 skip1 = skip0.skip(1);
68 skip2 = skip1.skip(1);
69 skip3 = skip2.skip(1);
70 skip4 = skip3.skip(1);
71 it = skip0.iterator;
72 Expect.isNull(it.current);
73 Expect.isTrue(it.moveNext());
74 Expect.equals(1, it.current);
75 Expect.isTrue(it.moveNext());
76 Expect.equals(2, it.current);
77 Expect.isTrue(it.moveNext());
78 Expect.equals(3, it.current);
79 Expect.isFalse(it.moveNext());
80 Expect.isNull(it.current);
81 it = skip1.iterator;
82 Expect.isNull(it.current);
83 Expect.isTrue(it.moveNext());
84 Expect.equals(2, it.current);
85 Expect.isTrue(it.moveNext());
86 Expect.equals(3, it.current);
87 Expect.isFalse(it.moveNext());
88 Expect.isNull(it.current);
89 it = skip2.iterator;
90 Expect.isNull(it.current);
91 Expect.isTrue(it.moveNext());
92 Expect.equals(3, it.current);
93 Expect.isFalse(it.moveNext());
94 Expect.isNull(it.current);
95 it = skip3.iterator;
96 Expect.isNull(it.current);
97 Expect.isFalse(it.moveNext());
98 Expect.isNull(it.current);
99 it = skip4.iterator;
100 Expect.isNull(it.current);
101 Expect.isFalse(it.moveNext());
102 Expect.isNull(it.current);
103
104 skip0 = list2.skip(0);
105 Expect.isTrue(skip0 is! List);
106 Expect.isTrue(skip0.skip(2).skip(1) is! List);
107 it = skip0.iterator;
108 Expect.isNull(it.current);
109 Expect.isTrue(it.moveNext());
110 Expect.equals(4, it.current);
111 Expect.isTrue(it.moveNext());
112 Expect.equals(5, it.current);
113 Expect.isFalse(it.moveNext());
114 Expect.isNull(it.current);
115
116 skip1 = list2.skip(1);
117 Expect.isTrue(skip1 is! List);
118 Expect.isTrue(skip1.skip(2).skip(1) is! List);
119 it = skip1.iterator;
120 Expect.isNull(it.current);
121 Expect.isTrue(it.moveNext());
122 Expect.equals(5, it.current);
123 Expect.isFalse(it.moveNext());
124 Expect.isNull(it.current);
125
126 skip2 = list2.skip(2);
127 Expect.isTrue(skip2 is! List);
128 Expect.isTrue(skip2.skip(2).skip(1) is! List);
129 it = skip2.iterator;
130 Expect.isNull(it.current);
131 Expect.isFalse(it.moveNext());
132 Expect.isNull(it.current);
133
134 skip3 = list2.skip(3);
135 Expect.isTrue(skip3 is! List);
136 Expect.isTrue(skip3.skip(2).skip(1) is! List);
137 it = skip3.iterator;
138 Expect.isNull(it.current);
139 Expect.isFalse(it.moveNext());
140 Expect.isNull(it.current);
141
142 Iterable<String> skip02 = list3.skip(0);
143 Expect.isTrue(skip02 is! List);
144 Expect.isTrue(skip02.skip(2).skip(1) is! List);
145 Iterator<String> it2 = skip02.iterator;
146 Expect.isNull(it2.current);
147 Expect.isFalse(it2.moveNext());
148 Expect.isNull(it2.current);
149
150 Iterable<String> skip12 = list3.skip(1);
151 Expect.isTrue(skip12 is! List);
152 Expect.isTrue(skip12.skip(2).skip(1) is! List);
153 it2 = skip12.iterator;
154 Expect.isNull(it2.current);
155 Expect.isFalse(it2.moveNext());
156 Expect.isNull(it2.current);
157
158 skip0 = set1.skip(0);
159 List<int> copied = skip0.toList();
160 Expect.equals(3, copied.length);
161 Expect.isTrue(set1.contains(copied[0]));
162 Expect.isTrue(set1.contains(copied[1]));
163 Expect.isTrue(set1.contains(copied[2]));
164 Expect.isTrue(copied[0] != copied[1]);
165 Expect.isTrue(copied[0] != copied[2]);
166 Expect.isTrue(copied[1] != copied[2]);
167 it = skip0.iterator;
168 Expect.isNull(it.current);
169 Expect.isTrue(it.moveNext());
170 Expect.isNotNull(it.current);
171 Expect.isTrue(it.moveNext());
172 Expect.isNotNull(it.current);
173 Expect.isTrue(it.moveNext());
174 Expect.isNotNull(it.current);
175 Expect.isFalse(it.moveNext());
176 Expect.isNull(it.current);
177
178 skip1 = set1.skip(1);
179 copied = skip1.toList();
180 Expect.equals(2, copied.length);
181 Expect.isTrue(set1.contains(copied[0]));
182 Expect.isTrue(set1.contains(copied[1]));
183 Expect.isTrue(copied[0] != copied[1]);
184 it = skip1.iterator;
185 Expect.isNull(it.current);
186 Expect.isTrue(it.moveNext());
187 Expect.isNotNull(it.current);
188 Expect.isTrue(it.moveNext());
189 Expect.isNotNull(it.current);
190 Expect.isFalse(it.moveNext());
191 Expect.isNull(it.current);
192
193 skip2 = set1.skip(2);
194 copied = skip2.toList();
195 Expect.equals(1, copied.length);
196 Expect.isTrue(set1.contains(copied[0]));
197 it = skip2.iterator;
198 Expect.isNull(it.current);
199 Expect.isTrue(it.moveNext());
200 Expect.isNotNull(it.current);
201 Expect.isFalse(it.moveNext());
202 Expect.isNull(it.current);
203
204 skip3 = set1.skip(3);
205 it = skip3.iterator;
206 Expect.isNull(it.current);
207 Expect.isFalse(it.moveNext());
208 Expect.isNull(it.current);
209
210 skip4 = set1.skip(4);
211 it = skip4.iterator;
212 Expect.isNull(it.current);
213 Expect.isFalse(it.moveNext());
214 Expect.isNull(it.current);
215
216 var dynamicSkip0 = set2.skip(0);
217 var dynamicIt = dynamicSkip0.iterator;
218 Expect.isNull(dynamicIt.current);
219 Expect.isFalse(dynamicIt.moveNext());
220 Expect.isNull(dynamicIt.current);
221
222 var dynamicSkip1 = set2.skip(1);
223 dynamicIt = dynamicSkip1.iterator;
224 Expect.isNull(dynamicIt.current);
225 Expect.isFalse(dynamicIt.moveNext());
226 Expect.isNull(dynamicIt.current);
227
228 testSkipTake(Iterable input, int skip, int take) {
229 List expected = [];
230 Iterator iter = input.iterator;
231 for (int i = 0; i < skip; i++) iter.moveNext();
232 for (int i = 0; i < take; i++) {
233 if (!iter.moveNext()) break;
234 expected.add(iter.current);
235 }
236 Expect.listEquals(expected, input.skip(skip).take(take).toList());
237 }
238
239 List longList = [1, 4, 5, 3, 8, 11, 12, 6, 9, 10, 13, 7, 2, 14, 15];
240 Set bigSet = longList.toSet();
241
242 for (Iterable collection in [longList, longList.reversed, bigSet]) {
243 testSkipTake(collection, 0, 0);
244 testSkipTake(collection, 0, 5);
245 testSkipTake(collection, 0, 15);
246 testSkipTake(collection, 0, 25);
247 testSkipTake(collection, 5, 0);
248 testSkipTake(collection, 5, 5);
249 testSkipTake(collection, 5, 10);
250 testSkipTake(collection, 5, 20);
251 testSkipTake(collection, 15, 0);
252 testSkipTake(collection, 15, 5);
253 testSkipTake(collection, 20, 0);
254 testSkipTake(collection, 20, 5);
255 Expect.throws(() => longList.skip(-1), (e) => e is RangeError);
256 }
257 }
OLDNEW
« no previous file with comments | « tests/corelib_strong/iterable_single_where_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698