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

Side by Side Diff: tests/corelib/src/SetTest.dart

Issue 9114021: Added method map to Collection interface and all its implementations (except classes generated fr... (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 11 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) 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 class SetTest { 5 class SetTest {
6 6
7 static testMain() { 7 static testMain() {
8 Set set = new Set(); 8 Set set = new Set();
9 Expect.equals(0, set.length); 9 Expect.equals(0, set.length);
10 set.add(1); 10 set.add(1);
(...skipping 28 matching lines...) Expand all
39 testForEach(int val) { 39 testForEach(int val) {
40 sum += (val + 1); 40 sum += (val + 1);
41 } 41 }
42 42
43 set.forEach(testForEach); 43 set.forEach(testForEach);
44 Expect.equals(10 + 9 + 8 + 7 + 6 + 5 + 4 + 3 + 2 + 1, sum); 44 Expect.equals(10 + 9 + 8 + 7 + 6 + 5 + 4 + 3 + 2 + 1, sum);
45 45
46 Expect.equals(true, set.isSubsetOf(set)); 46 Expect.equals(true, set.isSubsetOf(set));
47 Expect.equals(true, set.containsAll(set)); 47 Expect.equals(true, set.containsAll(set));
48 48
49 // Test Set.map.
50 testMap(int val) {
51 return val * val;
52 }
53
54 Set mapped = set.map(testMap);
55 Expect.equals(10, mapped.length);
56
57 Expect.equals(true, mapped.contains(0));
58 Expect.equals(true, mapped.contains(1));
59 Expect.equals(true, mapped.contains(4));
60 Expect.equals(true, mapped.contains(9));
61 Expect.equals(true, mapped.contains(16));
62 Expect.equals(true, mapped.contains(25));
63 Expect.equals(true, mapped.contains(36));
64 Expect.equals(true, mapped.contains(49));
65 Expect.equals(true, mapped.contains(64));
66 Expect.equals(true, mapped.contains(81));
67
68 sum = 0;
69 set.forEach(testForEach);
70 Expect.equals(10 + 9 + 8 + 7 + 6 + 5 + 4 + 3 + 2 + 1, sum);
71
72 sum = 0;
73
74 mapped.forEach(testForEach);
75 Expect.equals(1 + 2 + 5 + 10 + 17 + 26 + 37 + 50 + 65 + 82, sum);
76
49 // Test Set.filter. 77 // Test Set.filter.
50 testFilter(int val) { 78 testFilter(int val) {
51 return val.isEven(); 79 return val.isEven();
52 } 80 }
53 81
54 Set filtered = set.filter(testFilter); 82 Set filtered = set.filter(testFilter);
83
55 Expect.equals(5, filtered.length); 84 Expect.equals(5, filtered.length);
56 85
57 Expect.equals(true, set.contains(0)); 86 Expect.equals(true, filtered.contains(0));
58 Expect.equals(true, set.contains(2)); 87 Expect.equals(true, filtered.contains(2));
59 Expect.equals(true, set.contains(4)); 88 Expect.equals(true, filtered.contains(4));
60 Expect.equals(true, set.contains(6)); 89 Expect.equals(true, filtered.contains(6));
61 Expect.equals(true, set.contains(8)); 90 Expect.equals(true, filtered.contains(8));
62 91
63 sum = 0; 92 sum = 0;
64 filtered.forEach(testForEach); 93 filtered.forEach(testForEach);
65 Expect.equals(1 + 3 + 5 + 7 + 9, sum); 94 Expect.equals(1 + 3 + 5 + 7 + 9, sum);
66 95
67 Expect.equals(true, set.containsAll(filtered)); 96 Expect.equals(true, set.containsAll(filtered));
68 Expect.equals(true, filtered.isSubsetOf(set)); 97 Expect.equals(true, filtered.isSubsetOf(set));
69 98
70 // Test Set.every. 99 // Test Set.every.
71 testEvery(int val) { 100 testEvery(int val) {
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 set.clear(); 162 set.clear();
134 Expect.equals(0, set.length); 163 Expect.equals(0, set.length);
135 set.add(11); 164 set.add(11);
136 Expect.equals(1, set.length); 165 Expect.equals(1, set.length);
137 } 166 }
138 } 167 }
139 168
140 main() { 169 main() {
141 SetTest.testMain(); 170 SetTest.testMain();
142 } 171 }
OLDNEW
« tests/corelib/src/RegExpAllMatchesTest.dart ('K') | « tests/corelib/src/RegExpAllMatchesTest.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698