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

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

Issue 2683893002: Make corelib_strong tests strong-mode compliant (Closed)
Patch Set: Created 3 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
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 7
8 main() { 8 main() {
9 defaultFunctionValuesTest(); 9 defaultFunctionValuesTest();
10 defaultKeyFunctionTest(); 10 defaultKeyFunctionTest();
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 110
111 void genericTypeTest() { 111 void genericTypeTest() {
112 var map = new SplayTreeMap<int, String>.fromIterable([1, 2, 3], value: (x) => '$x'); 112 var map = new SplayTreeMap<int, String>.fromIterable([1, 2, 3], value: (x) => '$x');
113 Expect.isTrue(map is Map<int, String>); 113 Expect.isTrue(map is Map<int, String>);
114 Expect.isTrue(map is SplayTreeMap<int, String>); 114 Expect.isTrue(map is SplayTreeMap<int, String>);
115 115
116 // Make sure it is not just SplayTreeMap<dynamic, dynamic>. 116 // Make sure it is not just SplayTreeMap<dynamic, dynamic>.
117 Expect.isFalse(map is SplayTreeMap<String, dynamic>); 117 Expect.isFalse(map is SplayTreeMap<String, dynamic>);
118 Expect.isFalse(map is SplayTreeMap<dynamic, int>); 118 Expect.isFalse(map is SplayTreeMap<dynamic, int>);
119 } 119 }
120 typedef String intToString(int v);
121 typedef bool intToBool(int v);
120 122
121 // Test in checked mode with explicitly given types. 123 // Test in checked mode with explicitly given types.
122 void typedTest() { 124 void typedTest() {
123 bool isCheckedMode = false; 125 bool isCheckedMode = false;
124 assert((isCheckedMode = true)); 126 assert((isCheckedMode = true));
125 if (!isCheckedMode) return; 127 if (!isCheckedMode) return;
126 128
127 // Assign functions to untyped function variables. 129 // Assign functions to typed function variables.
128 Function key = (int v) => "$v"; 130 intToString key = (int v) => "$v";
129 Function value = (int v) => v.isOdd; 131 intToBool value = (int v) => v.isOdd;
130 Function id = (int i) => i; 132 Function id = (int i) => i;
131 133
132 Expect.throws(() { 134 Expect.throws(() {
133 new SplayTreeMap<String,bool>.fromIterable(<int>[1, 2, 3], 135 new SplayTreeMap<String,bool>.fromIterable(<int>[1, 2, 3],
134 key: key 136 key: key
135 // No "value" map, defaults to identity, which returns int, not bool. 137 // No "value" map, defaults to identity, which returns int, not bool.
136 ); 138 );
137 }); 139 });
138 140
139 Expect.throws(() { 141 Expect.throws(() {
140 new SplayTreeMap<String,bool>.fromIterable(<int>[1, 2, 3], 142 new SplayTreeMap<String,bool>.fromIterable(<int>[1, 2, 3],
141 // No "key" map, defaults to identity, which returns int, not String. 143 // No "key" map, defaults to identity, which returns int, not String.
142 value: value 144 value: value
143 ); 145 );
144 }); 146 });
145 147
146 Expect.throws(() { 148 Expect.throws(() {
147 new SplayTreeMap<String,bool>.fromIterable(<int>[1, 2, 3], 149 new SplayTreeMap<String,bool>.fromIterable(<int>[1, 2, 3],
148 key: id, // wrong type. 150 key: id as dynamic, // wrong type.
149 value: value 151 value: value
150 ); 152 );
151 }); 153 });
152 154
153 Expect.throws(() { 155 Expect.throws(() {
154 new SplayTreeMap<String,bool>.fromIterable(<int>[1, 2, 3], 156 new SplayTreeMap<String,bool>.fromIterable(<int>[1, 2, 3],
155 key: key, 157 key: key,
156 value: id // wrong type. 158 value: id as dynamic // wrong type.
157 ); 159 );
158 }); 160 });
159 161
160 // But it works with explicit types when used correctly. 162 // But it works with explicit types when used correctly.
161 SplayTreeMap<String, bool> map = 163 SplayTreeMap<String, bool> map =
162 new SplayTreeMap<String, bool>.fromIterable(<int>[1, 2, 3], 164 new SplayTreeMap<String, bool>.fromIterable(<int>[1, 2, 3],
163 key: key, 165 key: key,
164 value: value); 166 value: value);
165 Iterable<String> keys = map.keys; 167 Iterable<String> keys = map.keys;
166 Iterable<bool> values = map.values; 168 Iterable<bool> values = map.values;
167 List<String> keyList = keys.toList(); 169 List<String> keyList = keys.toList();
168 List<bool> valueList = values.toList(); 170 List<bool> valueList = values.toList();
169 Expect.equals(3, keyList.length); 171 Expect.equals(3, keyList.length);
170 Expect.equals(3, valueList.length); 172 Expect.equals(3, valueList.length);
171 Expect.equals(keys.first, map.firstKey()); 173 Expect.equals(keys.first, map.firstKey());
172 Expect.equals(keys.last, map.lastKey()); 174 Expect.equals(keys.last, map.lastKey());
173 } 175 }
OLDNEW
« tests/corelib_strong/sort_test.dart ('K') | « tests/corelib_strong/sort_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698