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

Side by Side Diff: tests/compiler/dart2js/link_test.dart

Issue 177963002: Use List instead of Link in the type system. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Rebase and some algorithmic bugs fixed. Created 6 years, 9 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
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 4
5 import "package:expect/expect.dart"; 5 import "package:expect/expect.dart";
6 import '../../../sdk/lib/_internal/compiler/implementation/util/util.dart'; 6 import '../../../sdk/lib/_internal/compiler/implementation/util/util.dart';
7 import '../../../sdk/lib/_internal/compiler/implementation/util/util_implementat ion.dart'; 7 import 'link_helper.dart';
8 8
9 main() { 9 main() {
10 test(const Link<Comparable>().prepend('three').prepend(2).prepend('one'), 10 test(const Link<Comparable>().prepend('three').prepend(2).prepend('one'),
11 ['one', 2, 'three']); 11 ['one', 2, 'three']);
12 test(const Link<Comparable>().prepend(3).prepend('two').prepend(1), 12 test(const Link<Comparable>().prepend(3).prepend('two').prepend(1),
13 [1, 'two', 3]); 13 [1, 'two', 3]);
14 test(const Link<String>().prepend('single'), ['single']); 14 test(const Link<String>().prepend('single'), ['single']);
15 test(const Link(), []); 15 test(const Link(), []);
16 testFromList([]);
17 testFromList([0]);
18 testFromList([0, 1]);
19 testFromList([0, 1, 2]);
20 testFromList([0, 1, 2, 3]);
21 testFromList([0, 1, 2, 3, 4]);
22 testFromList([0, 1, 2, 3, 4, 5]);
23 testSkip(); 16 testSkip();
24 } 17 }
25 18
26 testFromList(List list) {
27 test(new Link.fromList(list), list);
28 }
29
30 test(Link link, List list) { 19 test(Link link, List list) {
31 Expect.equals(list.isEmpty, link.isEmpty); 20 Expect.equals(list.isEmpty, link.isEmpty);
32 int i = 0; 21 int i = 0;
33 for (var element in link.toList()) { 22 for (var element in link.toList()) {
34 Expect.equals(list[i++], element); 23 Expect.equals(list[i++], element);
35 } 24 }
36 Expect.equals(list.length, i); 25 Expect.equals(list.length, i);
37 i = 0; 26 i = 0;
38 for (var element in link) { 27 for (var element in link) {
39 Expect.equals(list[i++], element); 28 Expect.equals(list[i++], element);
40 } 29 }
41 Expect.equals(list.length, i); 30 Expect.equals(list.length, i);
42 i = 0; 31 i = 0;
43 for (; !link.isEmpty; link = link.tail) { 32 for (; !link.isEmpty; link = link.tail) {
44 Expect.equals(list[i++], link.head); 33 Expect.equals(list[i++], link.head);
45 } 34 }
46 Expect.equals(list.length, i); 35 Expect.equals(list.length, i);
47 Expect.isTrue(link.isEmpty); 36 Expect.isTrue(link.isEmpty);
48 } 37 }
49 38
50 testSkip() { 39 testSkip() {
51 var nonEmptyLink = new Link.fromList([0, 1, 2, 3, 4, 5]); 40 var nonEmptyLink = LinkFromList([0, 1, 2, 3, 4, 5]);
52 for (int i = 0 ; i < 5; i++) { 41 for (int i = 0 ; i < 5; i++) {
53 var link = nonEmptyLink.skip(i); 42 var link = nonEmptyLink.skip(i);
54 Expect.isFalse(link.isEmpty); 43 Expect.isFalse(link.isEmpty);
55 Expect.equals(i, link.head); 44 Expect.equals(i, link.head);
56 } 45 }
57 Expect.isTrue(nonEmptyLink.skip(6).isEmpty); 46 Expect.isTrue(nonEmptyLink.skip(6).isEmpty);
58 Expect.throws(() => nonEmptyLink.skip(7), (e) => e is RangeError); 47 Expect.throws(() => nonEmptyLink.skip(7), (e) => e is RangeError);
59 48
60 var emptyLink = const Link(); 49 var emptyLink = const Link();
61 Expect.isTrue(emptyLink.skip(0).isEmpty); 50 Expect.isTrue(emptyLink.skip(0).isEmpty);
62 Expect.throws(() => emptyLink.skip(1), (e) => e is RangeError); 51 Expect.throws(() => emptyLink.skip(1), (e) => e is RangeError);
63 } 52 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698