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

Unified Diff: tests/corelib/collection_to_string_test.dart

Issue 292323006: Remove uses of IterableMixinWorkaround outside of VM and dart2js lists. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: tests/corelib/collection_to_string_test.dart
diff --git a/tests/corelib/collection_to_string_test.dart b/tests/corelib/collection_to_string_test.dart
index 97f25bc06d97d745a155bb07e8ce6bca8df5a391..79b29d91f8d6964b66b5a7415d0d3c3944c175af 100644
--- a/tests/corelib/collection_to_string_test.dart
+++ b/tests/corelib/collection_to_string_test.dart
@@ -23,7 +23,6 @@ main() {
rand = new Math.Random();
smokeTest();
exactTest();
- inexactTest();
}
@@ -86,34 +85,11 @@ void exactTest() {
StringBuffer stringRep = new StringBuffer();
Object o = randomCollection(size, stringRep, exact:true);
- print(stringRep);
- print(o);
- Expect.equals(o.toString(), stringRep.toString());
- }
-}
-
-/**
- * Generate a bunch of random collections (including Maps), and test that
- * there string form is as expected. The collections include collections
- * as elements, keys, and values, and include recursive references.
- *
- * This test includes collections with ill-defined iteration orders (i.e.,
- * HashSet, HashMap). As a consequence, it can't use equality tests on the
- * string form. Instead, it performs equality tests on their "alphagrams."
- * This might allow false positives, but it does give a fair amount of
- * confidence.
- */
-void inexactTest() {
- for (int i = 0; i < NUM_TESTS; i++) {
- // Choose a size from 0 to MAX_COLLECTION_SIZE, favoring larger sizes
- int size =
- Math.sqrt(random(MAX_COLLECTION_SIZE * MAX_COLLECTION_SIZE)).toInt();
-
- StringBuffer stringRep = new StringBuffer();
- Object o = randomCollection(size, stringRep, exact:false);
- print(stringRep);
- print(o);
- Expect.equals(alphagram(o.toString()), alphagram(stringRep.toString()));
+ String expected = stringRep.toString();
+ String actual = o.toString();
+ print("Expect: $expected");
Søren Gjesse 2014/05/23 07:18:13 Debug print.
Lasse Reichstein Nielsen 2014/05/23 09:09:53 Not really, they were already in the test, I just
+ print("Actual: $actual");
+ Expect.equals(expected, actual);
}
}
@@ -138,7 +114,7 @@ Object randomCollection(int size, StringBuffer stringRep, {bool exact}) {
* a collection with ill-defined iteration order (i.e., a HashSet or HashMap).
*/
Object randomCollectionHelper(int size, bool exact, StringBuffer stringRep,
- List beingMade) {
+ List beingMade) {
double interfaceFrac = rand.nextDouble();
if (exact) {
@@ -188,7 +164,8 @@ Queue randomQueue(int size, bool exact, StringBuffer stringRep, List beingMade){
*/
Set randomSet(int size, bool exact, StringBuffer stringRep, List beingMade) {
// Until we have LinkedHashSet, method will only be called with exact==true
- return populateRandomSet(size, exact, stringRep, beingMade, new Set());
+ return populateRandomCollection(
+ size, exact, stringRep, beingMade, new Set(), "{}");
}
/**
@@ -211,7 +188,7 @@ Map randomMap(int size, bool exact, StringBuffer stringRep, List beingMade) {
* recursive references.
*
* If exact is true, the elements of the returned collections will not be,
- * and will not contain a collection with ill-defined iteration order
+ * and will not contain, a collection with undefined iteration order
* (i.e., a HashSet or HashMap).
*/
populateRandomCollection(int size, bool exact,
@@ -227,15 +204,19 @@ populateRandomCollection(int size, bool exact,
if (i != 0) stringRep.write(', ');
coll.add(randomElement(random(size), exact, stringRep, beingMade));
}
- if (size > 5 && delimiters == "()") {
+ if (size > 5 && coll is! Map
+ // Lists don't yet use ListMixin or its toString.
+ // Remove this line when they do.
+ && coll is! List /// 01: ok
+ ) {
const int MAX_LENGTH = 80;
const int MIN_COUNT = 3;
const int MAX_COUNT = 100;
- // It's an iterable, it may omit some elements.
+ // It may omit some elements.
int end = stringRep.length;
if (size > MAX_COUNT) {
- // Last two elements are also omitted, just find the first three or
- // first 60 characters.
+ // Last two elements are also omitted, just find the first three elements
+ // or first 60 characters.
for (int i = MIN_COUNT; i < size; i++) {
int startIndex = indices[i];
if (startIndex - start > MAX_LENGTH - 6) { // Limit - ", ...)".length.
@@ -257,6 +238,9 @@ populateRandomCollection(int size, bool exact,
if (lengthAfter + ellipsisSize + lastTwoLength > MAX_LENGTH - 1) {
// Omit this element and everything up to the last two.
int elementStart = indices[i];
+ if (elementStart + ellipsisSize + lastTwoLength >= stringRep.length) {
+ break;
+ }
// Rewrite string buffer by copying it out, clearing, and putting
// the parts back in.
String buffer = stringRep.toString();
@@ -277,22 +261,6 @@ populateRandomCollection(int size, bool exact,
return coll;
}
-/** Like populateRandomCollection, but for sets (elements must be hashable) */
-Set populateRandomSet(int size, bool exact, StringBuffer stringRep,
- List beingMade, Set set) {
- stringRep.write('{');
-
- for (int i = 0; i < size; i++) {
- if (i != 0) stringRep.write(', ');
- set.add(i);
- stringRep.write(i);
- }
-
- stringRep.write('}');
- return set;
-}
-
-
/** Like populateRandomCollection, but for maps. */
Map populateRandomMap(int size, bool exact, StringBuffer stringRep,
List beingMade, Map map) {
@@ -330,10 +298,10 @@ Object randomElement(int size, bool exact, StringBuffer stringRep,
result = random(1000);
stringRep.write(result);
} else if (elementTypeFrac < 2/3) {
- // Element Is a random (new) collection
+ // Element is a random (new) collection
result = randomCollectionHelper(size, exact, stringRep, beingMade);
} else {
- // Element Is a random recursive ref
+ // Element is a random recursive ref
result = beingMade[random(beingMade.length)];
if (result is List) {
stringRep.write('[...]');
@@ -355,11 +323,3 @@ int random(int max) {
bool randomBool() {
return rand.nextBool();
}
-
-/** Returns the alphabetized characters in a string. */
-String alphagram(String s) {
- // Calling [toList] to convert unmodifiable list to normal list.
- List<int> chars = s.codeUnits.toList();
- chars.sort((int a, int b) => a - b);
- return new String.fromCharCodes(chars);
-}

Powered by Google App Engine
This is Rietveld 408576698