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

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

Issue 2983383002: Migrated test block 26 to Dart 2.0. (Closed)
Patch Set: Updated splay_tree_from_iterables_test to not check for checked mode, and updated status files acco… 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/sort_test.dart ('k') | tests/corelib/splay_tree_from_iterables_test.dart » ('j') | 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) 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
3 // BSD-style license that can be found in the LICENSE file.
4
5 import "package:expect/expect.dart";
6 import 'dart:collection';
7
8 main() {
9 defaultFunctionValuesTest();
10 defaultKeyFunctionTest();
11 defaultValueFunctionTest();
12 noDefaultValuesTest();
13 emptyIterableTest();
14 equalElementsTest();
15 genericTypeTest();
16 typedTest();
17 }
18
19 void defaultFunctionValuesTest() {
20 var map = new SplayTreeMap.fromIterable([1, 2, 3]);
21
22 Expect.isTrue(map is Map);
23 Expect.isTrue(map is SplayTreeMap);
24 Expect.isFalse(map is HashMap);
25
26 Expect.equals(3, map.length);
27 Expect.equals(3, map.keys.length);
28 Expect.equals(3, map.values.length);
29
30 Expect.equals(1, map[1]);
31 Expect.equals(2, map[2]);
32 Expect.equals(3, map[3]);
33 }
34
35 void defaultKeyFunctionTest() {
36 var map = new SplayTreeMap.fromIterable([1, 2, 3], value: (x) => x + 1);
37
38 Expect.isTrue(map is Map);
39 Expect.isTrue(map is SplayTreeMap);
40 Expect.isFalse(map is HashMap);
41
42 Expect.equals(3, map.length);
43 Expect.equals(3, map.keys.length);
44 Expect.equals(3, map.values.length);
45
46 Expect.equals(2, map[1]);
47 Expect.equals(3, map[2]);
48 Expect.equals(4, map[3]);
49 }
50
51 void defaultValueFunctionTest() {
52 var map = new SplayTreeMap.fromIterable([1, 2, 3], key: (x) => x + 1);
53
54 Expect.isTrue(map is Map);
55 Expect.isTrue(map is SplayTreeMap);
56 Expect.isFalse(map is HashMap);
57
58 Expect.equals(3, map.length);
59 Expect.equals(3, map.keys.length);
60 Expect.equals(3, map.values.length);
61
62 Expect.equals(1, map[2]);
63 Expect.equals(2, map[3]);
64 Expect.equals(3, map[4]);
65 }
66
67 void noDefaultValuesTest() {
68 var map = new SplayTreeMap.fromIterable([1, 2, 3],
69 key: (x) => x + 1, value: (x) => x - 1);
70
71 Expect.isTrue(map is Map);
72 Expect.isTrue(map is SplayTreeMap);
73 Expect.isFalse(map is HashMap);
74
75 Expect.equals(3, map.length);
76 Expect.equals(3, map.keys.length);
77 Expect.equals(3, map.values.length);
78
79 Expect.equals(0, map[2]);
80 Expect.equals(1, map[3]);
81 Expect.equals(2, map[4]);
82 }
83
84 void emptyIterableTest() {
85 var map = new SplayTreeMap.fromIterable([]);
86
87 Expect.isTrue(map is Map);
88 Expect.isTrue(map is SplayTreeMap);
89 Expect.isFalse(map is HashMap);
90
91 Expect.equals(0, map.length);
92 Expect.equals(0, map.keys.length);
93 Expect.equals(0, map.values.length);
94 }
95
96 void equalElementsTest() {
97 var map = new SplayTreeMap.fromIterable([1, 2, 2], key: (x) => x + 1);
98
99 Expect.isTrue(map is Map);
100 Expect.isTrue(map is SplayTreeMap);
101 Expect.isFalse(map is HashMap);
102
103 Expect.equals(2, map.length);
104 Expect.equals(2, map.keys.length);
105 Expect.equals(2, map.values.length);
106
107 Expect.equals(1, map[2]);
108 Expect.equals(2, map[3]);
109 }
110
111 void genericTypeTest() {
112 var map =
113 new SplayTreeMap<int, String>.fromIterable([1, 2, 3], value: (x) => '$x');
114 Expect.isTrue(map is Map<int, String>);
115 Expect.isTrue(map is SplayTreeMap<int, String>);
116
117 // Make sure it is not just SplayTreeMap<dynamic, dynamic>.
118 Expect.isFalse(map is SplayTreeMap<String, dynamic>);
119 Expect.isFalse(map is SplayTreeMap<dynamic, int>);
120 }
121
122 // Test in checked mode with explicitly given types.
123 void typedTest() {
124 if (!typeAssertionsEnabled) return;
125
126 // Assign functions to untyped function variables.
127 Function key = (int v) => "$v";
128 Function value = (int v) => v.isOdd;
129 Function id = (int i) => i;
130
131 Expect.throws(() {
132 new SplayTreeMap<String, bool>.fromIterable(<int>[1, 2, 3], key: key
133 // No "value" map, defaults to identity, which returns int, not bool.
134 );
135 });
136
137 Expect.throws(() {
138 new SplayTreeMap<String, bool>.fromIterable(<int>[1, 2, 3],
139 // No "key" map, defaults to identity, which returns int, not String.
140 value: value);
141 });
142
143 Expect.throws(() {
144 new SplayTreeMap<String, bool>.fromIterable(<int>[1, 2, 3],
145 key: id, // wrong type.
146 value: value);
147 });
148
149 Expect.throws(() {
150 new SplayTreeMap<String, bool>.fromIterable(<int>[1, 2, 3],
151 key: key, value: id // wrong type.
152 );
153 });
154
155 // But it works with explicit types when used correctly.
156 SplayTreeMap<String, bool> map = new SplayTreeMap<String, bool>.fromIterable(
157 <int>[1, 2, 3],
158 key: key, value: value);
159 Iterable<String> keys = map.keys;
160 Iterable<bool> values = map.values;
161 List<String> keyList = keys.toList();
162 List<bool> valueList = values.toList();
163 Expect.equals(3, keyList.length);
164 Expect.equals(3, valueList.length);
165 Expect.equals(keys.first, map.firstKey());
166 Expect.equals(keys.last, map.lastKey());
167 }
OLDNEW
« no previous file with comments | « tests/corelib/sort_test.dart ('k') | tests/corelib/splay_tree_from_iterables_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698