| 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 (including maps). | 
| 7  */ | 7  */ | 
| 8 | 8 | 
| 9 #library('collection_to_string'); | 9 #library('collection_to_string'); | 
| 10 #import('dart:math', prefix: 'Math'); | 10 #import('dart:math', prefix: 'Math'); | 
| 11 | 11 | 
| 12 // TODO(jjb): seed random number generator when API allows it | 12 // TODO(jjb): seed random number generator when API allows it | 
| 13 | 13 | 
| 14 const int NUM_TESTS = 300; | 14 const int NUM_TESTS = 300; | 
| 15 const int MAX_COLLECTION_SIZE = 7; | 15 const int MAX_COLLECTION_SIZE = 7; | 
| 16 | 16 | 
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 115  * If exact is true, the returned collections will not be, and will not contain | 115  * If exact is true, the returned collections will not be, and will not contain | 
| 116  * a collection with ill-defined iteration order (i.e., a HashSet or HashMap). | 116  * a collection with ill-defined iteration order (i.e., a HashSet or HashMap). | 
| 117  */ | 117  */ | 
| 118 Object randomCollection(int size, StringBuffer stringRep, {bool exact}) { | 118 Object randomCollection(int size, StringBuffer stringRep, {bool exact}) { | 
| 119   return randomCollectionHelper(size, exact, stringRep, []); | 119   return randomCollectionHelper(size, exact, stringRep, []); | 
| 120 } | 120 } | 
| 121 | 121 | 
| 122 /** | 122 /** | 
| 123  * Return a random collection (or map) of the specified size, placing its | 123  * Return a random collection (or map) of the specified size, placing its | 
| 124  * string representation into the given string buffer. The beingMade | 124  * string representation into the given string buffer. The beingMade | 
| 125  * parameter is a list of collections currently under construction, i.e., | 125  * parameter is a list of collections currently under construction, i.e., | 
| 126  * candidates for recursive references. | 126  * candidates for recursive references. | 
| 127  * | 127  * | 
| 128  * If exact is true, the returned collections will not be, and will not contain | 128  * If exact is true, the returned collections will not be, and will not contain | 
| 129  * a collection with ill-defined iteration order (i.e., a HashSet or HashMap). | 129  * a collection with ill-defined iteration order (i.e., a HashSet or HashMap). | 
| 130  */ | 130  */ | 
| 131 Object randomCollectionHelper(int size, bool exact, StringBuffer stringRep, | 131 Object randomCollectionHelper(int size, bool exact, StringBuffer stringRep, | 
| 132     List beingMade) { | 132     List beingMade) { | 
| 133   double interfaceFrac = rand.nextDouble(); | 133   double interfaceFrac = rand.nextDouble(); | 
| 134 | 134 | 
| 135   if (exact) { | 135   if (exact) { | 
| (...skipping 13 matching lines...) Expand all  Loading... | 
| 149       return randomSet(size, exact, stringRep, beingMade); | 149       return randomSet(size, exact, stringRep, beingMade); | 
| 150     } else { | 150     } else { | 
| 151       return randomMap(size, exact, stringRep, beingMade); | 151       return randomMap(size, exact, stringRep, beingMade); | 
| 152     } | 152     } | 
| 153   } | 153   } | 
| 154 } | 154 } | 
| 155 | 155 | 
| 156 /** | 156 /** | 
| 157  * Return a random List of the specified size, placing its string | 157  * Return a random List of the specified size, placing its string | 
| 158  * representation into the given string buffer. The beingMade | 158  * representation into the given string buffer. The beingMade | 
| 159  * parameter is a list of collections currently under construction, i.e., | 159  * parameter is a list of collections currently under construction, i.e., | 
| 160  * candidates for recursive references. | 160  * candidates for recursive references. | 
| 161  * | 161  * | 
| 162  * If exact is true, the returned collections will not be, and will not contain | 162  * If exact is true, the returned collections will not be, and will not contain | 
| 163  * a collection with ill-defined iteration order (i.e., a HashSet or HashMap). | 163  * a collection with ill-defined iteration order (i.e., a HashSet or HashMap). | 
| 164  */ | 164  */ | 
| 165 List randomList(int size, bool exact, StringBuffer stringRep, List beingMade) { | 165 List randomList(int size, bool exact, StringBuffer stringRep, List beingMade) { | 
| 166   return populateRandomCollection(size, exact, stringRep, beingMade, []); | 166   return populateRandomCollection(size, exact, stringRep, beingMade, []); | 
| 167 } | 167 } | 
| 168 | 168 | 
| 169 /** | 169 /** | 
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 294 bool randomBool() { | 294 bool randomBool() { | 
| 295   return rand.nextBool(); | 295   return rand.nextBool(); | 
| 296 } | 296 } | 
| 297 | 297 | 
| 298 /** Returns the alphabetized characters in a string. */ | 298 /** Returns the alphabetized characters in a string. */ | 
| 299 String alphagram(String s) { | 299 String alphagram(String s) { | 
| 300   List<int> chars = s.charCodes(); | 300   List<int> chars = s.charCodes(); | 
| 301   chars.sort((int a, int b) => a - b); | 301   chars.sort((int a, int b) => a - b); | 
| 302   return new String.fromCharCodes(chars); | 302   return new String.fromCharCodes(chars); | 
| 303 } | 303 } | 
| OLD | NEW | 
|---|