Skip to content

Commit c193570

Browse files
committed
Restore tests transforming maps to iterables
1 parent bc33f14 commit c193570

File tree

5 files changed

+88
-97
lines changed

5 files changed

+88
-97
lines changed

core/src/main/scala/scala/collection/parallel/mutable/ParHashMap.scala

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ extends scala.collection.parallel.BucketCombiner[(K, V), ParHashMap[K, V], Defau
177177
buckets(pos) = new UnrolledBuffer[DefaultEntry[K, V]]()
178178
}
179179
// add to bucket
180-
buckets(pos) += new DefaultEntry[K, V](elem._1, elem._2)
180+
buckets(pos) += new DefaultEntry(elem._1, elem._2)
181181
this
182182
}
183183

@@ -202,9 +202,7 @@ extends scala.collection.parallel.BucketCombiner[(K, V), ParHashMap[K, V], Defau
202202
var i = 0
203203
while (i < ParHashMapCombiner.numblocks) {
204204
if (buckets(i) ne null) {
205-
for (elem <- buckets(i)) {
206-
table.insertEntry(elem)
207-
}
205+
for (elem <- buckets(i)) table.insertEntry(elem)
208206
}
209207
i += 1
210208
}

scalacheck/src/test/scala/ParallelIterableCheck.scala

Lines changed: 78 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,10 @@ abstract class ParallelIterableCheck[T](collName: String) extends Properties(col
7474
val am1: Map[Any, Any] = m1.asInstanceOf[Map[Any, Any]]
7575
val am2: ParMap[Any, Any] = m2.asInstanceOf[ParMap[Any, Any]]
7676
am1.forall { case (k, v) => am2.get(k).contains(v) } && am2.forall { case (k, v) => am1.get(k).contains(v) }
77-
case (i1: Set[T], i2: ParSet[T]) =>
78-
i1.forall(i2) && i2.forall(i1)
79-
case _ => t1.iterator.sameElements(t2) && t2.sameElements(t1)
77+
case _ =>
78+
val s1 = t1.toSet
79+
val s2 = t2.toSet
80+
s1.forall(s2) && s2.forall(s1)
8081
}
8182

8283
def printDebugInfo[A, CC[X] <: ParIterable[X], C <: ParIterable[A], S <: Iterable[A] with IterableOps[A, Iterable, S]](coll: ParIterableLike[A, CC, C, S]): Unit = {
@@ -161,6 +162,48 @@ abstract class ParallelIterableCheck[T](collName: String) extends Properties(col
161162
results.reduceLeft(_ && _)
162163
}
163164

165+
property("mappings must be equal") = forAllNoShrink(collectionPairs) { case (t, coll) =>
166+
val results = for ((f, ind) <- mapFunctions.zipWithIndex) yield {
167+
val ms = t.map(f)
168+
val mp = coll.map(f)
169+
val invs = checkDataStructureInvariants(ms, mp)
170+
if (!areEqual(ms, mp) || !invs) {
171+
println(t)
172+
println(coll)
173+
println("mapped to: ")
174+
println(ms)
175+
println(mp)
176+
println("sizes: ")
177+
println(ms.size)
178+
println(mp.size)
179+
println("valid: " + invs)
180+
}
181+
("op index: " + ind) |: (areEqual(ms, mp) && invs)
182+
}
183+
results.reduceLeft(_ && _)
184+
}
185+
186+
property("collects must be equal") = forAllNoShrink(collectionPairs) { case (t, coll) =>
187+
val results = for ((f, ind) <- partialMapFunctions.zipWithIndex) yield {
188+
val ps = t.collect(f)
189+
val pp = coll.collect(f)
190+
if (!areEqual(ps, pp)) {
191+
println(t)
192+
println(coll)
193+
println("collected to: ")
194+
println(ps)
195+
println(pp)
196+
}
197+
("op index: " + ind) |: areEqual(ps, pp)
198+
}
199+
results.reduceLeft(_ && _)
200+
}
201+
202+
property("flatMaps must be equal") = forAllNoShrink(collectionPairs) { case (t, coll) =>
203+
(for ((f, ind) <- flatMapFunctions.zipWithIndex)
204+
yield ("op index: " + ind) |: areEqual(t.flatMap(f), coll.flatMap(f))).reduceLeft(_ && _)
205+
}
206+
164207
property("filters must be equal") = forAllNoShrink(collectionPairs) { case (t, coll) =>
165208
(for ((p, ind) <- filterPredicates.zipWithIndex) yield {
166209
val tf = t.filter(p)
@@ -311,6 +354,38 @@ abstract class ParallelIterableCheck[T](collName: String) extends Properties(col
311354
}).reduceLeft(_ && _)
312355
}
313356

357+
property("++s must be equal") = forAll(collectionTriplets) { case (t, coll, colltoadd) =>
358+
try {
359+
val toadd = colltoadd
360+
val tr = t ++ toadd.iterator
361+
val cr = coll ++ toadd.iterator
362+
if (!areEqual(tr, cr)) {
363+
println("from: " + t)
364+
println("and: " + coll.iterator.toList)
365+
println("adding: " + toadd)
366+
println(tr.toList)
367+
println(cr.iterator.toList)
368+
}
369+
("adding " |: areEqual(tr, cr)) &&
370+
(for ((trav, ind) <- addAllIterables.zipWithIndex) yield {
371+
val tadded = t ++ trav
372+
val cadded = coll ++ trav
373+
if (!areEqual(tadded, cadded)) {
374+
println("----------------------")
375+
println("from: " + t)
376+
println("and: " + coll)
377+
println("adding: " + trav)
378+
println(tadded)
379+
println(cadded)
380+
}
381+
("traversable " + ind) |: areEqual(tadded, cadded)
382+
}).reduceLeft(_ && _)
383+
} catch {
384+
case e: java.lang.Exception =>
385+
throw e
386+
}
387+
}
388+
314389
if (hasStrictOrder) property("copies to array must be equal") = forAllNoShrink(collectionPairs) { case (t, coll) =>
315390
val tarr = newArray(t.size)
316391
val collarr = newArray(coll.size)
@@ -362,84 +437,3 @@ abstract class ParallelIterableCheck[T](collName: String) extends Properties(col
362437
}
363438

364439
}
365-
366-
/**
367-
* Properties for collections whose elements are single values (as opposed to pairs of values)
368-
*/
369-
trait SimpleValuesCheck[T] { this: ParallelIterableCheck[T] =>
370-
371-
property("mappings must be equal") = forAllNoShrink(collectionPairs) { case (t, coll) =>
372-
val results = for ((f, ind) <- mapFunctions.zipWithIndex) yield {
373-
val ms = t.map(f)
374-
val mp = coll.map(f)
375-
val invs = checkDataStructureInvariants(ms, mp)
376-
if (!areEqual(ms, mp) || !invs) {
377-
println(t)
378-
println(coll)
379-
println("mapped to: ")
380-
println(ms)
381-
println(mp)
382-
println("sizes: ")
383-
println(ms.size)
384-
println(mp.size)
385-
println("valid: " + invs)
386-
}
387-
("op index: " + ind) |: (areEqual(ms, mp) && invs)
388-
}
389-
results.reduceLeft(_ && _)
390-
}
391-
392-
property("collects must be equal") = forAllNoShrink(collectionPairs) { case (t, coll) =>
393-
val results = for ((f, ind) <- partialMapFunctions.zipWithIndex) yield {
394-
val ps = t.collect(f)
395-
val pp = coll.collect(f)
396-
if (!areEqual(ps, pp)) {
397-
println(t)
398-
println(coll)
399-
println("collected to: ")
400-
println(ps)
401-
println(pp)
402-
}
403-
("op index: " + ind) |: areEqual(ps, pp)
404-
}
405-
results.reduceLeft(_ && _)
406-
}
407-
408-
property("flatMaps must be equal") = forAllNoShrink(collectionPairs) { case (t, coll) =>
409-
(for ((f, ind) <- flatMapFunctions.zipWithIndex)
410-
yield ("op index: " + ind) |: areEqual(t.flatMap(f), coll.flatMap(f))).reduceLeft(_ && _)
411-
}
412-
413-
property("++s must be equal") = forAll(collectionTriplets) { case (t, coll, colltoadd) =>
414-
try {
415-
val toadd = colltoadd
416-
val tr = t ++ toadd.iterator
417-
val cr = coll ++ toadd.iterator
418-
if (!areEqual(tr, cr)) {
419-
println("from: " + t)
420-
println("and: " + coll.iterator.toList)
421-
println("adding: " + toadd)
422-
println(tr.toList)
423-
println(cr.iterator.toList)
424-
}
425-
("adding " |: areEqual(tr, cr)) &&
426-
(for ((trav, ind) <- addAllIterables.zipWithIndex) yield {
427-
val tadded = t ++ trav
428-
val cadded = coll ++ trav
429-
if (!areEqual(tadded, cadded)) {
430-
println("----------------------")
431-
println("from: " + t)
432-
println("and: " + coll)
433-
println("adding: " + trav)
434-
println(tadded)
435-
println(cadded)
436-
}
437-
("traversable " + ind) |: areEqual(tadded, cadded)
438-
}).reduceLeft(_ && _)
439-
} catch {
440-
case e: java.lang.Exception =>
441-
throw e
442-
}
443-
}
444-
445-
}

scalacheck/src/test/scala/ParallelMapCheck1.scala

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ abstract class ParallelMapCheck[K, V](collname: String) extends ParallelIterable
3030
(iterable.to(Map), parmap, seq)
3131
}
3232

33-
// The following tests have been copied from `SimpleValuesCheck`, and adapted to test
33+
// The following tests have been copied from `ParIterableCheck`, and adapted to test
3434
// overloads of the methods that return Map and ParMap collections
35-
property("mappings must be equal") = forAll/*NoShrink*/(collectionPairs) { case (t, coll) =>
36-
val results = for ((f, ind) <- mapFunctions.zipWithIndex) yield {
35+
property("mappings returning maps must be equal") = forAll/*NoShrink*/(collectionPairs) { case (t, coll) =>
36+
val results = for ((f, ind) <- mapFunctions.zipWithIndex.take(5)) yield {
3737
val ms: Map[K, V] = t.map(f)
3838
val mp: ParMap[K, V] = coll.map(f)
3939
val invs = checkDataStructureInvariants(ms, mp)
@@ -53,7 +53,7 @@ abstract class ParallelMapCheck[K, V](collname: String) extends ParallelIterable
5353
results.reduceLeft(_ && _)
5454
}
5555

56-
property("collects must be equal") = forAllNoShrink(collectionPairs) { case (t, coll) =>
56+
property("collects returning maps must be equal") = forAllNoShrink(collectionPairs) { case (t, coll) =>
5757
val results = for ((f, ind) <- partialMapFunctions.zipWithIndex) yield {
5858
val ps: Map[K, V] = t.collect(f)
5959
val pp: ParMap[K, V] = coll.collect(f)
@@ -69,12 +69,12 @@ abstract class ParallelMapCheck[K, V](collname: String) extends ParallelIterable
6969
results.reduceLeft(_ && _)
7070
}
7171

72-
property("flatMaps must be equal") = forAllNoShrink(collectionPairs) { case (t, coll) =>
72+
property("flatMaps returning maps must be equal") = forAllNoShrink(collectionPairs) { case (t, coll) =>
7373
(for ((f, ind) <- flatMapFunctions.zipWithIndex)
7474
yield ("op index: " + ind) |: areEqual(t.flatMap(f), coll.flatMap(f))).reduceLeft(_ && _)
7575
}
7676

77-
property("++s must be equal") = forAll(collectionTriplets) { case (t, coll, colltoadd) =>
77+
property("++s returning maps must be equal") = forAll(collectionTriplets) { case (t, coll, colltoadd) =>
7878
try {
7979
val toadd = colltoadd
8080
val tr: Map[K, V] = t ++ toadd.iterator

scalacheck/src/test/scala/ParallelSeqCheck.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import scala.collection._
1010
import scala.collection.parallel._
1111

1212
abstract class ParallelSeqCheck[T](collName: String) extends ParallelIterableCheck[T](collName)
13-
with SeqOperators[T] with SimpleValuesCheck[T] {
13+
with SeqOperators[T] {
1414

1515
type CollType <: collection.parallel.ParSeq[T]
1616

scalacheck/src/test/scala/ParallelSetCheck.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ import org.scalacheck.Properties
99
import scala.collection._
1010
import scala.collection.parallel._
1111

12-
abstract class ParallelSetCheck[T](collname: String) extends ParallelIterableCheck[T](collname)
13-
with SimpleValuesCheck[T] {
12+
abstract class ParallelSetCheck[T](collname: String) extends ParallelIterableCheck[T](collname) {
1413

1514
type CollType <: ParSet[T]
1615

0 commit comments

Comments
 (0)