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 import 'dart:collection'; | 5 import 'dart:collection'; |
6 import "package:expect/expect.dart"; | 6 import "package:expect/expect.dart"; |
7 | 7 |
8 testRemove(base) { | 8 testRemove(base) { |
9 int length = base.length; | 9 int length = base.length; |
10 for (int i = 0; i < length; i++) { | 10 for (int i = 0; i < length; i++) { |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 for (var value in base) { | 77 for (var value in base) { |
78 Expect.isTrue(test(value), "$name: Found $value"); | 78 Expect.isTrue(test(value), "$name: Found $value"); |
79 } | 79 } |
80 for (var value in retained) { | 80 for (var value in retained) { |
81 Expect.isTrue(base.contains(value), "$name: Found $value"); | 81 Expect.isTrue(base.contains(value), "$name: Found $value"); |
82 } | 82 } |
83 } | 83 } |
84 | 84 |
85 void main() { | 85 void main() { |
86 var collections = [ | 86 var collections = [ |
87 [], [1], [2], [1, 2], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], | 87 [], |
88 [1, 3, 5, 7, 9], [2, 4, 6, 8, 10] | 88 [1], |
| 89 [2], |
| 90 [1, 2], |
| 91 [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], |
| 92 [1, 3, 5, 7, 9], |
| 93 [2, 4, 6, 8, 10] |
89 ]; | 94 ]; |
90 for (var base in collections) { | 95 for (var base in collections) { |
91 for (var delta in collections) { | 96 for (var delta in collections) { |
92 testRemove(base.toList()); | 97 testRemove(base.toList()); |
93 testRemove(base.toSet()); | 98 testRemove(base.toSet()); |
94 | 99 |
95 var deltaSet = delta.toSet(); | 100 var deltaSet = delta.toSet(); |
96 testRemoveWhere(base.toList(), deltaSet.contains); | 101 testRemoveWhere(base.toList(), deltaSet.contains); |
97 testRetainWhere(base.toList(), | 102 testRetainWhere(base.toList(), (e) => !deltaSet.contains(e)); |
98 (e) => !deltaSet.contains(e)); | |
99 | 103 |
100 testRemoveAll(base.toSet(), delta); | 104 testRemoveAll(base.toSet(), delta); |
101 testRemoveAll(base.toSet(), deltaSet); | 105 testRemoveAll(base.toSet(), deltaSet); |
102 testRetainAll(base.toSet(), delta); | 106 testRetainAll(base.toSet(), delta); |
103 testRetainAll(base.toSet(), deltaSet); | 107 testRetainAll(base.toSet(), deltaSet); |
104 testRemoveWhere(base.toSet(), deltaSet.contains); | 108 testRemoveWhere(base.toSet(), deltaSet.contains); |
105 testRetainWhere(base.toSet(), (e) => !deltaSet.contains(e)); | 109 testRetainWhere(base.toSet(), (e) => !deltaSet.contains(e)); |
106 | 110 |
107 // Test the ListBase class's List implementation. | 111 // Test the ListBase class's List implementation. |
108 testRemoveWhere(new MyList(base.toList()), deltaSet.contains); | 112 testRemoveWhere(new MyList(base.toList()), deltaSet.contains); |
109 testRetainWhere(new MyList(base.toList()), | 113 testRetainWhere(new MyList(base.toList()), (e) => !deltaSet.contains(e)); |
110 (e) => !deltaSet.contains(e)); | |
111 | |
112 } | 114 } |
113 } | 115 } |
114 } | 116 } |
115 | 117 |
116 class MyList<E> extends ListBase<E> { | 118 class MyList<E> extends ListBase<E> { |
117 List<E> _source; | 119 List<E> _source; |
118 MyList(this._source); | 120 MyList(this._source); |
119 int get length => _source.length; | 121 int get length => _source.length; |
120 void set length(int length) { _source.length = length; } | 122 void set length(int length) { |
121 E operator[](int index) => _source[index]; | 123 _source.length = length; |
122 void operator[]=(int index, E value) { _source[index] = value; } | 124 } |
| 125 |
| 126 E operator [](int index) => _source[index]; |
| 127 void operator []=(int index, E value) { |
| 128 _source[index] = value; |
| 129 } |
123 } | 130 } |
OLD | NEW |