summaryrefslogtreecommitdiff
path: root/test/files/scalacheck/parallel-collections/ParallelIterableCheck.scala
diff options
context:
space:
mode:
authorAleksandar Pokopec <aleksandar.prokopec@epfl.ch>2010-10-20 20:20:08 +0000
committerAleksandar Pokopec <aleksandar.prokopec@epfl.ch>2010-10-20 20:20:08 +0000
commitb689b912caa0e1bcd981c1a0092857ac83fb1e1d (patch)
tree194b115ae192b472baf904de14f7c61bce6af915 /test/files/scalacheck/parallel-collections/ParallelIterableCheck.scala
parentb1d9354a08107afab9c15d2ae1b8dded82b5ffef (diff)
downloadscala-b689b912caa0e1bcd981c1a0092857ac83fb1e1d.tar.gz
scala-b689b912caa0e1bcd981c1a0092857ac83fb1e1d.tar.bz2
scala-b689b912caa0e1bcd981c1a0092857ac83fb1e1d.zip
Some serious hash tries bugs fixed.
Plus one wild goose chase and test fixes. No review.
Diffstat (limited to 'test/files/scalacheck/parallel-collections/ParallelIterableCheck.scala')
-rw-r--r--test/files/scalacheck/parallel-collections/ParallelIterableCheck.scala108
1 files changed, 79 insertions, 29 deletions
diff --git a/test/files/scalacheck/parallel-collections/ParallelIterableCheck.scala b/test/files/scalacheck/parallel-collections/ParallelIterableCheck.scala
index bc08947af4..ea42e5efa3 100644
--- a/test/files/scalacheck/parallel-collections/ParallelIterableCheck.scala
+++ b/test/files/scalacheck/parallel-collections/ParallelIterableCheck.scala
@@ -21,6 +21,11 @@ abstract class ParallelIterableCheck[T](collName: String) extends Properties(col
def instances(valgens: Seq[Gen[T]]): Gen[Traversable[T]]
def fromTraversable(t: Traversable[T]): CollType
def isCheckingViews: Boolean
+ def hasStrictOrder: Boolean
+
+ def printDataStructureDebugInfo(cf: AnyRef) {
+ // can be overridden in subclasses
+ }
val rnd = new scala.util.Random
@@ -94,18 +99,26 @@ abstract class ParallelIterableCheck[T](collName: String) extends Properties(col
results.reduceLeft(_ && _)
}
+ def areEqual(t1: Traversable[T], t2: Traversable[T]) = if (hasStrictOrder) {
+ t1 == t2
+ } else (t1, t2) match { // it is slightly delicate what `equal` means if the order is not strict
+ case (m1: Map[_, _], m2: Map[_, _]) => m1 == m2
+ case (i1: Iterable[_], i2: Iterable[_]) => i1.toSet == i2.toSet
+ case _ => t1 == t2
+ }
+
property("mappings must be equal") = forAll(collectionPairs) { case (t, coll) =>
val results = for ((f, ind) <- mapFunctions.zipWithIndex) yield {
val ms = t.map(f)
val mp = coll.map(f)
- if (ms != mp) {
+ if (!areEqual(ms, mp)) {
println(t)
println(coll)
println("mapped to: ")
println(ms)
println(mp)
}
- ("op index: " + ind) |: ms == mp
+ ("op index: " + ind) |: areEqual(ms, mp)
}
results.reduceLeft(_ && _)
}
@@ -114,26 +127,39 @@ abstract class ParallelIterableCheck[T](collName: String) extends Properties(col
val results = for ((f, ind) <- partialMapFunctions.zipWithIndex) yield {
val ps = t.collect(f)
val pp = coll.collect(f)
- if (ps != pp) {
+ if (!areEqual(ps, pp)) {
println(t)
println(coll)
println("collected to: ")
println(ps)
println(pp)
}
- ("op index: " + ind) |: ps == pp
+ ("op index: " + ind) |: areEqual(ps, pp)
}
results.reduceLeft(_ && _)
}
property("flatMaps must be equal") = forAll(collectionPairs) { case (t, coll) =>
(for ((f, ind) <- flatMapFunctions.zipWithIndex)
- yield ("op index: " + ind) |: t.flatMap(f) == coll.flatMap(f)).reduceLeft(_ && _)
+ yield ("op index: " + ind) |: areEqual(t.flatMap(f), coll.flatMap(f))).reduceLeft(_ && _)
}
property("filters must be equal") = forAll(collectionPairs) { case (t, coll) =>
- (for ((p, ind) <- filterPredicates.zipWithIndex)
- yield ("op index: " + ind) |: t.filter(p) == coll.filter(p)).reduceLeft(_ && _)
+ (for ((p, ind) <- filterPredicates.zipWithIndex) yield {
+ val tf = t.filter(p)
+ val cf = coll.filter(p)
+ if (tf != cf || cf != tf) {
+ println(t)
+ println(coll)
+ println("filtered to:")
+ println(cf)
+ println(tf)
+ println("tf == cf - " + (tf == cf))
+ println("cf == tf - " + (cf == tf))
+ printDataStructureDebugInfo(cf)
+ }
+ ("op index: " + ind) |: tf == cf && cf == tf
+ }).reduceLeft(_ && _)
}
property("filterNots must be equal") = forAll(collectionPairs) { case (t, coll) =>
@@ -155,15 +181,15 @@ abstract class ParallelIterableCheck[T](collName: String) extends Properties(col
}).reduceLeft(_ && _)
}
- property("takes must be equal") = forAll(collectionPairsWithLengths) { case (t, coll, n) =>
+ if (hasStrictOrder) property("takes must be equal") = forAll(collectionPairsWithLengths) { case (t, coll, n) =>
("take " + n + " elements") |: t.take(n) == coll.take(n)
}
- property("drops must be equal") = forAll(collectionPairsWithLengths) { case (t, coll, n) =>
+ if (hasStrictOrder) property("drops must be equal") = forAll(collectionPairsWithLengths) { case (t, coll, n) =>
("drop " + n + " elements") |: t.drop(n) == coll.drop(n)
}
- property("slices must be equal") = forAll(collectionPairsWith2Indices)
+ if (hasStrictOrder) property("slices must be equal") = forAll(collectionPairsWith2Indices)
{ case (t, coll, fr, slicelength) =>
val from = if (fr < 0) 0 else fr
val until = if (from + slicelength > t.size) t.size else from + slicelength
@@ -187,7 +213,7 @@ abstract class ParallelIterableCheck[T](collName: String) extends Properties(col
("slice from " + from + " until " + until) |: tsl == collsl
}
- property("splits must be equal") = forAll(collectionPairsWithLengths) { case (t, coll, n) =>
+ if (hasStrictOrder) property("splits must be equal") = forAll(collectionPairsWithLengths) { case (t, coll, n) =>
val tspl = t.splitAt(n)
val cspl = coll.splitAt(n)
if (tspl != cspl) {
@@ -200,64 +226,88 @@ abstract class ParallelIterableCheck[T](collName: String) extends Properties(col
("splitAt " + n) |: tspl == cspl
}
- property("takeWhiles must be equal") = forAll(collectionPairs) { case (t, coll) =>
- (for ((pred, ind) <- takeWhilePredicates.zipWithIndex)
- yield ("operator " + ind) |: t.takeWhile(pred) == coll.takeWhile(pred)).reduceLeft(_ && _)
+ if (hasStrictOrder) property("takeWhiles must be equal") = forAll(collectionPairs) { case (t, coll) =>
+ (for ((pred, ind) <- takeWhilePredicates.zipWithIndex) yield {
+ val tt = t.takeWhile(pred)
+ val ct = coll.takeWhile(pred)
+ if (tt != ct) {
+ println("from: " + t)
+ println("and: " + coll)
+ println("taking while...")
+ println(tt)
+ println(ct)
+ }
+ ("operator " + ind) |: tt == ct
+ }).reduceLeft(_ && _)
}
- property("spans must be equal") = forAll(collectionPairs) { case (t, coll) =>
+ if (hasStrictOrder) property("spans must be equal") = forAll(collectionPairs) { case (t, coll) =>
(for ((pred, ind) <- spanPredicates.zipWithIndex) yield {
val tsp = t.span(pred)
val csp = coll.span(pred)
if (tsp != csp) {
println("from: " + t)
println("and: " + coll)
+ println("span with predicate " + ind)
println(tsp)
println(csp)
+ println("---------------------------------")
+ println(coll.span(pred))
+ println("---------------------------------")
}
("operator " + ind) |: tsp == csp
}).reduceLeft(_ && _)
}
- property("dropWhiles must be equal") = forAll(collectionPairs) { case (t, coll) =>
+ if (hasStrictOrder) property("dropWhiles must be equal") = forAll(collectionPairs) { case (t, coll) =>
(for ((pred, ind) <- dropWhilePredicates.zipWithIndex) yield {
("operator " + ind) |: t.dropWhile(pred) == coll.dropWhile(pred)
}).reduceLeft(_ && _)
}
property("folds must be equal for assoc. operators") = forAll(collectionPairs) { case (t, coll) =>
- (for (((first, op), ind) <- foldArguments.zipWithIndex)
- yield ("operator " + ind) |: t.foldLeft(first)(op) == coll.fold(first)(op)).reduceLeft(_ && _)
+ (for (((first, op), ind) <- foldArguments.zipWithIndex) yield {
+ val tres = t.foldLeft(first)(op)
+ val cres = coll.fold(first)(op)
+ if (cres != tres) {
+ println("from: " + t)
+ println("and: " + coll)
+ println("folds are: ")
+ println(tres)
+ println(cres)
+ }
+ ("operator " + ind) |: tres == cres
+ }).reduceLeft(_ && _)
}
property("++s must be equal") = forAll(collectionTriplets) { case (t, coll, colltoadd) =>
val toadd = colltoadd
- val tr = t ++ toadd
- val cr = coll ++ fromTraversable(toadd).iterator
- if (!tr.toList.iterator.sameElements(cr.iterator)) {
+ val tr = t ++ toadd.iterator
+ val cr = coll ++ toadd.iterator
+ if (areEqual(tr, cr)) {
println("from: " + t)
println("and: " + coll.iterator.toList)
println("adding: " + toadd)
println(tr.toList)
println(cr.iterator.toList)
}
- ("adding " |: tr == cr) &&
+ ("adding " |: areEqual(tr, cr)) &&
(for ((trav, ind) <- (addAllTraversables).zipWithIndex) yield {
val tadded = t ++ trav
- val cadded = coll ++ fromTraversable(trav.toList)
- if (tadded != cadded) {
+ val cadded = coll ++ collection.parallel.mutable.ParArray(trav.toSeq: _*)
+ if (!areEqual(tadded, cadded)) {
println("----------------------")
println("from: " + t)
- println("and: " + coll.iterator.toList)
+ println("and: " + coll)
println("adding: " + trav)
- println(tadded.toList)
- println(cadded.iterator.toList)
+ println(tadded)
+ println(cadded)
}
- ("traversable " + ind) |: (tadded) == (cadded)
+ ("traversable " + ind) |: areEqual(tadded, cadded)
}).reduceLeft(_ && _)
}
- property("copies to array must be equal") = forAll(collectionPairs) { case (t, coll) =>
+ if (hasStrictOrder) property("copies to array must be equal") = forAll(collectionPairs) { case (t, coll) =>
val tarr = newArray(t.size)
val collarr = newArray(coll.size)
t.copyToArray(tarr, 0, t.size)