OLD | NEW |
(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 main() { |
| 6 var it, i; |
| 7 var entries = [1, 2, 3, 4, 499, 42]; |
| 8 var set = new OrderedSet(); |
| 9 set.addAll(entries); |
| 10 |
| 11 Expect.listEquals([1, 2, 3, 4, 499, 42], set.toList()); |
| 12 it = set.iterator; |
| 13 i = 0; |
| 14 while (it.moveNext()) { |
| 15 Expect.equals(entries[i++], it.current); |
| 16 } |
| 17 // Add the entries in reverse order and make sure that this doesn't change |
| 18 // the internal order. |
| 19 for (int j = entries.length - 1; j >= 0; j--) { |
| 20 set.add(entries[j]); |
| 21 } |
| 22 Expect.listEquals([1, 2, 3, 4, 499, 42], set.toList()); |
| 23 it = set.iterator; |
| 24 i = 0; |
| 25 while (it.moveNext()) { |
| 26 Expect.equals(entries[i++], it.current); |
| 27 } |
| 28 |
| 29 set = new OrderedSet.from(entries); |
| 30 Expect.listEquals([1, 2, 3, 4, 499, 42], set.toList()); |
| 31 it = set.iterator; |
| 32 i = 0; |
| 33 while (it.moveNext()) { |
| 34 Expect.equals(entries[i++], it.current); |
| 35 } |
| 36 // Add the entries in reverse order and make sure that this doesn't change |
| 37 // the internal order. |
| 38 for (int j = entries.length - 1; j >= 0; j--) { |
| 39 set.add(entries[j]); |
| 40 } |
| 41 Expect.listEquals([1, 2, 3, 4, 499, 42], set.toList()); |
| 42 it = set.iterator; |
| 43 i = 0; |
| 44 while (it.moveNext()) { |
| 45 Expect.equals(entries[i++], it.current); |
| 46 } |
| 47 } |
OLD | NEW |