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 "dart:typed_data"; | 6 import "dart:typed_data"; |
7 import "package:expect/expect.dart"; | 7 import "package:expect/expect.dart"; |
8 | 8 |
9 void main() { | 9 void main() { |
10 // Typed lists - fixed length and can only contain integers. | 10 // Typed lists - fixed length and can only contain integers. |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 testGrowableList(new Int8List(0).toList()); | 42 testGrowableList(new Int8List(0).toList()); |
43 testGrowableList(new Uint16List(0).toList()); | 43 testGrowableList(new Uint16List(0).toList()); |
44 testGrowableList(new Int16List(0).toList()); | 44 testGrowableList(new Int16List(0).toList()); |
45 testGrowableList(new Uint32List(0).toList()); | 45 testGrowableList(new Uint32List(0).toList()); |
46 testGrowableList(new Int32List(0).toList()); | 46 testGrowableList(new Int32List(0).toList()); |
47 } | 47 } |
48 | 48 |
49 void testLength(int length, List list) { | 49 void testLength(int length, List list) { |
50 Expect.equals(length, list.length); | 50 Expect.equals(length, list.length); |
51 (length == 0 ? Expect.isTrue : Expect.isFalse)(list.isEmpty); | 51 (length == 0 ? Expect.isTrue : Expect.isFalse)(list.isEmpty); |
| 52 (length != 0 ? Expect.isTrue : Expect.isFalse)(list.isNotEmpty); |
52 } | 53 } |
53 | 54 |
54 void testTypedLengthInvariantOperations(List list) { | 55 void testTypedLengthInvariantOperations(List list) { |
55 // length | 56 // length |
56 Expect.equals(list.length, 4); | 57 Expect.equals(list.length, 4); |
57 // operators [], []=. | 58 // operators [], []=. |
58 for (int i = 0; i < 4; i++) list[i] = 0; | 59 for (int i = 0; i < 4; i++) list[i] = 0; |
59 list[0] = 4; | 60 list[0] = 4; |
60 Expect.listEquals([4, 0, 0, 0], list); | 61 Expect.listEquals([4, 0, 0, 0], list); |
61 list[1] = 7; | 62 list[1] = 7; |
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
469 } | 470 } |
470 | 471 |
471 class MyFixedList<E> extends ListBase<E> { | 472 class MyFixedList<E> extends ListBase<E> { |
472 List<E> _source; | 473 List<E> _source; |
473 MyFixedList(this._source); | 474 MyFixedList(this._source); |
474 int get length => _source.length; | 475 int get length => _source.length; |
475 void set length(int length) { throw new UnsupportedError("Fixed length!"); } | 476 void set length(int length) { throw new UnsupportedError("Fixed length!"); } |
476 E operator[](int index) => _source[index]; | 477 E operator[](int index) => _source[index]; |
477 void operator[]=(int index, E value) { _source[index] = value; } | 478 void operator[]=(int index, E value) { _source[index] = value; } |
478 } | 479 } |
OLD | NEW |