| 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 library set_test; | 5 library set_test; |
| 6 | 6 |
| 7 import "dart:collection"; | 7 import "dart:collection"; |
| 8 | 8 |
| 9 void testMain(Set create()) { | 9 void testMain(Set create()) { |
| 10 Set set = create(); | 10 Set set = create(); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 set.forEach(testForEach); | 71 set.forEach(testForEach); |
| 72 Expect.equals(10 + 9 + 8 + 7 + 6 + 5 + 4 + 3 + 2 + 1, sum); | 72 Expect.equals(10 + 9 + 8 + 7 + 6 + 5 + 4 + 3 + 2 + 1, sum); |
| 73 | 73 |
| 74 sum = 0; | 74 sum = 0; |
| 75 | 75 |
| 76 mapped.forEach(testForEach); | 76 mapped.forEach(testForEach); |
| 77 Expect.equals(1 + 2 + 5 + 10 + 17 + 26 + 37 + 50 + 65 + 82, sum); | 77 Expect.equals(1 + 2 + 5 + 10 + 17 + 26 + 37 + 50 + 65 + 82, sum); |
| 78 | 78 |
| 79 // Test Set.filter. | 79 // Test Set.filter. |
| 80 testFilter(int val) { | 80 testFilter(int val) { |
| 81 return val % 2 == 0; | 81 return val.isEven; |
| 82 } | 82 } |
| 83 | 83 |
| 84 Set filtered = set.where(testFilter).toSet(); | 84 Set filtered = set.where(testFilter).toSet(); |
| 85 | 85 |
| 86 Expect.equals(5, filtered.length); | 86 Expect.equals(5, filtered.length); |
| 87 | 87 |
| 88 Expect.isTrue(filtered.contains(0)); | 88 Expect.isTrue(filtered.contains(0)); |
| 89 Expect.isTrue(filtered.contains(2)); | 89 Expect.isTrue(filtered.contains(2)); |
| 90 Expect.isTrue(filtered.contains(4)); | 90 Expect.isTrue(filtered.contains(4)); |
| 91 Expect.isTrue(filtered.contains(6)); | 91 Expect.isTrue(filtered.contains(6)); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 Expect.isTrue(filtered.containsAll(intersection)); | 138 Expect.isTrue(filtered.containsAll(intersection)); |
| 139 Expect.isTrue(intersection.isSubsetOf(set)); | 139 Expect.isTrue(intersection.isSubsetOf(set)); |
| 140 Expect.isTrue(intersection.isSubsetOf(filtered)); | 140 Expect.isTrue(intersection.isSubsetOf(filtered)); |
| 141 | 141 |
| 142 // Test Set.union. | 142 // Test Set.union. |
| 143 Set twice = create()..addAll([0, 2, 4, 6, 8, 10, 12, 14]); | 143 Set twice = create()..addAll([0, 2, 4, 6, 8, 10, 12, 14]); |
| 144 Set thrice = create()..addAll([0, 3, 6, 9, 12, 15]); | 144 Set thrice = create()..addAll([0, 3, 6, 9, 12, 15]); |
| 145 Set union = twice.union(thrice); | 145 Set union = twice.union(thrice); |
| 146 Expect.equals(11, union.length); | 146 Expect.equals(11, union.length); |
| 147 for (int i = 0; i < 16; i++) { | 147 for (int i = 0; i < 16; i++) { |
| 148 Expect.equals((i % 2) == 0 || (i % 3) == 0, union.contains(i)); | 148 Expect.equals(i.isEven || (i % 3) == 0, union.contains(i)); |
| 149 } | 149 } |
| 150 | 150 |
| 151 // Test Set.difference. | 151 // Test Set.difference. |
| 152 Set difference = twice.difference(thrice); | 152 Set difference = twice.difference(thrice); |
| 153 Expect.equals(5, difference.length); | 153 Expect.equals(5, difference.length); |
| 154 for (int i = 0; i < 16; i++) { | 154 for (int i = 0; i < 16; i++) { |
| 155 Expect.equals((i % 2) == 0 && (i % 3) != 0, difference.contains(i)); | 155 Expect.equals(i.isEven && (i % 3) != 0, difference.contains(i)); |
| 156 } | 156 } |
| 157 Expect.isTrue(twice.difference(thrice).difference(twice).isEmpty); | 157 Expect.isTrue(twice.difference(thrice).difference(twice).isEmpty); |
| 158 | 158 |
| 159 // Test Set.addAll. | 159 // Test Set.addAll. |
| 160 List list = new List.fixedLength(10); | 160 List list = new List.fixedLength(10); |
| 161 for (int i = 0; i < 10; i++) { | 161 for (int i = 0; i < 10; i++) { |
| 162 list[i] = i + 10; | 162 list[i] = i + 10; |
| 163 } | 163 } |
| 164 set.addAll(list); | 164 set.addAll(list); |
| 165 Expect.equals(20, set.length); | 165 Expect.equals(20, set.length); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 181 set.clear(); | 181 set.clear(); |
| 182 Expect.equals(0, set.length); | 182 Expect.equals(0, set.length); |
| 183 set.add(11); | 183 set.add(11); |
| 184 Expect.equals(1, set.length); | 184 Expect.equals(1, set.length); |
| 185 } | 185 } |
| 186 | 186 |
| 187 main() { | 187 main() { |
| 188 testMain(() => new Set()); | 188 testMain(() => new Set()); |
| 189 testMain(() => new HashSet()); | 189 testMain(() => new HashSet()); |
| 190 } | 190 } |
| OLD | NEW |