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 "package:expect/expect.dart"; | 5 import "package:expect/expect.dart"; |
6 import 'package:compiler/src/util/util.dart'; | 6 import 'package:compiler/src/util/util.dart'; |
7 import 'link_helper.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([]); | 16 testFromList([]); |
17 testFromList([0]); | 17 testFromList([0]); |
18 testFromList([0, 1]); | 18 testFromList([0, 1]); |
19 testFromList([0, 1, 2]); | 19 testFromList([0, 1, 2]); |
20 testFromList([0, 1, 2, 3]); | 20 testFromList([0, 1, 2, 3]); |
21 testFromList([0, 1, 2, 3, 4]); | 21 testFromList([0, 1, 2, 3, 4]); |
22 testFromList([0, 1, 2, 3, 4, 5]); | 22 testFromList([0, 1, 2, 3, 4, 5]); |
23 testSkip(); | 23 testSkip(); |
(...skipping 20 matching lines...) Expand all Loading... |
44 i = 0; | 44 i = 0; |
45 for (; !link.isEmpty; link = link.tail) { | 45 for (; !link.isEmpty; link = link.tail) { |
46 Expect.equals(list[i++], link.head); | 46 Expect.equals(list[i++], link.head); |
47 } | 47 } |
48 Expect.equals(list.length, i); | 48 Expect.equals(list.length, i); |
49 Expect.isTrue(link.isEmpty); | 49 Expect.isTrue(link.isEmpty); |
50 } | 50 } |
51 | 51 |
52 testSkip() { | 52 testSkip() { |
53 var nonEmptyLink = LinkFromList([0, 1, 2, 3, 4, 5]); | 53 var nonEmptyLink = LinkFromList([0, 1, 2, 3, 4, 5]); |
54 for (int i = 0 ; i < 5; i++) { | 54 for (int i = 0; i < 5; i++) { |
55 var link = nonEmptyLink.skip(i); | 55 var link = nonEmptyLink.skip(i); |
56 Expect.isFalse(link.isEmpty); | 56 Expect.isFalse(link.isEmpty); |
57 Expect.equals(i, link.head); | 57 Expect.equals(i, link.head); |
58 } | 58 } |
59 Expect.isTrue(nonEmptyLink.skip(6).isEmpty); | 59 Expect.isTrue(nonEmptyLink.skip(6).isEmpty); |
60 Expect.throws(() => nonEmptyLink.skip(7), (e) => e is RangeError); | 60 Expect.throws(() => nonEmptyLink.skip(7), (e) => e is RangeError); |
61 | 61 |
62 var emptyLink = const Link(); | 62 var emptyLink = const Link(); |
63 Expect.isTrue(emptyLink.skip(0).isEmpty); | 63 Expect.isTrue(emptyLink.skip(0).isEmpty); |
64 Expect.throws(() => emptyLink.skip(1), (e) => e is RangeError); | 64 Expect.throws(() => emptyLink.skip(1), (e) => e is RangeError); |
65 } | 65 } |
66 | 66 |
67 testCopyWithout() { | 67 testCopyWithout() { |
68 test(const Link().copyWithout(0), []); | 68 test(const Link().copyWithout(0), []); |
69 | 69 |
70 test(LinkFromList([0]).copyWithout(0), []); | 70 test(LinkFromList([0]).copyWithout(0), []); |
71 test(LinkFromList([0, 1]).copyWithout(0), [1]); | 71 test(LinkFromList([0, 1]).copyWithout(0), [1]); |
72 test(LinkFromList([0, 1, 2]).copyWithout(0), [1, 2]); | 72 test(LinkFromList([0, 1, 2]).copyWithout(0), [1, 2]); |
73 test(LinkFromList([0, 1, 2]).copyWithout(1), [0, 2]); | 73 test(LinkFromList([0, 1, 2]).copyWithout(1), [0, 2]); |
74 test(LinkFromList([0, 1, 2]).copyWithout(2), [0, 1]); | 74 test(LinkFromList([0, 1, 2]).copyWithout(2), [0, 1]); |
75 test(LinkFromList([0, 1, 2]).copyWithout(3), [0, 1, 2]); | 75 test(LinkFromList([0, 1, 2]).copyWithout(3), [0, 1, 2]); |
76 } | 76 } |
OLD | NEW |