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

Side by Side Diff: tests/corelib_2/iterable_reduce_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
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 import "package:expect/expect.dart"; 5 import "package:expect/expect.dart";
6 import 'dart:collection'; 6 import 'dart:collection';
7 import 'dart:typed_data'; 7 import 'dart:typed_data';
8 8
9 class MyList extends ListBase { 9 class MyList extends ListBase {
10 List list; 10 List list;
(...skipping 18 matching lines...) Expand all
29 new List(3) 29 new List(3)
30 ..[0] = 1 30 ..[0] = 1
31 ..[1] = 2 31 ..[1] = 2
32 ..[2] = 3, 32 ..[2] = 3,
33 {1: 1, 2: 2, 3: 3}.keys, 33 {1: 1, 2: 2, 3: 3}.keys,
34 {1: 1, 2: 2, 3: 3}.values, 34 {1: 1, 2: 2, 3: 3}.values,
35 new Iterable.generate(3, (x) => x + 1), 35 new Iterable.generate(3, (x) => x + 1),
36 new List.generate(3, (x) => x + 1), 36 new List.generate(3, (x) => x + 1),
37 [0, 1, 2, 3].where((x) => x > 0), 37 [0, 1, 2, 3].where((x) => x > 0),
38 [0, 1, 2].map((x) => x + 1), 38 [0, 1, 2].map((x) => x + 1),
39 [ 39 [ //# 01: ok
40 [1, 2], 40 [1, 2], //# 01: ok
41 [3] 41 [3] //# 01: ok
42 ].expand(id), 42 ].expand(id), //# 01: ok
43 [3, 2, 1].reversed, 43 [3, 2, 1].reversed,
44 [0, 1, 2, 3].skip(1), 44 [0, 1, 2, 3].skip(1),
45 [1, 2, 3, 4].take(3), 45 [1, 2, 3, 4].take(3),
46 new Uint8List(3) 46 new Uint8List(3)
47 ..[0] = 1 47 ..[0] = 1
48 ..[1] = 2 48 ..[1] = 2
49 ..[2] = 3, 49 ..[2] = 3,
50 (new HashMap() 50 (new HashMap()
51 ..[1] = 1 51 ..[1] = 1
52 ..[2] = 2 52 ..[2] = 2
(...skipping 15 matching lines...) Expand all
68 ..[2] = 3) 68 ..[2] = 3)
69 .values, 69 .values,
70 new HashSet()..add(1)..add(2)..add(3), 70 new HashSet()..add(1)..add(2)..add(3),
71 new LinkedHashSet()..add(1)..add(2)..add(3), 71 new LinkedHashSet()..add(1)..add(2)..add(3),
72 new SplayTreeSet()..add(1)..add(2)..add(3), 72 new SplayTreeSet()..add(1)..add(2)..add(3),
73 "\x01\x02\x03".codeUnits, 73 "\x01\x02\x03".codeUnits,
74 "\x01\x02\x03".runes, 74 "\x01\x02\x03".runes,
75 new MyList([1, 2, 3]), 75 new MyList([1, 2, 3]),
76 ]) { 76 ]) {
77 int callCount = 0; 77 int callCount = 0;
78 var result = iterable.reduce((x, y) { 78 var result = iterable.reduce((x, y) { //# 01: ok
79 callCount++; 79 callCount++; //# 01: ok
80 return x + y; 80 return x + y; //# 01: ok
81 }); 81 }); //# 01: ok
82 Expect.equals(6, result, "${iterable.runtimeType}"); 82 Expect.equals(6, result, "${iterable.runtimeType}"); //# 01: ok
83 Expect.equals(2, callCount); 83 Expect.equals(2, callCount); //# 01: ok
84 } 84 }
85 85
86 // Empty iterables not allowed. 86 // Empty iterables not allowed.
87 for (var iterable in [ 87 for (var iterable in [
88 const [], 88 const [],
89 [], 89 [],
90 new List(0), 90 new List(0),
91 {}.keys, 91 {}.keys,
92 {}.values, 92 {}.values,
93 new Iterable.generate(0, (x) => x + 1), 93 new Iterable.generate(0, (x) => x + 1),
94 new List.generate(0, (x) => x + 1), 94 new List.generate(0, (x) => x + 1),
95 [0, 1, 2, 3].where((x) => false), 95 [0, 1, 2, 3].where((x) => false),
96 [].map((x) => x + 1), 96 [].map((x) => x + 1),
97 [[], []].expand(id), 97 [[], []].expand(id), //# 01: ok
98 [].reversed, 98 [].reversed,
99 [0, 1, 2, 3].skip(4), 99 [0, 1, 2, 3].skip(4),
100 [1, 2, 3, 4].take(0), 100 [1, 2, 3, 4].take(0),
101 new Uint8List(0), 101 new Uint8List(0),
102 (new HashMap()).keys, 102 (new HashMap()).keys,
103 (new HashMap()).values, 103 (new HashMap()).values,
104 (new SplayTreeMap()).keys, 104 (new SplayTreeMap()).keys,
105 (new SplayTreeMap()).values, 105 (new SplayTreeMap()).values,
106 new HashSet(), 106 new HashSet(),
107 new LinkedHashSet(), 107 new LinkedHashSet(),
(...skipping 11 matching lines...) Expand all
119 for (var iterable in [ 119 for (var iterable in [
120 const [1], 120 const [1],
121 [1], 121 [1],
122 new List(1)..[0] = 1, 122 new List(1)..[0] = 1,
123 {1: 1}.keys, 123 {1: 1}.keys,
124 {1: 1}.values, 124 {1: 1}.values,
125 new Iterable.generate(1, (x) => x + 1), 125 new Iterable.generate(1, (x) => x + 1),
126 new List.generate(1, (x) => x + 1), 126 new List.generate(1, (x) => x + 1),
127 [0, 1, 2, 3].where((x) => x == 1), 127 [0, 1, 2, 3].where((x) => x == 1),
128 [0].map((x) => x + 1), 128 [0].map((x) => x + 1),
129 [ 129 [ //# 01: ok
130 [], 130 [], //# 01: ok
131 [1] 131 [1] //# 01: ok
132 ].expand(id), 132 ].expand(id), //# 01: ok
133 [1].reversed, 133 [1].reversed,
134 [0, 1].skip(1), 134 [0, 1].skip(1),
135 [1, 2, 3, 4].take(1), 135 [1, 2, 3, 4].take(1),
136 new Uint8List(1)..[0] = 1, 136 new Uint8List(1)..[0] = 1,
137 (new HashMap()..[1] = 0).keys, 137 (new HashMap()..[1] = 0).keys,
138 (new HashMap()..[0] = 1).values, 138 (new HashMap()..[0] = 1).values,
139 (new SplayTreeMap()..[1] = 0).keys, 139 (new SplayTreeMap()..[1] = 0).keys,
140 (new SplayTreeMap()..[0] = 1).values, 140 (new SplayTreeMap()..[0] = 1).values,
141 new HashSet()..add(1), 141 new HashSet()..add(1),
142 new LinkedHashSet()..add(1), 142 new LinkedHashSet()..add(1),
143 new SplayTreeSet()..add(1), 143 new SplayTreeSet()..add(1),
144 "\x01".codeUnits, 144 "\x01".codeUnits,
145 "\x01".runes, 145 "\x01".runes,
146 new MyList([1]), 146 new MyList([1]),
147 ]) { 147 ]) {
148 Expect.equals(1, iterable.reduce((x, y) => throw "Unreachable")); 148 Expect.equals(1, iterable.reduce((x, y) => throw "Unreachable")); //# 01: ok
149 } 149 }
150 150
151 // Concurrent modifications not allowed. 151 // Concurrent modifications not allowed.
152 testModification(base, modify, transform) { 152 testModification(base, modify, transform) {
153 var iterable = transform(base); 153 var iterable = transform(base);
154 Expect.throws(() { 154 Expect.throws(() {
155 iterable.reduce((x, y) { 155 iterable.reduce((x, y) {
156 modify(base); 156 modify(base);
157 return x + y; 157 return x + y;
158 }); 158 });
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 ..[1] = 1 196 ..[1] = 1
197 ..[2] = 2 197 ..[2] = 2
198 ..[3] = 3; 198 ..[3] = 3;
199 testModification(splayMap, put4, (x) => x.keys); 199 testModification(splayMap, put4, (x) => x.keys);
200 splayMap = new SplayTreeMap() 200 splayMap = new SplayTreeMap()
201 ..[1] = 1 201 ..[1] = 1
202 ..[2] = 2 202 ..[2] = 2
203 ..[3] = 3; 203 ..[3] = 3;
204 testModification(splayMap, put4, (x) => x.values); 204 testModification(splayMap, put4, (x) => x.values);
205 } 205 }
OLDNEW
« no previous file with comments | « tests/corelib_2/iterable_mapping_test.dart ('k') | tests/corelib_2/iterable_return_type_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698