OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2012, 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 |
| 6 main() { |
| 7 testOperations(); |
| 8 } |
| 9 |
| 10 void testOperations() { |
| 11 // Comparison lists. |
| 12 List l = const [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; |
| 13 List r = const [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]; |
| 14 // A base list that starts out like l. |
| 15 List base = l.toList(); |
| 16 // A lazy reverse of base. |
| 17 List reversed = base.reversed; |
| 18 |
| 19 Expect.listEquals(r, reversed); |
| 20 Expect.listEquals(l, reversed.reversed); |
| 21 for (int i = 0; i < r.length; i++) { |
| 22 Expect.equals(r[i], reversed[i]); |
| 23 } |
| 24 Expect.equals(4, base.indexOf(5)); |
| 25 Expect.equals(5, reversed.indexOf(5)); |
| 26 |
| 27 // Combinations of start and end relative to start/end of list. |
| 28 List subr = [8, 7, 6, 5, 4, 3]; |
| 29 Expect.listEquals(subr, reversed.skip(2).take(6)); |
| 30 Expect.listEquals(subr, reversed.take(8).skip(2)); |
| 31 Expect.listEquals(subr, reversed.reversed.skip(2).take(6).reversed); |
| 32 Expect.listEquals(subr, reversed.reversed.take(8).skip(2).reversed); |
| 33 Expect.listEquals(subr, reversed.take(8).reversed.take(6).reversed); |
| 34 Expect.listEquals(subr, reversed.reversed.take(8).reversed.take(6)); |
| 35 Expect.listEquals(subr, reversed.reversed.skip(2).reversed.skip(2)); |
| 36 Expect.listEquals(subr, reversed.skip(2).reversed.skip(2).reversed); |
| 37 |
| 38 // Reverse const list. |
| 39 Expect.listEquals(r, l.reversed); |
| 40 } |
OLD | NEW |