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 queue_test; | 5 library queue_test; |
6 | 6 |
7 class QueueTest { | 7 class QueueTest { |
8 | 8 |
9 static testMain() { | 9 static testMain() { |
10 Queue queue = new Queue(); | 10 Queue queue = new Queue(); |
(...skipping 23 matching lines...) Expand all Loading... |
34 checkQueue(queue, 3, 1110); | 34 checkQueue(queue, 3, 1110); |
35 | 35 |
36 int mapTest(int value) { | 36 int mapTest(int value) { |
37 return value ~/ 10; | 37 return value ~/ 10; |
38 } | 38 } |
39 | 39 |
40 bool is10(int value) { | 40 bool is10(int value) { |
41 return (value == 10); | 41 return (value == 10); |
42 } | 42 } |
43 | 43 |
44 Queue mapped = queue.map(mapTest); | 44 Queue mapped = new Queue.from(queue.mappedBy(mapTest)); |
45 checkQueue(mapped, 3, 111); | 45 checkQueue(mapped, 3, 111); |
46 checkQueue(queue, 3, 1110); | 46 checkQueue(queue, 3, 1110); |
47 Expect.equals(1, mapped.removeFirst()); | 47 Expect.equals(1, mapped.removeFirst()); |
48 Expect.equals(100, mapped.removeLast()); | 48 Expect.equals(100, mapped.removeLast()); |
49 Expect.equals(10, mapped.removeFirst()); | 49 Expect.equals(10, mapped.removeFirst()); |
50 | 50 |
51 Queue other = queue.filter(is10); | 51 Queue other = new Queue.from(queue.where(is10)); |
52 checkQueue(other, 1, 10); | 52 checkQueue(other, 1, 10); |
53 | 53 |
54 Expect.equals(true, queue.some(is10)); | 54 Expect.equals(true, queue.any(is10)); |
55 | 55 |
56 bool isInstanceOfInt(int value) { | 56 bool isInstanceOfInt(int value) { |
57 return (value is int); | 57 return (value is int); |
58 } | 58 } |
59 | 59 |
60 Expect.equals(true, queue.every(isInstanceOfInt)); | 60 Expect.equals(true, queue.every(isInstanceOfInt)); |
61 | 61 |
62 Expect.equals(false, queue.every(is10)); | 62 Expect.equals(false, queue.every(is10)); |
63 | 63 |
64 bool is1(int value) { | 64 bool is1(int value) { |
65 return (value == 1); | 65 return (value == 1); |
66 } | 66 } |
67 Expect.equals(false, queue.some(is1)); | 67 Expect.equals(false, queue.any(is1)); |
68 | 68 |
69 queue.clear(); | 69 queue.clear(); |
70 Expect.equals(0, queue.length); | 70 Expect.equals(0, queue.length); |
71 | 71 |
72 var exception = null; | 72 var exception = null; |
73 try { | 73 try { |
74 queue.removeFirst(); | 74 queue.removeFirst(); |
75 } on StateError catch (e) { | 75 } on StateError catch (e) { |
76 exception = e; | 76 exception = e; |
77 } | 77 } |
(...skipping 13 matching lines...) Expand all Loading... |
91 queue.addFirst(2); | 91 queue.addFirst(2); |
92 Expect.equals(2, queue.first); | 92 Expect.equals(2, queue.first); |
93 Expect.equals(1, queue.last); | 93 Expect.equals(1, queue.last); |
94 | 94 |
95 queue.addLast(3); | 95 queue.addLast(3); |
96 Expect.equals(3, queue.last); | 96 Expect.equals(3, queue.last); |
97 bool isGreaterThanOne(int value) { | 97 bool isGreaterThanOne(int value) { |
98 return (value > 1); | 98 return (value > 1); |
99 } | 99 } |
100 | 100 |
101 other = queue.filter(isGreaterThanOne); | 101 other = new Queue.from(queue.where(isGreaterThanOne)); |
102 checkQueue(other, 2, 5); | 102 checkQueue(other, 2, 5); |
103 | 103 |
104 testAddAll(); | 104 testAddAll(); |
105 } | 105 } |
106 | 106 |
107 static void checkQueue(Queue queue, int expectedSize, int expectedSum) { | 107 static void checkQueue(Queue queue, int expectedSize, int expectedSum) { |
108 Expect.equals(expectedSize, queue.length); | 108 Expect.equals(expectedSize, queue.length); |
109 int sum = 0; | 109 int sum = 0; |
110 void sumElements(int value) { | 110 void sumElements(int value) { |
111 sum += value; | 111 sum += value; |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 entry1 = entry1.nextEntry(); | 177 entry1 = entry1.nextEntry(); |
178 entry2 = entry2.nextEntry(); | 178 entry2 = entry2.nextEntry(); |
179 } | 179 } |
180 Expect.equals(null, entry2); | 180 Expect.equals(null, entry2); |
181 } | 181 } |
182 } | 182 } |
183 | 183 |
184 main() { | 184 main() { |
185 QueueTest.testMain(); | 185 QueueTest.testMain(); |
186 } | 186 } |
OLD | NEW |