diff options
author | Aleksandar Pokopec <aleksandar.prokopec@epfl.ch> | 2011-01-07 12:05:31 +0000 |
---|---|---|
committer | Aleksandar Pokopec <aleksandar.prokopec@epfl.ch> | 2011-01-07 12:05:31 +0000 |
commit | 733a3d756943e67d7608dbfd92aac445a080d69d (patch) | |
tree | 6ce9bb74cee997212845c6fac15c8923b54c55ec /test/files/scalacheck/parallel-collections | |
parent | 07edcee629fb00808fb695ba4ec68a26f3e99490 (diff) | |
download | scala-733a3d756943e67d7608dbfd92aac445a080d69d.tar.gz scala-733a3d756943e67d7608dbfd92aac445a080d69d.tar.bz2 scala-733a3d756943e67d7608dbfd92aac445a080d69d.zip |
Implemented a (slower) workaround for parallel ...
Implemented a (slower) workaround for parallel vectors. Implemented
group by.
No review.
Diffstat (limited to 'test/files/scalacheck/parallel-collections')
6 files changed, 87 insertions, 0 deletions
diff --git a/test/files/scalacheck/parallel-collections/IntOperators.scala b/test/files/scalacheck/parallel-collections/IntOperators.scala index 24330d7670..4a74b91da8 100644 --- a/test/files/scalacheck/parallel-collections/IntOperators.scala +++ b/test/files/scalacheck/parallel-collections/IntOperators.scala @@ -60,6 +60,10 @@ trait IntOperators extends Operators[Int] { Array.fill(1000)(1).toSeq ) def newArray(sz: Int) = new Array[Int](sz) + def groupByFunctions = List( + _ % 2, _ % 3, _ % 5, _ % 10, _ % 154, _% 3217, + _ * 2, _ + 1 + ) } diff --git a/test/files/scalacheck/parallel-collections/Operators.scala b/test/files/scalacheck/parallel-collections/Operators.scala index b4321cf805..72133a5009 100644 --- a/test/files/scalacheck/parallel-collections/Operators.scala +++ b/test/files/scalacheck/parallel-collections/Operators.scala @@ -21,6 +21,7 @@ trait Operators[T] { def foldArguments: List[(T, (T, T) => T)] def addAllTraversables: List[Traversable[T]] def newArray(sz: Int): Array[T] + def groupByFunctions: List[T => T] } diff --git a/test/files/scalacheck/parallel-collections/PairOperators.scala b/test/files/scalacheck/parallel-collections/PairOperators.scala index 2055c29d38..fe851114be 100644 --- a/test/files/scalacheck/parallel-collections/PairOperators.scala +++ b/test/files/scalacheck/parallel-collections/PairOperators.scala @@ -73,6 +73,10 @@ trait PairOperators[K, V] extends Operators[(K, V)] { def newArray(sz: Int) = new Array[(K, V)](sz) + def groupByFunctions = (koperators.groupByFunctions zip voperators.groupByFunctions) map { + opt => { (p: (K, V)) => (opt._1(p._1), opt._2(p._2)) } + } + } diff --git a/test/files/scalacheck/parallel-collections/ParallelIterableCheck.scala b/test/files/scalacheck/parallel-collections/ParallelIterableCheck.scala index 60e8c8b1f2..9ddd5781b9 100644 --- a/test/files/scalacheck/parallel-collections/ParallelIterableCheck.scala +++ b/test/files/scalacheck/parallel-collections/ParallelIterableCheck.scala @@ -414,6 +414,22 @@ abstract class ParallelIterableCheck[T](collName: String) extends Properties(col }).reduceLeft(_ && _) } + // property("groupBy must be equal") = forAll(collectionPairs) { + // case (t, coll) => + // (for ((f, ind) <- groupByFunctions.zipWithIndex) yield { + // val tgroup = t.groupBy(f) + // val cgroup = coll.groupBy(f) + // if (tgroup != cgroup || cgroup != tgroup) { + // println("from: " + t) + // println("and: " + coll) + // println("groups are: ") + // println(tgroup) + // println(cgroup) + // } + // ("operator " + ind) |: tgroup == cgroup && cgroup == tgroup + // }).reduceLeft(_ && _) + // } + } diff --git a/test/files/scalacheck/parallel-collections/ParallelVectorCheck.scala b/test/files/scalacheck/parallel-collections/ParallelVectorCheck.scala new file mode 100644 index 0000000000..a2b6cef96d --- /dev/null +++ b/test/files/scalacheck/parallel-collections/ParallelVectorCheck.scala @@ -0,0 +1,61 @@ +package scala.collection +package parallel.immutable + + + +import org.scalacheck._ +import org.scalacheck.Gen +import org.scalacheck.Gen._ +import org.scalacheck.Prop._ +import org.scalacheck.Properties +import org.scalacheck.Arbitrary._ + +import scala.collection._ +import scala.collection.parallel.ops._ + + +import immutable.Vector +import immutable.VectorBuilder + + + + +abstract class ParallelVectorCheck[T](tp: String) extends collection.parallel.ParallelSeqCheck[T]("ParVector[" + tp + "]") { + // ForkJoinTasks.defaultForkJoinPool.setMaximumPoolSize(Runtime.getRuntime.availableProcessors * 2) + // ForkJoinTasks.defaultForkJoinPool.setParallelism(Runtime.getRuntime.availableProcessors * 2) + + type CollType = ParVector[T] + + def isCheckingViews = false + + def hasStrictOrder = true + + def ofSize(vals: Seq[Gen[T]], sz: Int) = { + val vb = new immutable.VectorBuilder[T]() + val gen = vals(rnd.nextInt(vals.size)) + for (i <- 0 until sz) vb += sample(gen) + vb.result + } + + def fromSeq(a: Seq[T]) = { + val pa = ParVector.newCombiner[T] + for (elem <- a.toList) pa += elem + pa.result + } + +} + + + +object IntParallelVectorCheck extends ParallelVectorCheck[Int]("Int") with IntSeqOperators with IntValues { + override def instances(vals: Seq[Gen[Int]]) = oneOf(super.instances(vals), sized { sz => + (0 until sz).toArray.toSeq + }, sized { sz => + (-sz until 0).toArray.toSeq + }) +} + + + + + diff --git a/test/files/scalacheck/parallel-collections/pc.scala b/test/files/scalacheck/parallel-collections/pc.scala index 075a76ca6a..598c5a3751 100644 --- a/test/files/scalacheck/parallel-collections/pc.scala +++ b/test/files/scalacheck/parallel-collections/pc.scala @@ -29,6 +29,7 @@ class ParCollProperties extends Properties("Parallel collections") { include(mutable.IntParallelHashSetCheck) // parallel vectors + include(immutable.IntParallelVectorCheck) /* Views */ |