summaryrefslogtreecommitdiff
path: root/test/files/scalacheck/parallel-collections/ParallelIterableCheck.scala
diff options
context:
space:
mode:
Diffstat (limited to 'test/files/scalacheck/parallel-collections/ParallelIterableCheck.scala')
-rw-r--r--test/files/scalacheck/parallel-collections/ParallelIterableCheck.scala82
1 files changed, 41 insertions, 41 deletions
diff --git a/test/files/scalacheck/parallel-collections/ParallelIterableCheck.scala b/test/files/scalacheck/parallel-collections/ParallelIterableCheck.scala
index e3f8778bca..26fa71d72c 100644
--- a/test/files/scalacheck/parallel-collections/ParallelIterableCheck.scala
+++ b/test/files/scalacheck/parallel-collections/ParallelIterableCheck.scala
@@ -16,14 +16,14 @@ import scala.collection.parallel._
abstract class ParallelIterableCheck[T](collName: String) extends Properties(collName) with Operators[T] {
type CollType <: ParIterable[T]
-
+
def values: Seq[Gen[T]]
def ofSize(vals: Seq[Gen[T]], sz: Int): Iterable[T]
def fromTraversable(t: Traversable[T]): CollType
def isCheckingViews: Boolean
def hasStrictOrder: Boolean
-
-
+
+
def instances(vals: Seq[Gen[T]]): Gen[Iterable[T]] = oneOf(
sized(
sz =>
@@ -31,46 +31,46 @@ abstract class ParallelIterableCheck[T](collName: String) extends Properties(col
),
for (sz <- choose(1000, 2000)) yield ofSize(vals, sz),
for (sz <- choose(4000, 4001)) yield ofSize(vals, sz),
- for (sz <- choose(10000, 10001)) yield ofSize(vals, sz)
+ for (sz <- choose(10000, 10001)) yield ofSize(vals, sz)
)
-
+
// used to check if constructed collection is valid
def checkDataStructureInvariants(orig: Traversable[T], cf: AnyRef) = {
// can be overriden in subclasses
true
}
-
+
def printDataStructureDebugInfo(cf: AnyRef) {
// can be overridden in subclasses
}
-
+
val rnd = new scala.util.Random
-
+
def sample(gen: Gen[T]): T = {
var s = gen.sample
while (s == None) s = gen.sample
s.get
}
-
+
def sampleValue: T = sample(values(rnd.nextInt(values.length)))
-
+
def collectionPairs = for (inst <- instances(values)) yield (inst, fromTraversable(inst))
-
+
def collectionPairsWithLengths = for (inst <- instances(values); s <- choose(0, inst.size))
yield (inst, fromTraversable(inst), s)
-
+
def collectionPairsWith2Indices = for (
inst <- instances(values);
f <- choose(0, inst.size);
s <- choose(0, inst.size))
yield (inst, fromTraversable(inst), f, s)
-
- def collectionTriplets = for (inst <- instances(values);
+
+ def collectionTriplets = for (inst <- instances(values);
updStart <- choose(0, inst.size); howMany <- choose(0, inst.size)) yield {
val modif = inst.toSeq.patch(updStart, inst.toSeq, howMany)
(inst, fromTraversable(inst), modif)
}
-
+
def areEqual(t1: GenTraversable[T], t2: GenTraversable[T]) = if (hasStrictOrder) {
t1 == t2 && t2 == t1
} else (t1, t2) match { // it is slightly delicate what `equal` means if the order is not strict
@@ -81,14 +81,14 @@ abstract class ParallelIterableCheck[T](collName: String) extends Properties(col
i1s == i2s && i2s == i1s
case _ => t1 == t2 && t2 == t1
}
-
+
def printDebugInfo(coll: ParIterableLike[_, _, _]) {
println("Collection debug info: ")
coll.printDebugBuffer
println("Task debug info: ")
println(coll.tasksupport.debugMessages.mkString("\n"))
}
-
+
def printComparison(t: Traversable[_], coll: ParIterable[_], tf: Traversable[_], cf: ParIterable[_], ind: Int) {
printDebugInfo(coll)
println("Operator: " + ind)
@@ -108,7 +108,7 @@ abstract class ParallelIterableCheck[T](collName: String) extends Properties(col
println("tf == cf - " + (tf == cf))
println("cf == tf - " + (cf == tf))
}
-
+
property("reductions must be equal for assoc. operators") = forAll(collectionPairs) { case (t, coll) =>
if (t.size != 0) {
val results = for ((op, ind) <- reduceOperators.zipWithIndex) yield {
@@ -126,7 +126,7 @@ abstract class ParallelIterableCheck[T](collName: String) extends Properties(col
results.reduceLeft(_ && _)
} else "has size 0" |: true
}
-
+
property("counts must be equal") = forAll(collectionPairs) { case (t, coll) =>
val results = for ((pred, ind) <- countPredicates.zipWithIndex) yield {
val tc = t.count(pred)
@@ -142,19 +142,19 @@ abstract class ParallelIterableCheck[T](collName: String) extends Properties(col
}
results.reduceLeft(_ && _)
}
-
+
property("forall must be equal") = forAll(collectionPairs) { case (t, coll) =>
val results = for ((pred, ind) <- forallPredicates.zipWithIndex)
yield ("op index: " + ind) |: t.forall(pred) == coll.forall(pred)
results.reduceLeft(_ && _)
}
-
+
property("exists must be equal") = forAll(collectionPairs) { case (t, coll) =>
val results = for ((pred, ind) <- existsPredicates.zipWithIndex)
yield ("op index: " + ind) |: t.exists(pred) == coll.exists(pred)
results.reduceLeft(_ && _)
}
-
+
property("both must find or not find an element") = forAll(collectionPairs) { case (t, coll) =>
val results = for ((pred, ind) <- findPredicates.zipWithIndex) yield {
val ft = t.find(pred)
@@ -163,7 +163,7 @@ abstract class ParallelIterableCheck[T](collName: String) extends Properties(col
}
results.reduceLeft(_ && _)
}
-
+
property("mappings must be equal") = forAll(collectionPairs) { case (t, coll) =>
val results = for ((f, ind) <- mapFunctions.zipWithIndex) yield {
val ms = t.map(f)
@@ -184,7 +184,7 @@ abstract class ParallelIterableCheck[T](collName: String) extends Properties(col
}
results.reduceLeft(_ && _)
}
-
+
property("collects must be equal") = forAll(collectionPairs) { case (t, coll) =>
val results = for ((f, ind) <- partialMapFunctions.zipWithIndex) yield {
val ps = t.collect(f)
@@ -200,12 +200,12 @@ abstract class ParallelIterableCheck[T](collName: String) extends Properties(col
}
results.reduceLeft(_ && _)
}
-
+
property("flatMaps must be equal") = forAll(collectionPairs) { case (t, coll) =>
(for ((f, ind) <- flatMapFunctions.zipWithIndex)
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 {
val tf = t.filter(p)
@@ -234,7 +234,7 @@ abstract class ParallelIterableCheck[T](collName: String) extends Properties(col
("op index: " + ind) |: tf == cf && cf == tf && invs
}).reduceLeft(_ && _)
}
-
+
property("filterNots must be equal") = forAll(collectionPairs) { case (t, coll) =>
(for ((p, ind) <- filterNotPredicates.zipWithIndex) yield {
val tf = t.filterNot(p)
@@ -243,7 +243,7 @@ abstract class ParallelIterableCheck[T](collName: String) extends Properties(col
("op index: " + ind) |: tf == cf && cf == tf
}).reduceLeft(_ && _)
}
-
+
if (!isCheckingViews) property("partitions must be equal") = forAll(collectionPairs) { case (t, coll) =>
(for ((p, ind) <- partitionPredicates.zipWithIndex) yield {
val tpart = t.partition(p)
@@ -257,15 +257,15 @@ abstract class ParallelIterableCheck[T](collName: String) extends Properties(col
("op index: " + ind) |: tpart == cpart
}).reduceLeft(_ && _)
}
-
+
if (hasStrictOrder) property("takes must be equal") = forAll(collectionPairsWithLengths) { case (t, coll, n) =>
("take " + n + " elements") |: t.take(n) == coll.take(n)
}
-
+
if (hasStrictOrder) property("drops must be equal") = forAll(collectionPairsWithLengths) { case (t, coll, n) =>
("drop " + n + " elements") |: t.drop(n) == coll.drop(n)
}
-
+
if (hasStrictOrder) property("slices must be equal") = forAll(collectionPairsWith2Indices)
{ case (t, coll, fr, slicelength) =>
val from = if (fr < 0) 0 else fr
@@ -289,7 +289,7 @@ abstract class ParallelIterableCheck[T](collName: String) extends Properties(col
}
("slice from " + from + " until " + until) |: tsl == collsl
}
-
+
if (hasStrictOrder) property("splits must be equal") = forAll(collectionPairsWithLengths) { case (t, coll, n) =>
val tspl = t.splitAt(n)
val cspl = coll.splitAt(n)
@@ -302,7 +302,7 @@ abstract class ParallelIterableCheck[T](collName: String) extends Properties(col
}
("splitAt " + n) |: tspl == cspl
}
-
+
if (hasStrictOrder) property("takeWhiles must be equal") = forAll(collectionPairs) { case (t, coll) =>
(for ((pred, ind) <- takeWhilePredicates.zipWithIndex) yield {
val tt = t.takeWhile(pred)
@@ -317,7 +317,7 @@ abstract class ParallelIterableCheck[T](collName: String) extends Properties(col
("operator " + ind) |: tt == ct
}).reduceLeft(_ && _)
}
-
+
if (hasStrictOrder) property("spans must be equal") = forAll(collectionPairs) { case (t, coll) =>
(for ((pred, ind) <- spanPredicates.zipWithIndex) yield {
val tsp = t.span(pred)
@@ -335,13 +335,13 @@ abstract class ParallelIterableCheck[T](collName: String) extends Properties(col
("operator " + ind) |: tsp == csp
}).reduceLeft(_ && _)
}
-
+
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 {
val tres = t.foldLeft(first)(op)
@@ -356,7 +356,7 @@ abstract class ParallelIterableCheck[T](collName: String) extends Properties(col
("operator " + ind) |: tres == cres
}).reduceLeft(_ && _)
}
-
+
property("++s must be equal") = forAll(collectionTriplets) { case (t, coll, colltoadd) =>
val toadd = colltoadd
val tr = t ++ toadd.iterator
@@ -383,7 +383,7 @@ abstract class ParallelIterableCheck[T](collName: String) extends Properties(col
("traversable " + ind) |: areEqual(tadded, cadded)
}).reduceLeft(_ && _)
}
-
+
if (hasStrictOrder) property("copies to array must be equal") = forAll(collectionPairs) { case (t, coll) =>
val tarr = newArray(t.size)
val collarr = newArray(coll.size)
@@ -397,7 +397,7 @@ abstract class ParallelIterableCheck[T](collName: String) extends Properties(col
}
tarr.toSeq == collarr.toSeq
}
-
+
if (hasStrictOrder) property("scans must be equal") = forAll(collectionPairs) {
case (t, coll) =>
(for (((first, op), ind) <- foldArguments.zipWithIndex) yield {
@@ -413,7 +413,7 @@ abstract class ParallelIterableCheck[T](collName: String) extends Properties(col
("operator " + ind) |: tscan == cscan && cscan == tscan
}).reduceLeft(_ && _)
}
-
+
property("groupBy must be equal") = forAll(collectionPairs) {
case (t, coll) =>
(for ((f, ind) <- groupByFunctions.zipWithIndex) yield {
@@ -429,7 +429,7 @@ abstract class ParallelIterableCheck[T](collName: String) extends Properties(col
("operator " + ind) |: tgroup == cgroup && cgroup == tgroup
}).reduceLeft(_ && _)
}
-
+
}