| 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 #library("GrowableObjectArrayTest.dart"); | 5 #library("GrowableObjectArrayTest.dart"); |
| 6 #import("dart:coreimpl"); | 6 #import("dart:coreimpl"); |
| 7 | 7 |
| 8 class GrowableObjectArrayTest { | 8 class GrowableObjectArrayTest { |
| 9 | 9 |
| 10 static void testOutOfBoundForIndexOf() { | 10 static void testOutOfBoundForIndexOf() { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 Expect.equals(4, array.indexOf(1, 1)); | 31 Expect.equals(4, array.indexOf(1, 1)); |
| 32 Expect.equals(-1, array.lastIndexOf(4, 2)); | 32 Expect.equals(-1, array.lastIndexOf(4, 2)); |
| 33 | 33 |
| 34 Expect.equals(5, array.length); | 34 Expect.equals(5, array.length); |
| 35 | 35 |
| 36 testMap(int n) => n + 2; | 36 testMap(int n) => n + 2; |
| 37 | 37 |
| 38 GrowableObjectArray mapped = array.map(testMap); | 38 GrowableObjectArray mapped = array.map(testMap); |
| 39 | 39 |
| 40 Expect.equals(5, mapped.length); | 40 Expect.equals(5, mapped.length); |
| 41 | 41 |
| 42 Expect.equals(3, mapped[0]); | 42 Expect.equals(3, mapped[0]); |
| 43 Expect.equals(4, mapped[1]); | 43 Expect.equals(4, mapped[1]); |
| 44 Expect.equals(5, mapped[2]); | 44 Expect.equals(5, mapped[2]); |
| 45 Expect.equals(6, mapped[3]); | 45 Expect.equals(6, mapped[3]); |
| 46 Expect.equals(3, mapped[4]); | 46 Expect.equals(3, mapped[4]); |
| 47 | 47 |
| 48 Expect.equals(5, array.length); | 48 Expect.equals(5, array.length); |
| 49 | 49 |
| 50 Expect.equals(1, array[0]); | 50 Expect.equals(1, array[0]); |
| 51 Expect.equals(2, array[1]); | 51 Expect.equals(2, array[1]); |
| 52 Expect.equals(3, array[2]); | 52 Expect.equals(3, array[2]); |
| 53 Expect.equals(4, array[3]); | 53 Expect.equals(4, array[3]); |
| 54 Expect.equals(1, array[4]); | 54 Expect.equals(1, array[4]); |
| 55 | 55 |
| 56 bool found = false; | 56 bool found = false; |
| 57 array = array.filter(bool _(e) { | 57 array = array.filter(bool _(e) { |
| 58 return found || !(found = (e == 1)); | 58 return found || !(found = (e == 1)); |
| 59 }); | 59 }); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 83 Expect.equals(5, array.length); | 83 Expect.equals(5, array.length); |
| 84 array = array.filter((e) => e != 1 ); | 84 array = array.filter((e) => e != 1 ); |
| 85 Expect.equals(1, array.length); | 85 Expect.equals(1, array.length); |
| 86 Expect.equals(2, array[0]); | 86 Expect.equals(2, array[0]); |
| 87 | 87 |
| 88 // Check correct copy order/ | 88 // Check correct copy order/ |
| 89 array = new GrowableObjectArray<int>(); | 89 array = new GrowableObjectArray<int>(); |
| 90 for (int i = 0; i < 10; i++) { | 90 for (int i = 0; i < 10; i++) { |
| 91 array.add(i); | 91 array.add(i); |
| 92 } | 92 } |
| 93 array.copyFrom(array, 7, 8, 2); | 93 array.setRange(8, 2, array, 7); |
| 94 Expect.equals(7, array[7]); | 94 Expect.equals(7, array[7]); |
| 95 Expect.equals(7, array[8]); | 95 Expect.equals(7, array[8]); |
| 96 Expect.equals(8, array[9]); | 96 Expect.equals(8, array[9]); |
| 97 array.copyFrom(array, 5, 4, 2); | 97 array.setRange(4, 2, array, 5); |
| 98 Expect.equals(5, array[4]); | 98 Expect.equals(5, array[4]); |
| 99 Expect.equals(6, array[5]); | 99 Expect.equals(6, array[5]); |
| 100 Expect.equals(6, array[6]); | 100 Expect.equals(6, array[6]); |
| 101 | 101 |
| 102 testOutOfBoundForIndexOf(); | 102 testOutOfBoundForIndexOf(); |
| 103 | 103 |
| 104 GrowableObjectArray<int> h = new GrowableObjectArray<int>.withCapacity(10); | 104 GrowableObjectArray<int> h = new GrowableObjectArray<int>.withCapacity(10); |
| 105 List constArray = const [0, 1, 2, 3, 4]; | 105 List constArray = const [0, 1, 2, 3, 4]; |
| 106 h.addAll(constArray); | 106 h.addAll(constArray); |
| 107 Expect.equals(5, h.length); | 107 Expect.equals(5, h.length); |
| 108 } | 108 } |
| 109 } | 109 } |
| 110 | 110 |
| 111 main() { | 111 main() { |
| 112 GrowableObjectArrayTest.testMain(); | 112 GrowableObjectArrayTest.testMain(); |
| 113 } | 113 } |
| OLD | NEW |