| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 class ListTest { | |
| 6 | |
| 7 static testMain() { | |
| 8 testList(); | |
| 9 testExpandableList(); | |
| 10 } | |
| 11 | |
| 12 static void expectValues(list, val1, val2, val3, val4) { | |
| 13 Expect.equals(true, list.length == 4); | |
| 14 Expect.equals(true, list.length == 4); | |
| 15 Expect.equals(true, !list.isEmpty()); | |
| 16 Expect.equals(list[0], val1); | |
| 17 Expect.equals(list[1], val2); | |
| 18 Expect.equals(list[2], val3); | |
| 19 Expect.equals(list[3], val4); | |
| 20 } | |
| 21 | |
| 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 | |
| 30 testFilter(val) { return val == 3; } | |
| 31 Collection filtered = list.filter(testFilter); | |
| 32 Expect.equals(filtered.length, 1); | |
| 33 | |
| 34 testEvery(val) { return val != 11; } | |
| 35 bool test = list.every(testEvery); | |
| 36 Expect.equals(true, test); | |
| 37 | |
| 38 testSome(val) { return val == 1; } | |
| 39 test = list.some(testSome); | |
| 40 Expect.equals(true, test); | |
| 41 | |
| 42 testSomeFirst(val) { return val == 0; } | |
| 43 test = list.some(testSomeFirst); | |
| 44 Expect.equals(true, test); | |
| 45 | |
| 46 testSomeLast(val) { return val == (list.length - 1); } | |
| 47 test = list.some(testSomeLast); | |
| 48 Expect.equals(true, test); | |
| 49 } | |
| 50 | |
| 51 static void testList() { | |
| 52 List list = new List(4); | |
| 53 Expect.equals(list.length, 4); | |
| 54 list[0] = 4; | |
| 55 expectValues(list, 4, null, null, null); | |
| 56 String val = "fisk"; | |
| 57 list[1] = val; | |
| 58 expectValues(list, 4, val, null, null); | |
| 59 double d = 2.0; | |
| 60 list[3] = d; | |
| 61 expectValues(list, 4, val, null, d); | |
| 62 | |
| 63 for (int i = 0; i < list.length; i++) { | |
| 64 list[i] = i; | |
| 65 } | |
| 66 | |
| 67 for (int i = 0; i < 4; i++) { | |
| 68 Expect.equals(list[i], i); | |
| 69 } | |
| 70 | |
| 71 testClosures(list); | |
| 72 | |
| 73 var exception = null; | |
| 74 try { | |
| 75 list.clear(); | |
| 76 } catch (UnsupportedOperationException e) { | |
| 77 exception = e; | |
| 78 } | |
| 79 Expect.equals(true, exception != null); | |
| 80 } | |
| 81 | |
| 82 static void testExpandableList() { | |
| 83 List list = new List(); | |
| 84 Expect.equals(true, list.isEmpty()); | |
| 85 Expect.equals(list.length, 0); | |
| 86 list.add(4); | |
| 87 Expect.equals(1, list.length); | |
| 88 Expect.equals(true, !list.isEmpty()); | |
| 89 Expect.equals(list.length, 1); | |
| 90 Expect.equals(list.length, 1); | |
| 91 Expect.equals(list.removeLast(), 4); | |
| 92 | |
| 93 for (int i = 0; i < 10; i++) { | |
| 94 list.add(i); | |
| 95 } | |
| 96 | |
| 97 Expect.equals(list.length, 10); | |
| 98 for (int i = 0; i < 10; i++) { | |
| 99 Expect.equals(list[i], i); | |
| 100 } | |
| 101 | |
| 102 testClosures(list); | |
| 103 | |
| 104 Expect.equals(list.removeLast(), 9); | |
| 105 list.clear(); | |
| 106 Expect.equals(list.length, 0); | |
| 107 Expect.equals(list.length, 0); | |
| 108 Expect.equals(true, list.isEmpty()); | |
| 109 } | |
| 110 } | |
| 111 | |
| 112 main() { | |
| 113 ListTest.testMain(); | |
| 114 } | |
| OLD | NEW |