| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 /** | 5 /** |
| 6 * Tests for the toString methods on collections and maps. | 6 * Tests for the toString methods on collections and maps. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 library collection_to_string; | 9 library collection_to_string; |
| 10 | 10 |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 /** | 200 /** |
| 201 * Populates the given empty collection with elements, emitting the string | 201 * Populates the given empty collection with elements, emitting the string |
| 202 * representation of the collection to stringRep. The beingMade parameter is | 202 * representation of the collection to stringRep. The beingMade parameter is |
| 203 * a list of collections currently under construction, i.e., candidates for | 203 * a list of collections currently under construction, i.e., candidates for |
| 204 * recursive references. | 204 * recursive references. |
| 205 * | 205 * |
| 206 * If exact is true, the elements of the returned collections will not be, | 206 * If exact is true, the elements of the returned collections will not be, |
| 207 * and will not contain a collection with ill-defined iteration order | 207 * and will not contain a collection with ill-defined iteration order |
| 208 * (i.e., a HashSet or HashMap). | 208 * (i.e., a HashSet or HashMap). |
| 209 */ | 209 */ |
| 210 Collection populateRandomCollection(int size, bool exact, | 210 populateRandomCollection(int size, bool exact, |
| 211 StringBuffer stringRep, List beingMade, Collection coll) { | 211 StringBuffer stringRep, List beingMade, var coll) { |
| 212 beingMade.add(coll); | 212 beingMade.add(coll); |
| 213 stringRep.write(coll is List ? '[' : '{'); | 213 stringRep.write(coll is List ? '[' : '{'); |
| 214 | 214 |
| 215 for (int i = 0; i < size; i++) { | 215 for (int i = 0; i < size; i++) { |
| 216 if (i != 0) stringRep.write(', '); | 216 if (i != 0) stringRep.write(', '); |
| 217 coll.add(randomElement(random(size), exact, stringRep, beingMade)); | 217 coll.add(randomElement(random(size), exact, stringRep, beingMade)); |
| 218 } | 218 } |
| 219 | 219 |
| 220 stringRep.write(coll is List ? ']' : '}'); | 220 stringRep.write(coll is List ? ']' : '}'); |
| 221 beingMade.removeLast(); | 221 beingMade.removeLast(); |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 return rand.nextBool(); | 298 return rand.nextBool(); |
| 299 } | 299 } |
| 300 | 300 |
| 301 /** Returns the alphabetized characters in a string. */ | 301 /** Returns the alphabetized characters in a string. */ |
| 302 String alphagram(String s) { | 302 String alphagram(String s) { |
| 303 // Calling [toList] to convert unmodifiable list to normal list. | 303 // Calling [toList] to convert unmodifiable list to normal list. |
| 304 List<int> chars = s.codeUnits.toList(); | 304 List<int> chars = s.codeUnits.toList(); |
| 305 chars.sort((int a, int b) => a - b); | 305 chars.sort((int a, int b) => a - b); |
| 306 return new String.fromCharCodes(chars); | 306 return new String.fromCharCodes(chars); |
| 307 } | 307 } |
| OLD | NEW |