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; } | 23 testMap(val) {return val * 2 + 10; } |
24 Collection mapped = list.map(testMap); | 24 Collection mapped = list.map(testMap); |
25 Expect.equals(mapped.length, list.length); | 25 Expect.equals(mapped.length, list.length); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 try { | 91 try { |
92 list.clear(); | 92 list.clear(); |
93 } on UnsupportedError catch (e) { | 93 } on UnsupportedError catch (e) { |
94 exception = e; | 94 exception = e; |
95 } | 95 } |
96 Expect.equals(true, exception != null); | 96 Expect.equals(true, exception != null); |
97 } | 97 } |
98 | 98 |
99 static void testExpandableList() { | 99 static void testExpandableList() { |
100 List list = new List(); | 100 List list = new List(); |
101 Expect.equals(true, list.isEmpty()); | 101 Expect.equals(true, list.isEmpty); |
102 Expect.equals(list.length, 0); | 102 Expect.equals(list.length, 0); |
103 list.add(4); | 103 list.add(4); |
104 Expect.equals(1, list.length); | 104 Expect.equals(1, list.length); |
105 Expect.equals(true, !list.isEmpty()); | 105 Expect.equals(true, !list.isEmpty); |
106 Expect.equals(list.length, 1); | 106 Expect.equals(list.length, 1); |
107 Expect.equals(list.length, 1); | 107 Expect.equals(list.length, 1); |
108 Expect.equals(list.removeLast(), 4); | 108 Expect.equals(list.removeLast(), 4); |
109 | 109 |
110 for (int i = 0; i < 10; i++) { | 110 for (int i = 0; i < 10; i++) { |
111 list.add(i); | 111 list.add(i); |
112 } | 112 } |
113 | 113 |
114 Expect.equals(list.length, 10); | 114 Expect.equals(list.length, 10); |
115 for (int i = 0; i < 10; i++) { | 115 for (int i = 0; i < 10; i++) { |
(...skipping 16 matching lines...) Expand all Loading... |
132 list[3] = 3; | 132 list[3] = 3; |
133 Expect.equals(-1, list.indexOf(100)); | 133 Expect.equals(-1, list.indexOf(100)); |
134 Expect.equals(-1, list.lastIndexOf(100)); | 134 Expect.equals(-1, list.lastIndexOf(100)); |
135 | 135 |
136 testClosures(list); | 136 testClosures(list); |
137 | 137 |
138 Expect.equals(list.removeLast(), 9); | 138 Expect.equals(list.removeLast(), 9); |
139 list.clear(); | 139 list.clear(); |
140 Expect.equals(list.length, 0); | 140 Expect.equals(list.length, 0); |
141 Expect.equals(list.length, 0); | 141 Expect.equals(list.length, 0); |
142 Expect.equals(true, list.isEmpty()); | 142 Expect.equals(true, list.isEmpty); |
143 } | 143 } |
144 } | 144 } |
145 | 145 |
146 class Yes { | 146 class Yes { |
147 operator ==(var other) => true; | 147 operator ==(var other) => true; |
148 } | 148 } |
149 | 149 |
150 main() { | 150 main() { |
151 ListTest.testMain(); | 151 ListTest.testMain(); |
152 } | 152 } |
OLD | NEW |