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

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

Issue 716513002: Fix type in generic type of parameters to SplayTreeMap.fromIterable. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 1 month 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
« no previous file with comments | « sdk/lib/collection/splay_tree.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
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();
11 defaultValueFunctionTest(); 11 defaultValueFunctionTest();
12 noDefaultValuesTest(); 12 noDefaultValuesTest();
13 emptyIterableTest(); 13 emptyIterableTest();
14 equalElementsTest(); 14 equalElementsTest();
15 genericTypeTest(); 15 genericTypeTest();
16 typedTest();
16 } 17 }
17 18
18 void defaultFunctionValuesTest() { 19 void defaultFunctionValuesTest() {
19 var map = new SplayTreeMap.fromIterable([1, 2, 3]); 20 var map = new SplayTreeMap.fromIterable([1, 2, 3]);
20 21
21 Expect.isTrue(map is Map); 22 Expect.isTrue(map is Map);
22 Expect.isTrue(map is SplayTreeMap); 23 Expect.isTrue(map is SplayTreeMap);
23 Expect.isFalse(map is HashMap); 24 Expect.isFalse(map is HashMap);
24 25
25 Expect.equals(3, map.length); 26 Expect.equals(3, map.length);
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 void genericTypeTest() { 111 void genericTypeTest() {
111 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');
112 Expect.isTrue(map is Map<int, String>); 113 Expect.isTrue(map is Map<int, String>);
113 Expect.isTrue(map is SplayTreeMap<int, String>); 114 Expect.isTrue(map is SplayTreeMap<int, String>);
114 115
115 // Make sure it is not just SplayTreeMap<dynamic, dynamic>. 116 // Make sure it is not just SplayTreeMap<dynamic, dynamic>.
116 Expect.isFalse(map is SplayTreeMap<String, dynamic>); 117 Expect.isFalse(map is SplayTreeMap<String, dynamic>);
117 Expect.isFalse(map is SplayTreeMap<dynamic, int>); 118 Expect.isFalse(map is SplayTreeMap<dynamic, int>);
118 } 119 }
119 120
121 // Test in checked mode with explicitly given types.
122 void typedTest() {
123 bool isCheckedMode = false;
124 assert((isCheckedMode = true));
125 if (!isCheckedMode) return;
126
127 Expect.throws(() {
128 new SplayTreeMap<String,bool>.fromIterable(<int>[1, 2, 3],
129 key: (int v) => "$v"
130 // No "value" map, defaults to identity, which returns int, not bool.
131 );
132 });
133
134 Expect.throws(() {
135 new SplayTreeMap<String,bool>.fromIterable(<int>[1, 2, 3],
136 // No "key" map, defaults to identity, which returns int, not String.
137 value: (int v) => v.isOdd
138 );
139 });
140
141 Expect.throws(() {
142 new SplayTreeMap<String,bool>.fromIterable(<int>[1, 2, 3],
143 key: (int v) => v, // wrong type.
144 value: (int v) => v.isOdd
145 );
146 });
147
148 Expect.throws(() {
149 new SplayTreeMap<String,bool>.fromIterable(<int>[1, 2, 3],
150 key: (int v) => "$v",
151 value: (int v) => v // wrong type.
152 );
153 });
154
155 // But it works with explicit types when used correctly.
156 Map<String, bool> map =
157 new SplayTreeMap<String, bool>.fromIterable(<int>[1, 2, 3],
158 key: (int v) => "$v",
159 value: (int v) => v.isOdd);
160 Iterable<String> keys = map.keys;
161 Iterable<bool> values = map.values;
162 List<String> keyList = keys.toList();
163 List<bool> valueList = values.toList();
164 Expect.equals(3, keyList.length);
165 Expect.equals(3, valueList.length);
166 Expect.equals(keys.first, map.firstKey());
167 Expect.equals(keys.last, map.lastKey());
168 }
OLDNEW
« no previous file with comments | « sdk/lib/collection/splay_tree.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698