Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(243)

Side by Side Diff: tests/language/list_test.dart

Issue 11783009: Big merge from experimental to bleeding edge. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tests/language/language_dart2js.status ('k') | tests/language/local_function_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 // Dart test program for testing arrays. 4 // Dart test program for testing arrays.
5 5
6 class ListTest { 6 class ListTest {
7 static void TestIterator() { 7 static void TestIterator() {
8 List<int> a = new List<int>(10); 8 List<int> a = new List<int>.fixedLength(10);
9 int count = 0; 9 int count = 0;
10 10
11 // Basic iteration over ObjectList. 11 // Basic iteration over ObjectList.
12 for (int elem in a) { 12 for (int elem in a) {
13 Expect.equals(null, elem); 13 Expect.equals(null, elem);
14 count++; 14 count++;
15 } 15 }
16 Expect.equals(10, count); 16 Expect.equals(10, count);
17 17
18 // List length is 0. 18 // List length is 0.
(...skipping 16 matching lines...) Expand all
35 // Iterate over List. 35 // Iterate over List.
36 int sum2 = 0; 36 int sum2 = 0;
37 for (int elem in fa) { 37 for (int elem in fa) {
38 sum2 += elem; 38 sum2 += elem;
39 } 39 }
40 Expect.equals(sum, sum2); 40 Expect.equals(sum, sum2);
41 } 41 }
42 42
43 static void testMain() { 43 static void testMain() {
44 int len = 10; 44 int len = 10;
45 List a = new List(len); 45 List a = new List.fixedLength(len);
46 Expect.equals(true, a is List); 46 Expect.equals(true, a is List);
47 Expect.equals(len, a.length); 47 Expect.equals(len, a.length);
48 a.forEach((element) { Expect.equals(null, element); }); 48 a.forEach((element) { Expect.equals(null, element); });
49 a[1] = 1; 49 a[1] = 1;
50 Expect.equals(1, a[1]); 50 Expect.equals(1, a[1]);
51 Expect.throws(() => a[len], (e) => e is RangeError); 51 Expect.throws(() => a[len], (e) => e is RangeError);
52 52
53 Expect.throws(() { 53 Expect.throws(() {
54 List a = new List(4); 54 List a = new List.fixedLength(4);
55 a.setRange(1, 1, a, null); 55 a.setRange(1, 1, a, null);
56 }, (e) => true); 56 });
57 57
58 Expect.throws(() { 58 Expect.throws(() {
59 List a = new List(4); 59 List a = new List.fixedLength(4);
60 a.setRange(10, 1, a, 1); 60 a.setRange(10, 1, a, 1);
61 }, (e) => e is RangeError); 61 }, (e) => e is RangeError);
62 62
63 a = new List(4); 63 a = new List.fixedLength(4);
64 List b = new List(4); 64 List b = new List.fixedLength(4);
65 b.setRange(0, 4, a, 0); 65 b.setRange(0, 4, a, 0);
66 66
67 List<int> unsorted = [4, 3, 9, 12, -4, 9]; 67 List<int> unsorted = [4, 3, 9, 12, -4, 9];
68 int compare(a, b) { 68 int compare(a, b) {
69 if (a < b) return -1; 69 if (a < b) return -1;
70 if (a > b) return 1; 70 if (a > b) return 1;
71 return 0; 71 return 0;
72 } 72 }
73 unsorted.sort(compare); 73 unsorted.sort(compare);
74 Expect.equals(6, unsorted.length); 74 Expect.equals(6, unsorted.length);
(...skipping 13 matching lines...) Expand all
88 Expect.equals(false, t.contains(-3)); 88 Expect.equals(false, t.contains(-3));
89 Expect.equals(6, unsorted.length); 89 Expect.equals(6, unsorted.length);
90 Expect.equals(5, t.length); 90 Expect.equals(5, t.length);
91 TestIterator(); 91 TestIterator();
92 int element = unsorted[2]; 92 int element = unsorted[2];
93 Expect.equals(9, element); 93 Expect.equals(9, element);
94 94
95 Expect.throws(() => unsorted[2.1], 95 Expect.throws(() => unsorted[2.1],
96 (e) => e is ArgumentError || e is TypeError); 96 (e) => e is ArgumentError || e is TypeError);
97 97
98 Expect.throws(() => new List(-1), (e) => true); 98 Expect.throws(() => new List.fixedLength(-1));
99 Expect.throws(() => new List(99999999999999999999999), (e) => true); 99 Expect.throws(() => new List.fixedLength(99999999999999999999999));
100 100
101 List list = new List(); 101 List list = new List();
102 // We cannot write just 'list.removeLast' due to issue 3769. 102 // We cannot write just 'list.removeLast' due to issue 3769.
103 Expect.throws(() => list.removeLast(), 103 Expect.throws(() => list.removeLast(),
104 (e) => e is RangeError); 104 (e) => e is RangeError);
105 Expect.equals(0, list.length); 105 Expect.equals(0, list.length);
106 } 106 }
107 } 107 }
108 108
109 main() { 109 main() {
110 ListTest.testMain(); 110 ListTest.testMain();
111 } 111 }
OLDNEW
« no previous file with comments | « tests/language/language_dart2js.status ('k') | tests/language/local_function_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698