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 ListTest { | 5 class ListTest { |
6 | 6 |
7 static testMain() { | 7 static testMain() { |
8 testList(); | 8 testList(); |
9 testExpandableList(); | 9 testExpandableList(); |
10 } | 10 } |
11 | 11 |
12 static void expectValues(list, val1, val2, val3, val4) { | 12 static void expectValues(list, val1, val2, val3, val4) { |
13 Expect.equals(true, list.length == 4); | 13 Expect.equals(true, list.length == 4); |
14 Expect.equals(true, list.length == 4); | 14 Expect.equals(true, list.length == 4); |
15 Expect.equals(true, !list.isEmpty()); | 15 Expect.equals(true, !list.isEmpty()); |
16 Expect.equals(list[0], val1); | 16 Expect.equals(list[0], val1); |
17 Expect.equals(list[1], val2); | 17 Expect.equals(list[1], val2); |
18 Expect.equals(list[2], val3); | 18 Expect.equals(list[2], val3); |
19 Expect.equals(list[3], val4); | 19 Expect.equals(list[3], val4); |
20 } | 20 } |
21 | 21 |
22 static void testClosures(List list) { | 22 static void testClosures(List list) { |
| 23 testMap(val) {return val * 2 + 10; } |
| 24 Collection mapped = list.map(testMap); |
| 25 Expect.equals(mapped.length, list.length); |
| 26 for (var i = 0; i < list.length; i++) { |
| 27 Expect.equals(mapped[i], list[i]*2 + 10); |
| 28 } |
| 29 |
23 testFilter(val) { return val == 3; } | 30 testFilter(val) { return val == 3; } |
24 Collection filtered = list.filter(testFilter); | 31 Collection filtered = list.filter(testFilter); |
25 Expect.equals(filtered.length, 1); | 32 Expect.equals(filtered.length, 1); |
26 | 33 |
27 testEvery(val) { return val != 11; } | 34 testEvery(val) { return val != 11; } |
28 bool test = list.every(testEvery); | 35 bool test = list.every(testEvery); |
29 Expect.equals(true, test); | 36 Expect.equals(true, test); |
30 | 37 |
31 testSome(val) { return val == 1; } | 38 testSome(val) { return val == 1; } |
32 test = list.some(testSome); | 39 test = list.some(testSome); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 list.clear(); | 105 list.clear(); |
99 Expect.equals(list.length, 0); | 106 Expect.equals(list.length, 0); |
100 Expect.equals(list.length, 0); | 107 Expect.equals(list.length, 0); |
101 Expect.equals(true, list.isEmpty()); | 108 Expect.equals(true, list.isEmpty()); |
102 } | 109 } |
103 } | 110 } |
104 | 111 |
105 main() { | 112 main() { |
106 ListTest.testMain(); | 113 ListTest.testMain(); |
107 } | 114 } |
OLD | NEW |