OLD | NEW |
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 Expect.equals(true, set.add(1)); |
11 Expect.equals(1, set.length); | 11 Expect.equals(1, set.length); |
12 Expect.equals(true, set.contains(1)); | 12 Expect.equals(true, set.contains(1)); |
13 | 13 |
14 set.add(1); | 14 Expect.equals(false, set.add(1)); |
15 Expect.equals(1, set.length); | 15 Expect.equals(1, set.length); |
16 Expect.equals(true, set.contains(1)); | 16 Expect.equals(true, set.contains(1)); |
17 | 17 |
18 set.remove(1); | 18 Expect.equals(true, set.remove(1)); |
19 Expect.equals(0, set.length); | 19 Expect.equals(0, set.length); |
20 Expect.equals(false, set.contains(1)); | 20 Expect.equals(false, set.contains(1)); |
21 | 21 |
22 for (int i = 0; i < 10; i++) { | 22 for (int i = 0; i < 10; i++) { |
23 set.add(i); | 23 Expect.equals(true, set.add(i)); |
24 } | 24 } |
25 | 25 |
26 Expect.equals(10, set.length); | 26 Expect.equals(10, set.length); |
27 for (int i = 0; i < 10; i++) { | 27 for (int i = 0; i < 10; i++) { |
28 Expect.equals(true, set.contains(i)); | 28 Expect.equals(true, set.contains(i)); |
29 } | 29 } |
30 | 30 |
31 Expect.equals(10, set.length); | 31 Expect.equals(10, set.length); |
32 | 32 |
33 for (int i = 10; i < 20; i++) { | 33 for (int i = 10; i < 20; i++) { |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 filtered.add(10); | 107 filtered.add(10); |
108 Expect.equals(false, filtered.every(testEvery)); | 108 Expect.equals(false, filtered.every(testEvery)); |
109 | 109 |
110 // Test Set.some. | 110 // Test Set.some. |
111 testSome(int val) { | 111 testSome(int val) { |
112 return (val == 4); | 112 return (val == 4); |
113 } | 113 } |
114 | 114 |
115 Expect.equals(true, set.some(testSome)); | 115 Expect.equals(true, set.some(testSome)); |
116 Expect.equals(true, filtered.some(testSome)); | 116 Expect.equals(true, filtered.some(testSome)); |
117 filtered.remove(4); | 117 Expect.equals(true, filtered.remove(4)); |
118 Expect.equals(false, filtered.some(testSome)); | 118 Expect.equals(false, filtered.some(testSome)); |
119 | 119 |
120 // Test Set.intersection. | 120 // Test Set.intersection. |
121 Set intersection = set.intersection(filtered); | 121 Set intersection = set.intersection(filtered); |
122 Expect.equals(true, set.contains(0)); | 122 Expect.equals(true, set.contains(0)); |
123 Expect.equals(true, set.contains(2)); | 123 Expect.equals(true, set.contains(2)); |
124 Expect.equals(true, set.contains(6)); | 124 Expect.equals(true, set.contains(6)); |
125 Expect.equals(true, set.contains(8)); | 125 Expect.equals(true, set.contains(8)); |
126 Expect.equals(false, intersection.contains(1)); | 126 Expect.equals(false, intersection.contains(1)); |
127 Expect.equals(false, intersection.contains(3)); | 127 Expect.equals(false, intersection.contains(3)); |
(...skipping 26 matching lines...) Expand all Loading... |
154 for (int i = 0; i < 10; i++) { | 154 for (int i = 0; i < 10; i++) { |
155 Expect.equals(true, set.contains(i)); | 155 Expect.equals(true, set.contains(i)); |
156 } | 156 } |
157 for (int i = 10; i < 20; i++) { | 157 for (int i = 10; i < 20; i++) { |
158 Expect.equals(false, set.contains(i)); | 158 Expect.equals(false, set.contains(i)); |
159 } | 159 } |
160 | 160 |
161 // Test Set.clear. | 161 // Test Set.clear. |
162 set.clear(); | 162 set.clear(); |
163 Expect.equals(0, set.length); | 163 Expect.equals(0, set.length); |
164 set.add(11); | 164 Expect.equals(true, set.add(11)); |
165 Expect.equals(1, set.length); | 165 Expect.equals(1, set.length); |
166 } | 166 } |
167 } | 167 } |
168 | 168 |
169 main() { | 169 main() { |
170 SetTest.testMain(); | 170 SetTest.testMain(); |
171 } | 171 } |
OLD | NEW |