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

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

Issue 12295009: Recommit changing List.skip/take/revert returns Iterable and remove mappedBy. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Make Future.wait simpler. Created 7 years, 10 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
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 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 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 main() { 5 main() {
6 List<int> list1 = <int>[1, 2, 3]; 6 List<int> list1 = <int>[1, 2, 3];
7 List<int> list2 = const <int>[4, 5]; 7 List<int> list2 = const <int>[4, 5];
8 List<String> list3 = <String>[]; 8 List<String> list3 = <String>[];
9 Set<int> set1 = new Set<int>(); 9 Set<int> set1 = new Set<int>();
10 set1..add(11) 10 set1..add(11)
11 ..add(12) 11 ..add(12)
12 ..add(13); 12 ..add(13);
13 Set set2 = new Set(); 13 Set set2 = new Set();
14 14
15 Iterable<int> skip0 = list1.skip(0); 15 Iterable<int> skip0 = list1.skip(0);
16 Expect.isTrue(skip0 is List); 16 Expect.isTrue(skip0 is! List);
17 Iterator<int> it = skip0.iterator; 17 Iterator<int> it = skip0.iterator;
18 Expect.isNull(it.current); 18 Expect.isNull(it.current);
19 Expect.isTrue(it.moveNext()); 19 Expect.isTrue(it.moveNext());
20 Expect.equals(1, it.current); 20 Expect.equals(1, it.current);
21 Expect.isTrue(it.moveNext()); 21 Expect.isTrue(it.moveNext());
22 Expect.equals(2, it.current); 22 Expect.equals(2, it.current);
23 Expect.isTrue(it.moveNext()); 23 Expect.isTrue(it.moveNext());
24 Expect.equals(3, it.current); 24 Expect.equals(3, it.current);
25 Expect.isFalse(it.moveNext()); 25 Expect.isFalse(it.moveNext());
26 Expect.isNull(it.current); 26 Expect.isNull(it.current);
27 27
28 Iterable<int> skip1 = list1.skip(1); 28 Iterable<int> skip1 = list1.skip(1);
29 Expect.isTrue(skip1 is List); 29 Expect.isTrue(skip1 is! List);
30 Expect.isTrue(skip1.skip(2).skip(1) is List); 30 Expect.isTrue(skip1.skip(2).skip(1) is! List);
31 it = skip1.iterator; 31 it = skip1.iterator;
32 Expect.isNull(it.current); 32 Expect.isNull(it.current);
33 Expect.isTrue(it.moveNext()); 33 Expect.isTrue(it.moveNext());
34 Expect.equals(2, it.current); 34 Expect.equals(2, it.current);
35 Expect.isTrue(it.moveNext()); 35 Expect.isTrue(it.moveNext());
36 Expect.equals(3, it.current); 36 Expect.equals(3, it.current);
37 Expect.isFalse(it.moveNext()); 37 Expect.isFalse(it.moveNext());
38 Expect.isNull(it.current); 38 Expect.isNull(it.current);
39 39
40 Iterable<int> skip2 = list1.skip(2); 40 Iterable<int> skip2 = list1.skip(2);
41 Expect.isTrue(skip2 is List); 41 Expect.isTrue(skip2 is! List);
42 Expect.isTrue(skip2.skip(2).skip(1) is List); 42 Expect.isTrue(skip2.skip(2).skip(1) is! List);
43 it = skip2.iterator; 43 it = skip2.iterator;
44 Expect.isNull(it.current); 44 Expect.isNull(it.current);
45 Expect.isTrue(it.moveNext()); 45 Expect.isTrue(it.moveNext());
46 Expect.equals(3, it.current); 46 Expect.equals(3, it.current);
47 Expect.isFalse(it.moveNext()); 47 Expect.isFalse(it.moveNext());
48 Expect.isNull(it.current); 48 Expect.isNull(it.current);
49 49
50 Iterable<int> skip3 = list1.skip(3); 50 Iterable<int> skip3 = list1.skip(3);
51 Expect.isTrue(skip3 is List); 51 Expect.isTrue(skip3 is! List);
52 Expect.isTrue(skip3.skip(2).skip(1) is List); 52 Expect.isTrue(skip3.skip(2).skip(1) is! List);
53 it = skip3.iterator; 53 it = skip3.iterator;
54 Expect.isNull(it.current); 54 Expect.isNull(it.current);
55 Expect.isFalse(it.moveNext()); 55 Expect.isFalse(it.moveNext());
56 Expect.isNull(it.current); 56 Expect.isNull(it.current);
57 57
58 Iterable<int> skip4 = list1.skip(4); 58 Iterable<int> skip4 = list1.skip(4);
59 Expect.isTrue(skip4 is List); 59 Expect.isTrue(skip4 is! List);
60 Expect.isTrue(skip4.skip(2).skip(1) is List); 60 Expect.isTrue(skip4.skip(2).skip(1) is! List);
61 it = skip4.iterator; 61 it = skip4.iterator;
62 Expect.isNull(it.current); 62 Expect.isNull(it.current);
63 Expect.isFalse(it.moveNext()); 63 Expect.isFalse(it.moveNext());
64 Expect.isNull(it.current); 64 Expect.isNull(it.current);
65 65
66 skip0 = list1.skip(0); 66 skip0 = list1.skip(0);
67 skip1 = skip0.skip(1); 67 skip1 = skip0.skip(1);
68 skip2 = skip1.skip(1); 68 skip2 = skip1.skip(1);
69 skip3 = skip2.skip(1); 69 skip3 = skip2.skip(1);
70 skip4 = skip3.skip(1); 70 skip4 = skip3.skip(1);
(...skipping 24 matching lines...) Expand all
95 it = skip3.iterator; 95 it = skip3.iterator;
96 Expect.isNull(it.current); 96 Expect.isNull(it.current);
97 Expect.isFalse(it.moveNext()); 97 Expect.isFalse(it.moveNext());
98 Expect.isNull(it.current); 98 Expect.isNull(it.current);
99 it = skip4.iterator; 99 it = skip4.iterator;
100 Expect.isNull(it.current); 100 Expect.isNull(it.current);
101 Expect.isFalse(it.moveNext()); 101 Expect.isFalse(it.moveNext());
102 Expect.isNull(it.current); 102 Expect.isNull(it.current);
103 103
104 skip0 = list2.skip(0); 104 skip0 = list2.skip(0);
105 Expect.isTrue(skip0 is List); 105 Expect.isTrue(skip0 is! List);
106 Expect.isTrue(skip0.skip(2).skip(1) is List); 106 Expect.isTrue(skip0.skip(2).skip(1) is! List);
107 it = skip0.iterator; 107 it = skip0.iterator;
108 Expect.isNull(it.current); 108 Expect.isNull(it.current);
109 Expect.isTrue(it.moveNext()); 109 Expect.isTrue(it.moveNext());
110 Expect.equals(4, it.current); 110 Expect.equals(4, it.current);
111 Expect.isTrue(it.moveNext()); 111 Expect.isTrue(it.moveNext());
112 Expect.equals(5, it.current); 112 Expect.equals(5, it.current);
113 Expect.isFalse(it.moveNext()); 113 Expect.isFalse(it.moveNext());
114 Expect.isNull(it.current); 114 Expect.isNull(it.current);
115 115
116 skip1 = list2.skip(1); 116 skip1 = list2.skip(1);
117 Expect.isTrue(skip1 is List); 117 Expect.isTrue(skip1 is! List);
118 Expect.isTrue(skip1.skip(2).skip(1) is List); 118 Expect.isTrue(skip1.skip(2).skip(1) is! List);
119 it = skip1.iterator; 119 it = skip1.iterator;
120 Expect.isNull(it.current); 120 Expect.isNull(it.current);
121 Expect.isTrue(it.moveNext()); 121 Expect.isTrue(it.moveNext());
122 Expect.equals(5, it.current); 122 Expect.equals(5, it.current);
123 Expect.isFalse(it.moveNext()); 123 Expect.isFalse(it.moveNext());
124 Expect.isNull(it.current); 124 Expect.isNull(it.current);
125 125
126 skip2 = list2.skip(2); 126 skip2 = list2.skip(2);
127 Expect.isTrue(skip2 is List); 127 Expect.isTrue(skip2 is! List);
128 Expect.isTrue(skip2.skip(2).skip(1) is List); 128 Expect.isTrue(skip2.skip(2).skip(1) is! List);
129 it = skip2.iterator; 129 it = skip2.iterator;
130 Expect.isNull(it.current); 130 Expect.isNull(it.current);
131 Expect.isFalse(it.moveNext()); 131 Expect.isFalse(it.moveNext());
132 Expect.isNull(it.current); 132 Expect.isNull(it.current);
133 133
134 skip3 = list2.skip(3); 134 skip3 = list2.skip(3);
135 Expect.isTrue(skip3 is List); 135 Expect.isTrue(skip3 is! List);
136 Expect.isTrue(skip3.skip(2).skip(1) is List); 136 Expect.isTrue(skip3.skip(2).skip(1) is! List);
137 it = skip3.iterator; 137 it = skip3.iterator;
138 Expect.isNull(it.current); 138 Expect.isNull(it.current);
139 Expect.isFalse(it.moveNext()); 139 Expect.isFalse(it.moveNext());
140 Expect.isNull(it.current); 140 Expect.isNull(it.current);
141 141
142 Iterable<String> skip02 = list3.skip(0); 142 Iterable<String> skip02 = list3.skip(0);
143 Expect.isTrue(skip02 is List); 143 Expect.isTrue(skip02 is! List);
144 Expect.isTrue(skip02.skip(2).skip(1) is List); 144 Expect.isTrue(skip02.skip(2).skip(1) is! List);
145 Iterator<String> it2 = skip02.iterator; 145 Iterator<String> it2 = skip02.iterator;
146 Expect.isNull(it2.current); 146 Expect.isNull(it2.current);
147 Expect.isFalse(it2.moveNext()); 147 Expect.isFalse(it2.moveNext());
148 Expect.isNull(it2.current); 148 Expect.isNull(it2.current);
149 149
150 Iterable<String> skip12 = list3.skip(1); 150 Iterable<String> skip12 = list3.skip(1);
151 Expect.isTrue(skip12 is List); 151 Expect.isTrue(skip12 is! List);
152 Expect.isTrue(skip12.skip(2).skip(1) is List); 152 Expect.isTrue(skip12.skip(2).skip(1) is! List);
153 it2 = skip12.iterator; 153 it2 = skip12.iterator;
154 Expect.isNull(it2.current); 154 Expect.isNull(it2.current);
155 Expect.isFalse(it2.moveNext()); 155 Expect.isFalse(it2.moveNext());
156 Expect.isNull(it2.current); 156 Expect.isNull(it2.current);
157 157
158 skip0 = set1.skip(0); 158 skip0 = set1.skip(0);
159 List<int> copied = skip0.toList(); 159 List<int> copied = skip0.toList();
160 Expect.equals(3, copied.length); 160 Expect.equals(3, copied.length);
161 Expect.isTrue(set1.contains(copied[0])); 161 Expect.isTrue(set1.contains(copied[0]));
162 Expect.isTrue(set1.contains(copied[1])); 162 Expect.isTrue(set1.contains(copied[1]));
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 it = skip0.iterator; 217 it = skip0.iterator;
218 Expect.isNull(it.current); 218 Expect.isNull(it.current);
219 Expect.isFalse(it.moveNext()); 219 Expect.isFalse(it.moveNext());
220 Expect.isNull(it.current); 220 Expect.isNull(it.current);
221 221
222 skip1 = set2.skip(1); 222 skip1 = set2.skip(1);
223 it = skip1.iterator; 223 it = skip1.iterator;
224 Expect.isNull(it.current); 224 Expect.isNull(it.current);
225 Expect.isFalse(it.moveNext()); 225 Expect.isFalse(it.moveNext());
226 Expect.isNull(it.current); 226 Expect.isNull(it.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 }
227 } 256 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698