diff options
Diffstat (limited to 'test/files/scalacheck/parallel-collections')
17 files changed, 303 insertions, 253 deletions
diff --git a/test/files/scalacheck/parallel-collections/IntOperators.scala b/test/files/scalacheck/parallel-collections/IntOperators.scala index 5c997962ba..4a74b91da8 100644 --- a/test/files/scalacheck/parallel-collections/IntOperators.scala +++ b/test/files/scalacheck/parallel-collections/IntOperators.scala @@ -106,7 +106,7 @@ trait IntSeqOperators extends IntOperators with SeqOperators[Int] { List(4, 5, 6, 7, 8, 9, 10), List(4, 5, 6, 7, 8, 9, 0), List(-4, -3, -2, -1) - ) + ) } diff --git a/test/files/scalacheck/parallel-collections/PairOperators.scala b/test/files/scalacheck/parallel-collections/PairOperators.scala index 4711e21c34..fe851114be 100644 --- a/test/files/scalacheck/parallel-collections/PairOperators.scala +++ b/test/files/scalacheck/parallel-collections/PairOperators.scala @@ -7,76 +7,76 @@ import scala.collection.parallel._ trait PairOperators[K, V] extends Operators[(K, V)] { def koperators: Operators[K] def voperators: Operators[V] - + private def zipPredicates(kps: List[K => Boolean], vps: List[V => Boolean]): List[((K, V)) => Boolean] = for { (kp, vp) <- koperators.countPredicates zip voperators.countPredicates } yield new Function1[(K, V), Boolean] { def apply(kv: (K, V)) = kp(kv._1) && vp(kv._2) } - + /* operators */ - + def reduceOperators = for { (kop, vop) <- koperators.reduceOperators zip voperators.reduceOperators } yield new Function2[(K, V), (K, V), (K, V)] { def apply(kv1: (K, V), kv2: (K, V)) = (kop(kv1._1, kv2._1), vop(kv1._2, kv2._2)) } - + def countPredicates = zipPredicates(koperators.countPredicates, voperators.countPredicates) - + def forallPredicates = zipPredicates(koperators.forallPredicates, voperators.forallPredicates) - + def existsPredicates = zipPredicates(koperators.existsPredicates, voperators.existsPredicates) - + def findPredicates = zipPredicates(koperators.findPredicates, voperators.findPredicates) - + def mapFunctions = for { (km, vm) <- koperators.mapFunctions zip voperators.mapFunctions } yield new Function1[(K, V), (K, V)] { def apply(kv: (K, V)) = (km(kv._1), vm(kv._2)) } - + def partialMapFunctions = for { (kpm, vpm) <- koperators.partialMapFunctions zip voperators.partialMapFunctions } yield new PartialFunction[(K, V), (K, V)] { def isDefinedAt(kv: (K, V)) = kpm.isDefinedAt(kv._1) && vpm.isDefinedAt(kv._2) def apply(kv: (K, V)) = (kpm(kv._1), vpm(kv._2)) } - + def flatMapFunctions = for { (kfm, vfm) <- koperators.flatMapFunctions zip voperators.flatMapFunctions } yield new Function1[(K, V), Traversable[(K, V)]] { def apply(kv: (K, V)) = kfm(kv._1).toIterable zip vfm(kv._2).toIterable } - + def filterPredicates = zipPredicates(koperators.filterPredicates, voperators.filterPredicates) - + def filterNotPredicates = filterPredicates - + def partitionPredicates = filterPredicates - + def takeWhilePredicates = zipPredicates(koperators.takeWhilePredicates, voperators.takeWhilePredicates) - + def dropWhilePredicates = takeWhilePredicates - + def spanPredicates = takeWhilePredicates - + def foldArguments = for { ((kinit, kop), (vinit, vop)) <- koperators.foldArguments zip voperators.foldArguments } yield ((kinit, vinit), new Function2[(K, V), (K, V), (K, V)] { def apply(kv1: (K, V), kv2: (K, V)) = (kop(kv1._1, kv2._1), vop(kv1._2, kv2._2)) }) - + def addAllTraversables = for { (kt, vt) <- koperators.addAllTraversables zip voperators.addAllTraversables } yield kt.toIterable zip vt.toIterable - + 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/PairValues.scala b/test/files/scalacheck/parallel-collections/PairValues.scala index 5007c4598b..864dad2425 100644 --- a/test/files/scalacheck/parallel-collections/PairValues.scala +++ b/test/files/scalacheck/parallel-collections/PairValues.scala @@ -17,7 +17,7 @@ import org.scalacheck.Arbitrary._ trait PairValues[K, V] { def kvalues: Seq[Gen[K]] def vvalues: Seq[Gen[V]] - + def values = for { kg <- kvalues vg <- vvalues diff --git a/test/files/scalacheck/parallel-collections/ParallelArrayCheck.scala b/test/files/scalacheck/parallel-collections/ParallelArrayCheck.scala index a01c8c7dbe..691a3e961e 100644 --- a/test/files/scalacheck/parallel-collections/ParallelArrayCheck.scala +++ b/test/files/scalacheck/parallel-collections/ParallelArrayCheck.scala @@ -17,22 +17,25 @@ import scala.collection.parallel.ops._ abstract class ParallelArrayCheck[T](tp: String) extends ParallelSeqCheck[T]("ParArray[" + tp + "]") { // ForkJoinTasks.defaultForkJoinPool.setMaximumPoolSize(Runtime.getRuntime.availableProcessors * 2) // ForkJoinTasks.defaultForkJoinPool.setParallelism(Runtime.getRuntime.availableProcessors * 2) - + type CollType = ParArray[T] - + def isCheckingViews = false - + def hasStrictOrder = true + def tasksupport: TaskSupport + def ofSize(vals: Seq[Gen[T]], sz: Int) = { val a = new mutable.ArrayBuffer[T](sz) val gen = vals(rnd.nextInt(vals.size)) for (i <- 0 until sz) a += sample(gen) a } - + def fromSeq(a: Seq[T]) = { val pa = new ParArray[T](a.size) + pa.tasksupport = tasksupport var i = 0 for (elem <- a.toList) { pa(i) = elem @@ -40,20 +43,20 @@ abstract class ParallelArrayCheck[T](tp: String) extends ParallelSeqCheck[T]("Pa } pa } - + property("array mappings must be equal") = forAll(collectionPairs) { case (t, coll) => val results = for ((f, ind) <- mapFunctions.zipWithIndex) yield ("op index: " + ind) |: t.map(f) == coll.map(f) results.reduceLeft(_ && _) } - + } -object IntParallelArrayCheck extends ParallelArrayCheck[Int]("Int") with IntSeqOperators with IntValues { +class IntParallelArrayCheck(val tasksupport: TaskSupport) extends ParallelArrayCheck[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 => + }, sized { sz => (-sz until 0).toArray.toSeq }) } diff --git a/test/files/scalacheck/parallel-collections/ParallelArrayTest.scala b/test/files/scalacheck/parallel-collections/ParallelArrayTest.scala index 680f6e1d28..db2b1ea01e 100644 --- a/test/files/scalacheck/parallel-collections/ParallelArrayTest.scala +++ b/test/files/scalacheck/parallel-collections/ParallelArrayTest.scala @@ -15,7 +15,7 @@ // /** // * this currently passes, but do we want it to? -// * does it have meaning to have an empty parallel array? +// * does it have meaning to have an empty parallel array? // */ // new ParallelArray(0) // () diff --git a/test/files/scalacheck/parallel-collections/ParallelArrayViewCheck.scala b/test/files/scalacheck/parallel-collections/ParallelArrayViewCheck.scala index d2a8fa7c22..9805e2644f 100644 --- a/test/files/scalacheck/parallel-collections/ParallelArrayViewCheck.scala +++ b/test/files/scalacheck/parallel-collections/ParallelArrayViewCheck.scala @@ -24,18 +24,18 @@ // extends ParallelSeqCheck[T]("ParallelSeqView[" + tp + ", ParallelArray[" + tp + "]]") { // // ForkJoinTasks.defaultForkJoinPool.setMaximumPoolSize(Runtime.getRuntime.availableProcessors * 2) // // ForkJoinTasks.defaultForkJoinPool.setParallelism(Runtime.getRuntime.availableProcessors * 2) - + // type CollType = ParallelSeqView[T, ParallelArray[T], ArraySeq[T]] - + // def isCheckingViews = true - + // def instances(vals: Seq[Gen[T]]): Gen[Seq[T]] = sized { sz => // val a = new ArrayBuffer[T](sz) // val gen = vals(rnd.nextInt(vals.size)) // for (i <- 0 until sz) a += sample(gen) // a // } - + // def fromSeq(a: Seq[T]) = { // val pa = new ParallelArray[T](a.size) // var i = 0 @@ -45,13 +45,13 @@ // } // pa.view // } - + // property("forces must be equal") = forAll(collectionPairs) { case (s, coll) => // val smodif = (s ++ s).reverse.take(s.length).reverse.zip(s).drop(s.length / 2) // val cmodif = (coll ++ s).reverse.take(s.length).reverse.zip(s).drop(s.length / 2).force // smodif == cmodif // } - + // } @@ -68,18 +68,18 @@ // extends ParallelSeqCheck[T]("ParallelSeqView[" + tp + "], ParallelArray[" + tp + "].++.patch.reverse.take.reverse") { // ForkJoinTasks.defaultForkJoinPool.setMaximumPoolSize(Runtime.getRuntime.availableProcessors * 2) // ForkJoinTasks.defaultForkJoinPool.setParallelism(Runtime.getRuntime.availableProcessors * 2) - + // type CollType = collection.parallel.ParallelSeq[T] - + // def isCheckingViews = true - + // def instances(vals: Seq[Gen[T]]): Gen[Seq[T]] = sized { sz => // val a = new ArrayBuffer[T](sz) // val gen = vals(rnd.nextInt(vals.size)) // for (i <- 0 until sz) a += sample(gen) // a // } - + // def fromSeq(a: Seq[T]) = { // val pa = new ParallelArray[T](a.size) // var i = 0 @@ -91,7 +91,7 @@ // val original = modified.take(modified.length / 2).reverse // original // } - + // } diff --git a/test/files/scalacheck/parallel-collections/ParallelCtrieCheck.scala b/test/files/scalacheck/parallel-collections/ParallelCtrieCheck.scala index e141c398fd..cf15afb3b9 100644 --- a/test/files/scalacheck/parallel-collections/ParallelCtrieCheck.scala +++ b/test/files/scalacheck/parallel-collections/ParallelCtrieCheck.scala @@ -18,22 +18,25 @@ import scala.collection.parallel.ops._ abstract class ParallelConcurrentTrieMapCheck[K, V](tp: String) extends ParallelMapCheck[K, V]("mutable.ParConcurrentTrieMap[" + tp + "]") { // ForkJoinTasks.defaultForkJoinPool.setMaximumPoolSize(Runtime.getRuntime.availableProcessors * 2) // ForkJoinTasks.defaultForkJoinPool.setParallelism(Runtime.getRuntime.availableProcessors * 2) - + type CollType = ParTrieMap[K, V] - + def isCheckingViews = false - + def hasStrictOrder = false - def ofSize(vals: Seq[Gen[(K, V)]], sz: Int) = { + def tasksupport: TaskSupport + + def ofSize(vals: Seq[Gen[(K, V)]], sz: Int) = { val ct = new concurrent.TrieMap[K, V] val gen = vals(rnd.nextInt(vals.size)) for (i <- 0 until sz) ct += sample(gen) ct } - + def fromTraversable(t: Traversable[(K, V)]) = { val pct = new ParTrieMap[K, V] + pct.tasksupport = tasksupport var i = 0 for (kv <- t.toList) { pct += kv @@ -41,33 +44,33 @@ abstract class ParallelConcurrentTrieMapCheck[K, V](tp: String) extends Parallel } pct } - + } -object IntIntParallelConcurrentTrieMapCheck extends ParallelConcurrentTrieMapCheck[Int, Int]("Int, Int") +class IntIntParallelConcurrentTrieMapCheck(val tasksupport: TaskSupport) extends ParallelConcurrentTrieMapCheck[Int, Int]("Int, Int") with PairOperators[Int, Int] with PairValues[Int, Int] { def intvalues = new IntValues {} def kvalues = intvalues.values def vvalues = intvalues.values - + val intoperators = new IntOperators {} def voperators = intoperators def koperators = intoperators - + override def printDataStructureDebugInfo(ds: AnyRef) = ds match { case pm: ParTrieMap[k, v] => println("Mutable parallel ctrie") case _ => println("could not match data structure type: " + ds.getClass) } - + override def checkDataStructureInvariants(orig: Traversable[(Int, Int)], ds: AnyRef) = ds match { // case pm: ParHashMap[k, v] if 1 == 0 => // disabled this to make tests faster // val invs = pm.brokenInvariants - + // val containsall = (for ((k, v) <- orig) yield { // if (pm.asInstanceOf[ParHashMap[Int, Int]].get(k) == Some(v)) true // else { @@ -75,8 +78,8 @@ with PairValues[Int, Int] // false // } // }).foldLeft(true)(_ && _) - - + + // if (invs.isEmpty) containsall // else { // println("Invariants broken:\n" + invs.mkString("\n")) @@ -84,7 +87,7 @@ with PairValues[Int, Int] // } case _ => true } - + } diff --git a/test/files/scalacheck/parallel-collections/ParallelHashMapCheck.scala b/test/files/scalacheck/parallel-collections/ParallelHashMapCheck.scala index 0152b1b435..34b3f33de2 100644 --- a/test/files/scalacheck/parallel-collections/ParallelHashMapCheck.scala +++ b/test/files/scalacheck/parallel-collections/ParallelHashMapCheck.scala @@ -17,22 +17,25 @@ import scala.collection.parallel.ops._ abstract class ParallelHashMapCheck[K, V](tp: String) extends ParallelMapCheck[K, V]("mutable.ParHashMap[" + tp + "]") { // ForkJoinTasks.defaultForkJoinPool.setMaximumPoolSize(Runtime.getRuntime.availableProcessors * 2) // ForkJoinTasks.defaultForkJoinPool.setParallelism(Runtime.getRuntime.availableProcessors * 2) - + type CollType = ParHashMap[K, V] - + def isCheckingViews = false - + def hasStrictOrder = false - def ofSize(vals: Seq[Gen[(K, V)]], sz: Int) = { + def tasksupport: TaskSupport + + def ofSize(vals: Seq[Gen[(K, V)]], sz: Int) = { val hm = new mutable.HashMap[K, V] val gen = vals(rnd.nextInt(vals.size)) for (i <- 0 until sz) hm += sample(gen) hm } - + def fromTraversable(t: Traversable[(K, V)]) = { val phm = new ParHashMap[K, V] + phm.tasksupport = tasksupport var i = 0 for (kv <- t.toList) { phm += kv @@ -40,33 +43,33 @@ abstract class ParallelHashMapCheck[K, V](tp: String) extends ParallelMapCheck[K } phm } - + } -object IntIntParallelHashMapCheck extends ParallelHashMapCheck[Int, Int]("Int, Int") +class IntIntParallelHashMapCheck(val tasksupport: TaskSupport) extends ParallelHashMapCheck[Int, Int]("Int, Int") with PairOperators[Int, Int] with PairValues[Int, Int] { def intvalues = new IntValues {} def kvalues = intvalues.values def vvalues = intvalues.values - + val intoperators = new IntOperators {} def voperators = intoperators def koperators = intoperators - + override def printDataStructureDebugInfo(ds: AnyRef) = ds match { case pm: ParHashMap[k, v] => println("Mutable parallel hash map\n" + pm.hashTableContents.debugInformation) case _ => println("could not match data structure type: " + ds.getClass) } - + override def checkDataStructureInvariants(orig: Traversable[(Int, Int)], ds: AnyRef) = ds match { // case pm: ParHashMap[k, v] if 1 == 0 => // disabled this to make tests faster // val invs = pm.brokenInvariants - + // val containsall = (for ((k, v) <- orig) yield { // if (pm.asInstanceOf[ParHashMap[Int, Int]].get(k) == Some(v)) true // else { @@ -74,8 +77,8 @@ with PairValues[Int, Int] // false // } // }).foldLeft(true)(_ && _) - - + + // if (invs.isEmpty) containsall // else { // println("Invariants broken:\n" + invs.mkString("\n")) @@ -83,7 +86,7 @@ with PairValues[Int, Int] // } case _ => true } - + } diff --git a/test/files/scalacheck/parallel-collections/ParallelHashSetCheck.scala b/test/files/scalacheck/parallel-collections/ParallelHashSetCheck.scala index a0a6d1ae5e..91de2472a7 100644 --- a/test/files/scalacheck/parallel-collections/ParallelHashSetCheck.scala +++ b/test/files/scalacheck/parallel-collections/ParallelHashSetCheck.scala @@ -17,34 +17,37 @@ import scala.collection.parallel.ops._ abstract class ParallelHashSetCheck[T](tp: String) extends ParallelSetCheck[T]("mutable.ParHashSet[" + tp + "]") { // ForkJoinTasks.defaultForkJoinPool.setMaximumPoolSize(Runtime.getRuntime.availableProcessors * 2) // ForkJoinTasks.defaultForkJoinPool.setParallelism(Runtime.getRuntime.availableProcessors * 2) - + type CollType = ParHashSet[T] - + def isCheckingViews = false - + def hasStrictOrder = false - def ofSize(vals: Seq[Gen[T]], sz: Int) = { + def tasksupport: TaskSupport + + def ofSize(vals: Seq[Gen[T]], sz: Int) = { val hm = new mutable.HashSet[T] val gen = vals(rnd.nextInt(vals.size)) for (i <- 0 until sz) hm += sample(gen) hm } - + def fromTraversable(t: Traversable[T]) = { - val phm = new ParHashSet[T] + val phs = new ParHashSet[T] + phs.tasksupport = tasksupport var i = 0 for (kv <- t.toList) { - phm += kv + phs += kv i += 1 } - phm + phs } - + } -object IntParallelHashSetCheck extends ParallelHashSetCheck[Int]("Int") +class IntParallelHashSetCheck(val tasksupport: TaskSupport) extends ParallelHashSetCheck[Int]("Int") with IntOperators with IntValues { @@ -54,12 +57,12 @@ with IntValues case _ => println("could not match data structure type: " + ds.getClass) } - + override def checkDataStructureInvariants(orig: Traversable[Int], ds: AnyRef) = ds match { // case pm: ParHashSet[t] if 1 == 0 => // // for an example of how not to write code proceed below // val invs = pm.brokenInvariants - + // val containsall = (for (elem <- orig) yield { // if (pm.asInstanceOf[ParHashSet[Int]](elem) == true) true // else { @@ -69,8 +72,8 @@ with IntValues // false // } // }).foldLeft(true)(_ && _) - - + + // if (invs.isEmpty) { // if (!containsall) println(pm.debugInformation) // containsall @@ -80,7 +83,7 @@ with IntValues // } case _ => true } - + } diff --git a/test/files/scalacheck/parallel-collections/ParallelHashTrieCheck.scala b/test/files/scalacheck/parallel-collections/ParallelHashTrieCheck.scala index 3a2893f48a..9e29be5429 100644 --- a/test/files/scalacheck/parallel-collections/ParallelHashTrieCheck.scala +++ b/test/files/scalacheck/parallel-collections/ParallelHashTrieCheck.scala @@ -17,22 +17,25 @@ import scala.collection.parallel.ops._ abstract class ParallelHashMapCheck[K, V](tp: String) extends ParallelMapCheck[K, V]("immutable.ParHashMap[" + tp + "]") { // ForkJoinTasks.defaultForkJoinPool.setMaximumPoolSize(Runtime.getRuntime.availableProcessors * 2) // ForkJoinTasks.defaultForkJoinPool.setParallelism(Runtime.getRuntime.availableProcessors * 2) - + type CollType = ParHashMap[K, V] - + def isCheckingViews = false - + def hasStrictOrder = false - + + def tasksupport: TaskSupport + def ofSize(vals: Seq[Gen[(K, V)]], sz: Int) = { var hm = new immutable.HashMap[K, V] val gen = vals(rnd.nextInt(vals.size)) for (i <- 0 until sz) hm += sample(gen) hm } - + def fromTraversable(t: Traversable[(K, V)]) = { var phm = new ParHashMap[K, V] + phm.tasksupport = tasksupport var i = 0 for (kv <- t.toList) { phm += kv @@ -40,22 +43,22 @@ abstract class ParallelHashMapCheck[K, V](tp: String) extends ParallelMapCheck[K } phm } - + } -object IntIntParallelHashMapCheck extends ParallelHashMapCheck[Int, Int]("Int, Int") +class IntIntParallelHashMapCheck(val tasksupport: TaskSupport) extends ParallelHashMapCheck[Int, Int]("Int, Int") with PairOperators[Int, Int] with PairValues[Int, Int] { def intvalues = new IntValues {} def kvalues = intvalues.values def vvalues = intvalues.values - + val intoperators = new IntOperators {} def voperators = intoperators def koperators = intoperators - + override def printDataStructureDebugInfo(ds: AnyRef) = ds match { case pm: ParHashMap[k, v] => pm.printDebugInfo @@ -69,48 +72,51 @@ with PairValues[Int, Int] abstract class ParallelHashSetCheck[T](tp: String) extends ParallelSetCheck[T]("immutable.ParHashSet[" + tp + "]") { // ForkJoinTasks.defaultForkJoinPool.setMaximumPoolSize(Runtime.getRuntime.availableProcessors * 2) // ForkJoinTasks.defaultForkJoinPool.setParallelism(Runtime.getRuntime.availableProcessors * 2) - + type CollType = ParHashSet[T] - + def isCheckingViews = false - + def hasStrictOrder = false - + + def tasksupport: TaskSupport + def ofSize(vals: Seq[Gen[T]], sz: Int) = { var hm = new immutable.HashSet[T] val gen = vals(rnd.nextInt(vals.size)) for (i <- 0 until sz) hm += sample(gen) hm } - + def fromTraversable(t: Traversable[T]) = { - var phm = new ParHashSet[T] + var phs = new ParHashSet[T] + phs.tasksupport = tasksupport var i = 0 for (kv <- t.toList) { - phm += kv + phs += kv i += 1 } - phm + phs } - + override def printDataStructureDebugInfo(ds: AnyRef) = ds match { case pm: ParHashSet[t] => println("Parallel hash set") case _ => println("could not match data structure type: " + ds.getClass) } - + } -object IntParallelHashSetCheck extends ParallelHashSetCheck[Int]("Int") +class IntParallelHashSetCheck(val tasksupport: TaskSupport) extends ParallelHashSetCheck[Int]("Int") with IntOperators with IntValues { def intvalues = new IntValues {} def kvalues = intvalues.values def vvalues = intvalues.values - + override def printDataStructureDebugInfo(ds: AnyRef) = ds match { case pm: ParHashMap[k, v] => pm.printDebugInfo diff --git a/test/files/scalacheck/parallel-collections/ParallelIterableCheck.scala b/test/files/scalacheck/parallel-collections/ParallelIterableCheck.scala index e3f8778bca..774d6f428b 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,34 +356,39 @@ 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 - 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 " |: areEqual(tr, cr)) && - (for ((trav, ind) <- (addAllTraversables).zipWithIndex) yield { - val tadded = t ++ trav - val cadded = coll ++ collection.parallel.mutable.ParArray(trav.toSeq: _*) - if (!areEqual(tadded, cadded)) { - println("----------------------") + try { + val toadd = colltoadd + val tr = t ++ toadd.iterator + val cr = coll ++ toadd.iterator + if (!areEqual(tr, cr)) { println("from: " + t) - println("and: " + coll) - println("adding: " + trav) - println(tadded) - println(cadded) + println("and: " + coll.iterator.toList) + println("adding: " + toadd) + println(tr.toList) + println(cr.iterator.toList) } - ("traversable " + ind) |: areEqual(tadded, cadded) - }).reduceLeft(_ && _) + ("adding " |: areEqual(tr, cr)) && + (for ((trav, ind) <- (addAllTraversables).zipWithIndex) yield { + val tadded = t ++ trav + val cadded = coll ++ collection.parallel.mutable.ParArray(trav.toSeq: _*) + if (!areEqual(tadded, cadded)) { + println("----------------------") + println("from: " + t) + println("and: " + coll) + println("adding: " + trav) + println(tadded) + println(cadded) + } + ("traversable " + ind) |: areEqual(tadded, cadded) + }).reduceLeft(_ && _) + } catch { + case e: java.lang.Exception => + throw e + } } - + 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 +402,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 +418,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 +434,7 @@ abstract class ParallelIterableCheck[T](collName: String) extends Properties(col ("operator " + ind) |: tgroup == cgroup && cgroup == tgroup }).reduceLeft(_ && _) } - + } diff --git a/test/files/scalacheck/parallel-collections/ParallelMapCheck1.scala b/test/files/scalacheck/parallel-collections/ParallelMapCheck1.scala index b6af8f41bd..d4643e7f2c 100644 --- a/test/files/scalacheck/parallel-collections/ParallelMapCheck1.scala +++ b/test/files/scalacheck/parallel-collections/ParallelMapCheck1.scala @@ -16,15 +16,15 @@ import scala.collection.parallel._ abstract class ParallelMapCheck[K, V](collname: String) extends ParallelIterableCheck[(K, V)](collname) { type CollType <: ParMap[K, V] - + property("gets iterated keys") = forAll(collectionPairs) { case (t, coll) => val containsT = for ((k, v) <- t) yield (coll.get(k) == Some(v)) val containsSelf = coll.map { case (k, v) => coll.get(k) == Some(v) } ("Par contains elements of seq map" |: containsT.forall(_ == true)) && ("Par contains elements of itself" |: containsSelf.forall(_ == true)) - } - + } + } diff --git a/test/files/scalacheck/parallel-collections/ParallelRangeCheck.scala b/test/files/scalacheck/parallel-collections/ParallelRangeCheck.scala index 3c6a35d8f1..f490d9490a 100644 --- a/test/files/scalacheck/parallel-collections/ParallelRangeCheck.scala +++ b/test/files/scalacheck/parallel-collections/ParallelRangeCheck.scala @@ -17,18 +17,18 @@ import scala.collection.parallel.ops._ -object ParallelRangeCheck extends ParallelSeqCheck[Int]("ParallelRange[Int]") with ops.IntSeqOperators { +class ParallelRangeCheck(val tasksupport: TaskSupport) extends ParallelSeqCheck[Int]("ParallelRange[Int]") with ops.IntSeqOperators { // ForkJoinTasks.defaultForkJoinPool.setMaximumPoolSize(Runtime.getRuntime.availableProcessors * 2) // ForkJoinTasks.defaultForkJoinPool.setParallelism(Runtime.getRuntime.availableProcessors * 2) - + type CollType = collection.parallel.ParSeq[Int] - + def hasStrictOrder = true - + def isCheckingViews = false - + def ofSize(vals: Seq[Gen[Int]], sz: Int) = unsupported - + override def instances(vals: Seq[Gen[Int]]): Gen[Seq[Int]] = sized { start => sized { end => sized { step => @@ -36,22 +36,26 @@ object ParallelRangeCheck extends ParallelSeqCheck[Int]("ParallelRange[Int]") wi } } } - + def fromSeq(a: Seq[Int]) = a match { - case r: Range => ParRange(r.start, r.end, r.step, false) + case r: Range => + val pr = ParRange(r.start, r.end, r.step, false) + pr.tasksupport = tasksupport + pr case _ => val pa = new parallel.mutable.ParArray[Int](a.length) + pa.tasksupport = tasksupport for (i <- 0 until a.length) pa(i) = a(i) pa } - + override def traversable2Seq(t: Traversable[Int]): Seq[Int] = t match { case r: Range => r case _ => t.toSeq } - + def values = Seq(choose(-100, 100)) - + } diff --git a/test/files/scalacheck/parallel-collections/ParallelSeqCheck.scala b/test/files/scalacheck/parallel-collections/ParallelSeqCheck.scala index dd897412ae..3f8a8ad4f5 100644 --- a/test/files/scalacheck/parallel-collections/ParallelSeqCheck.scala +++ b/test/files/scalacheck/parallel-collections/ParallelSeqCheck.scala @@ -16,13 +16,13 @@ import scala.collection.parallel._ abstract class ParallelSeqCheck[T](collName: String) extends ParallelIterableCheck[T](collName) with SeqOperators[T] { - + type CollType <: collection.parallel.ParSeq[T] - + def ofSize(vals: Seq[Gen[T]], sz: Int): Seq[T] def fromSeq(s: Seq[T]): CollType - + override def instances(vals: Seq[Gen[T]]): Gen[Seq[T]] = oneOf( sized( sz => @@ -31,17 +31,17 @@ abstract class ParallelSeqCheck[T](collName: String) extends ParallelIterableChe for (sz <- choose(1000, 2000)) yield ofSize(vals, sz) ) - + def fromTraversable(t: Traversable[T]) = fromSeq(traversable2Seq(t)) def traversable2Seq(t: Traversable[T]): Seq[T] = { if (t.isInstanceOf[Iterable[_]]) t.asInstanceOf[Iterable[T]].iterator.toList else t.toList } - + override def collectionPairs: Gen[(Seq[T], CollType)] = for (inst <- instances(values)) yield (inst, fromSeq(inst)) - + override def collectionPairsWithLengths: Gen[(Seq[T], CollType, Int)] = for (inst <- instances(values); s <- choose(0, inst.size)) yield (inst, fromSeq(inst), s); - + def collectionPairsWithModifiedWithLengths: Gen[(Seq[T], CollType, ParSeq[T], Int)] = for (inst <- instances(values); s <- choose(0, inst.size); updateStart <- choose(0, inst.size); howMany <- choose(0, inst.size)) yield { @@ -49,31 +49,31 @@ abstract class ParallelSeqCheck[T](collName: String) extends ParallelIterableChe val parcollmodif = fromSeq(modifySlightly(inst, updateStart, howMany)) (inst, parcoll, parcollmodif, s) } - + def collectionPairsWithModified: Gen[(Seq[T], CollType, ParSeq[T])] = for (inst <- instances(values); updateStart <- choose(0, inst.size); howMany <- choose(0, inst.size)) yield { val parcoll = fromSeq(inst) val parcollmodif = fromSeq(modifySlightly(inst, updateStart, howMany)) (inst, parcoll, parcollmodif) } - + def collectionPairsWithSliced: Gen[(Seq[T], CollType, ParSeq[T])] = for (inst <- instances(values); sliceStart <- choose(0, inst.size); howMany <- choose(0, inst.size)) yield { val parcoll = fromSeq(inst) val parcollsliced = fromSeq(inst.slice(sliceStart, sliceStart + howMany)) (inst, parcoll, parcollsliced) } - + def collectionTripletsWith2Indices: Gen[(Seq[T], CollType, Seq[T], Int, Int)] = for (inst <- instances(values); f <- choose(0, inst.size); s <- choose(0, inst.size - f); third <- instances(values); sliceStart <- choose(0, inst.size); howMany <- choose(0, inst.size)) yield { (inst, fromSeq(inst), inst.slice(sliceStart, sliceStart + howMany), f, s) } - + private def modifySlightly(coll: Seq[T], updateStart: Int, howMany: Int) = { coll.patch(updateStart, coll, howMany) } - + property("segmentLengths must be equal") = forAll(collectionPairsWithLengths) { case (s, coll, len) => (for ((pred, ind) <- segmentLengthPredicates.zipWithIndex) yield { val slen = s.segmentLength(pred, if (len < 0) 0 else len) @@ -87,13 +87,13 @@ abstract class ParallelSeqCheck[T](collName: String) extends ParallelIterableChe ("operator " + ind) |: slen == clen }).reduceLeft(_ && _) } - + property("prefixLengths must be equal") = forAll(collectionPairs) { case (s, coll) => (for ((pred, ind) <- segmentLengthPredicates.zipWithIndex) yield { ("operator " + ind) |: s.prefixLength(pred) == coll.prefixLength(pred) }).reduceLeft(_ && _) } - + property("indexWheres must be equal") = forAll(collectionPairsWithLengths) { case (s, coll, len) => (for ((pred, ind) <- indexWherePredicates.zipWithIndex) yield { val sind = s.indexWhere(pred, len) @@ -108,7 +108,7 @@ abstract class ParallelSeqCheck[T](collName: String) extends ParallelIterableChe ("operator " + ind) |: sind == cind }).reduceLeft(_ && _) } - + property("lastIndexWheres must be equal") = forAll(collectionPairsWithLengths) { case (s, coll, len) => (for ((pred, ind) <- lastIndexWherePredicates.zipWithIndex) yield { val end = if (len >= s.size) s.size - 1 else len @@ -117,7 +117,7 @@ abstract class ParallelSeqCheck[T](collName: String) extends ParallelIterableChe ("operator " + ind) |: sind == cind }).reduceLeft(_ && _) } - + property("reverses must be equal") = forAll(collectionPairs) { case (s, coll) => (s.length == 0 && s.getClass == classOf[collection.immutable.Range]) || { @@ -132,13 +132,13 @@ abstract class ParallelSeqCheck[T](collName: String) extends ParallelIterableChe sr == cr } } - + property("reverseMaps must be equal") = forAll(collectionPairs) { case (s, coll) => (for ((f, ind) <- reverseMapFunctions.zipWithIndex) yield { ("operator " + ind) |: s.reverseMap(f) == coll.reverseMap(f) }).reduceLeft(_ && _) } - + property("sameElements must be equal") = forAll(collectionPairsWithModifiedWithLengths) { case (s, coll, collmodif, len) => val pos = if (len < 0) 0 else len @@ -170,7 +170,7 @@ abstract class ParallelSeqCheck[T](collName: String) extends ParallelIterableChe ("collection " + ind) |: sres == pres }).reduceLeft(_ && _) } - + property("startsWiths must be equal") = forAll(collectionPairsWithModifiedWithLengths) { case (s, coll, collmodif, len) => val pos = if (len < 0) 0 else len @@ -194,7 +194,7 @@ abstract class ParallelSeqCheck[T](collName: String) extends ParallelIterableChe ("seq " + sq) |: ss == cs }).reduceLeft(_ && _) } - + property("endsWiths must be equal") = forAll(collectionPairsWithModified) { case (s, coll, collmodif) => ("ends with self" |: s.endsWith(s) == coll.endsWith(s)) && @@ -213,18 +213,18 @@ abstract class ParallelSeqCheck[T](collName: String) extends ParallelIterableChe ("seq " + sq) |: sew == cew }).reduceLeft(_ && _) } - + property("unions must be equal") = forAll(collectionPairsWithModified) { case (s, coll, collmodif) => ("modified" |: s.union(collmodif.seq) == coll.union(collmodif)) && ("empty" |: s.union(Nil) == coll.union(fromSeq(Nil))) } - + // This is failing with my views patch: array index out of bounds in the array iterator. // Couldn't see why this and only this was impacted, could use a second pair of eyes. - // + // // This was failing because some corner cases weren't added to the patch method in ParSeqLike. // Curiously, this wasn't detected before. - // + // if (!isCheckingViews) property("patches must be equal") = forAll(collectionTripletsWith2Indices) { case (s, coll, pat, from, repl) => ("with seq" |: s.patch(from, pat, repl) == coll.patch(from, pat, repl)) && @@ -232,7 +232,7 @@ abstract class ParallelSeqCheck[T](collName: String) extends ParallelIterableChe ("with empty" |: s.patch(from, Nil, repl) == coll.patch(from, fromSeq(Nil), repl)) && ("with one" |: (s.length == 0 || s.patch(from, List(s(0)), 1) == coll.patch(from, fromSeq(List(coll(0))), 1))) } - + if (!isCheckingViews) property("updates must be equal") = forAll(collectionPairsWithLengths) { case (s, coll, len) => val pos = if (len >= s.length) s.length - 1 else len if (s.length > 0) { @@ -247,15 +247,15 @@ abstract class ParallelSeqCheck[T](collName: String) extends ParallelIterableChe "from first" |: (supd == cupd) } else "trivially" |: true } - + property("prepends must be equal") = forAll(collectionPairs) { case (s, coll) => s.length == 0 || s(0) +: s == coll(0) +: coll } - + property("appends must be equal") = forAll(collectionPairs) { case (s, coll) => s.length == 0 || s :+ s(0) == coll :+ coll(0) } - + property("padTos must be equal") = forAll(collectionPairsWithLengths) { case (s, coll, len) => val someValue = sampleValue val sdoub = s.padTo(len * 2, someValue) @@ -269,14 +269,14 @@ abstract class ParallelSeqCheck[T](collName: String) extends ParallelIterableChe ("smaller" |: s.padTo(len / 2, someValue) == coll.padTo(len / 2, someValue)) && ("bigger" |: sdoub == cdoub) } - + property("corresponds must be equal") = forAll(collectionPairsWithModified) { case (s, coll, modified) => val modifcut = modified.toSeq.slice(0, modified.length) ("self" |: s.corresponds(s)(_ == _) == coll.corresponds(coll)(_ == _)) && ("modified" |: s.corresponds(modified.seq)(_ == _) == coll.corresponds(modified)(_ == _)) && ("modified2" |: s.corresponds(modifcut)(_ == _) == coll.corresponds(modifcut)(_ == _)) } - + } diff --git a/test/files/scalacheck/parallel-collections/ParallelSetCheck.scala b/test/files/scalacheck/parallel-collections/ParallelSetCheck.scala index 4211abbd16..56f7832fed 100644 --- a/test/files/scalacheck/parallel-collections/ParallelSetCheck.scala +++ b/test/files/scalacheck/parallel-collections/ParallelSetCheck.scala @@ -16,15 +16,15 @@ import scala.collection.parallel._ abstract class ParallelSetCheck[T](collname: String) extends ParallelIterableCheck[T](collname) { type CollType <: ParSet[T] - + property("gets iterated keys") = forAll(collectionPairs) { case (t, coll) => val containsT = for (elem <- t) yield (coll.contains(elem)) val containsSelf = for (elem <- coll) yield (coll.contains(elem)) ("Par contains elements of seq map" |: containsT.forall(_ == true)) && ("Par contains elements of itself" |: containsSelf.forall(_ == true)) - } - + } + } diff --git a/test/files/scalacheck/parallel-collections/ParallelVectorCheck.scala b/test/files/scalacheck/parallel-collections/ParallelVectorCheck.scala index e4bb588fa7..bbebd51919 100644 --- a/test/files/scalacheck/parallel-collections/ParallelVectorCheck.scala +++ b/test/files/scalacheck/parallel-collections/ParallelVectorCheck.scala @@ -17,37 +17,43 @@ import scala.collection.parallel.ops._ import immutable.Vector import immutable.VectorBuilder +import scala.collection.parallel.TaskSupport + 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 tasksupport: TaskSupport + 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 + val pc = ParVector.newCombiner[T] + for (elem <- a.toList) pc += elem + val pv = pc.result + pv.tasksupport = tasksupport + pv } - + } -object IntParallelVectorCheck extends ParallelVectorCheck[Int]("Int") with IntSeqOperators with IntValues { +class IntParallelVectorCheck(val tasksupport: TaskSupport) 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 => diff --git a/test/files/scalacheck/parallel-collections/pc.scala b/test/files/scalacheck/parallel-collections/pc.scala index 0a91977da0..a3c1df4054 100644 --- a/test/files/scalacheck/parallel-collections/pc.scala +++ b/test/files/scalacheck/parallel-collections/pc.scala @@ -1,42 +1,58 @@ - - - +/* + * scalac: -deprecation + * scalacheck: -workers 1 -minSize 0 -maxSize 4000 -minSuccessfulTests 5 + */ import org.scalacheck._ - import scala.collection.parallel._ +// package here to be able access the package-private implementation and shutdown the pool +package scala { -class ParCollProperties extends Properties("Parallel collections") { - /* Collections */ - - // parallel arrays - include(mutable.IntParallelArrayCheck) - - // parallel ranges - include(immutable.ParallelRangeCheck) + class ParCollProperties extends Properties("Parallel collections") { - // parallel immutable hash maps (tries) - include(immutable.IntIntParallelHashMapCheck) + def includeAllTestsWith(support: TaskSupport) { + // parallel arrays with default task support + include(new mutable.IntParallelArrayCheck(support)) + + // parallel ranges + include(new immutable.ParallelRangeCheck(support)) + + // parallel immutable hash maps (tries) + include(new immutable.IntIntParallelHashMapCheck(support)) + + // parallel immutable hash sets (tries) + include(new immutable.IntParallelHashSetCheck(support)) + + // parallel mutable hash maps (tables) + include(new mutable.IntIntParallelHashMapCheck(support)) + + // parallel ctrie + include(new mutable.IntIntParallelConcurrentTrieMapCheck(support)) + + // parallel mutable hash sets (tables) + include(new mutable.IntParallelHashSetCheck(support)) + + // parallel vectors + include(new immutable.IntParallelVectorCheck(support)) + } - // parallel immutable hash sets (tries) - include(immutable.IntParallelHashSetCheck) + includeAllTestsWith(defaultTaskSupport) - // parallel mutable hash maps (tables) - include(mutable.IntIntParallelHashMapCheck) - - // parallel ctrie - include(mutable.IntIntParallelConcurrentTrieMapCheck) - - // parallel mutable hash sets (tables) - include(mutable.IntParallelHashSetCheck) + val ec = scala.concurrent.ExecutionContext.fromExecutorService(java.util.concurrent.Executors.newFixedThreadPool(5)) + val ectasks = new collection.parallel.ExecutionContextTaskSupport(ec) + includeAllTestsWith(ectasks) + + // no post test hooks in scalacheck, so cannot do: + // ec.shutdown() - // parallel vectors - include(immutable.IntParallelVectorCheck) + } + } -object Test { +object Test extends scala.ParCollProperties { + /* def main(args: Array[String]) { val pc = new ParCollProperties org.scalacheck.Test.checkProperties( @@ -51,4 +67,5 @@ object Test { pc ) } + */ } |