Skip to content

Commit 7dd0418

Browse files
committed
Uncomment most ParIterableLikeCheck tests
Collection comparisons have been replaced with calls to Iterator#sameElements. Fix `seq` implementation of `ParArray`.
1 parent 10013dd commit 7dd0418

File tree

4 files changed

+102
-102
lines changed

4 files changed

+102
-102
lines changed

core/src/main/scala/scala/collection/parallel/ParIterableLike.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -793,7 +793,7 @@ self =>
793793
}
794794

795795
// FIXME Push down to `ParSeq`?
796-
def sameElements[U >: T](that: ParIterable[U]) = seq.iterator.sameElements(that)
796+
def sameElements[U >: T](that: IterableOnce[U]) = seq.iterator.sameElements(that)
797797

798798
def zip[U >: T, S](that: ParIterable[S]): CC[(U, S)] = {
799799
that match {

core/src/main/scala/scala/collection/parallel/ParSeqLike.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ self =>
189189
}
190190
}
191191

192-
override def sameElements[U >: T](that: ParIterable[U]): Boolean = {
192+
override def sameElements[U >: T](that: IterableOnce[U]): Boolean = {
193193
that match {
194194
case pthat: ParSeq[U] =>
195195
val ctx = new DefaultSignalling with VolatileAbort

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ self =>
7979

8080
def length = sz
8181

82-
def seq = arrayseq
82+
def seq = (if (length == arrayseq.length) arrayseq else arrayseq.take(length)): ArraySeq[T]
8383

8484
protected[parallel] def splitter: ParArrayIterator = {
8585
val pit = new ParArrayIterator

scalacheck/src/test/scala/ParallelIterableCheck.scala

Lines changed: 99 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -202,43 +202,43 @@ abstract class ParallelIterableCheck[T](collName: String) extends Properties(col
202202
// yield ("op index: " + ind) |: areEqual(t.flatMap(f), coll.flatMap(f))).reduceLeft(_ && _)
203203
// }
204204

205-
// property("filters must be equal") = forAllNoShrink(collectionPairs) { case (t, coll) =>
206-
// (for ((p, ind) <- filterPredicates.zipWithIndex) yield {
207-
// val tf = t.filter(p)
208-
// val cf = coll.filter(p)
209-
// val invs = checkDataStructureInvariants(tf, cf)
210-
// if (tf != cf || cf != tf || !invs) {
211-
// printDebugInfo(coll)
212-
// println("Operator: " + ind)
213-
// println("sz: " + t.size)
214-
// println(t)
215-
// println
216-
// println("sz: " + coll.size)
217-
// println(coll)
218-
// println
219-
// println("filtered to:")
220-
// println
221-
// println(cf)
222-
// println
223-
// println(tf)
224-
// println
225-
// println("tf == cf - " + (tf == cf))
226-
// println("cf == tf - " + (cf == tf))
227-
// printDataStructureDebugInfo(cf)
228-
// println("valid: " + invs)
229-
// }
230-
// ("op index: " + ind) |: tf == cf && cf == tf && invs
231-
// }).reduceLeft(_ && _)
232-
// }
205+
property("filters must be equal") = forAllNoShrink(collectionPairs) { case (t, coll) =>
206+
(for ((p, ind) <- filterPredicates.zipWithIndex) yield {
207+
val tf = t.filter(p)
208+
val cf = coll.filter(p)
209+
val invs = checkDataStructureInvariants(tf, cf)
210+
if (!tf.iterator.sameElements(cf) || !cf.sameElements(tf) || !invs) {
211+
printDebugInfo(coll)
212+
println("Operator: " + ind)
213+
println("sz: " + t.size)
214+
println(t)
215+
println
216+
println("sz: " + coll.size)
217+
println(coll)
218+
println
219+
println("filtered to:")
220+
println
221+
println(cf)
222+
println
223+
println(tf)
224+
println
225+
println("tf sameElements cf - " + (tf.iterator.sameElements(cf)))
226+
println("cf sameElements tf - " + (cf.sameElements(tf)))
227+
printDataStructureDebugInfo(cf)
228+
println("valid: " + invs)
229+
}
230+
("op index: " + ind) |: (tf.iterator.sameElements(cf) && cf.sameElements(tf) && invs)
231+
}).reduceLeft(_ && _)
232+
}
233233

234-
// property("filterNots must be equal") = forAllNoShrink(collectionPairs) { case (t, coll) =>
235-
// (for ((p, ind) <- filterNotPredicates.zipWithIndex) yield {
236-
// val tf = t.filterNot(p)
237-
// val cf = coll.filterNot(p)
238-
// if (tf != cf || cf != tf) printComparison(t, coll, tf, cf, ind)
239-
// ("op index: " + ind) |: tf == cf && cf == tf
240-
// }).reduceLeft(_ && _)
241-
// }
234+
property("filterNots must be equal") = forAllNoShrink(collectionPairs) { case (t, coll) =>
235+
(for ((p, ind) <- filterNotPredicates.zipWithIndex) yield {
236+
val tf = t.filterNot(p)
237+
val cf = coll.filterNot(p)
238+
if (!tf.iterator.sameElements(cf) || !cf.sameElements(tf)) printComparison(t, coll, tf, cf, ind)
239+
("op index: " + ind) |: tf.iterator.sameElements(cf) && cf.sameElements(tf)
240+
}).reduceLeft(_ && _)
241+
}
242242

243243
if (!isCheckingViews) property("partitions must be equal") = forAllNoShrink(collectionPairs) { case (t, coll) =>
244244
(for ((p, ind) <- partitionPredicates.zipWithIndex) yield {
@@ -254,37 +254,37 @@ abstract class ParallelIterableCheck[T](collName: String) extends Properties(col
254254
}).reduceLeft(_ && _)
255255
}
256256

257-
// if (hasStrictOrder) property("takes must be equal") = forAllNoShrink(collectionPairsWithLengths) { case (t, coll, n) =>
258-
// ("take " + n + " elements") |: t.take(n) == coll.take(n)
259-
// }
257+
if (hasStrictOrder) property("takes must be equal") = forAllNoShrink(collectionPairsWithLengths) { case (t, coll, n) =>
258+
("take " + n + " elements") |: t.take(n).iterator.sameElements(coll.take(n))
259+
}
260260

261-
// if (hasStrictOrder) property("drops must be equal") = forAllNoShrink(collectionPairsWithLengths) { case (t, coll, n) =>
262-
// ("drop " + n + " elements") |: t.drop(n) == coll.drop(n)
263-
// }
261+
if (hasStrictOrder) property("drops must be equal") = forAllNoShrink(collectionPairsWithLengths) { case (t, coll, n) =>
262+
("drop " + n + " elements") |: t.drop(n).iterator.sameElements(coll.drop(n))
263+
}
264264

265-
// if (hasStrictOrder) property("slices must be equal") = forAllNoShrink(collectionPairsWith2Indices)
266-
// { case (t, coll, fr, slicelength) =>
267-
// val from = if (fr < 0) 0 else fr
268-
// val until = if (from + slicelength > t.size) t.size else from + slicelength
269-
// val tsl = t.slice(from, until)
270-
// val collsl = coll.slice(from, until)
271-
// if (tsl != collsl) {
272-
// println("---------------------- " + from + ", " + until)
273-
// println("from: " + t)
274-
// println("and: " + coll)
275-
// println(tsl)
276-
// println(collsl)
277-
// println("as list: " + collsl.toList)
278-
// println(collsl.iterator.hasNext)
279-
// println(collsl.iterator.next)
280-
// println(collsl.iterator.hasNext)
281-
// println(collsl.iterator.next)
282-
// println(collsl.iterator.hasNext)
283-
// println(collsl.iterator.next)
284-
// println(collsl.iterator.hasNext)
285-
// }
286-
// ("slice from " + from + " until " + until) |: tsl == collsl
287-
// }
265+
if (hasStrictOrder) property("slices must be equal") = forAllNoShrink(collectionPairsWith2Indices)
266+
{ case (t, coll, fr, slicelength) =>
267+
val from = if (fr < 0) 0 else fr
268+
val until = if (from + slicelength > t.size) t.size else from + slicelength
269+
val tsl = t.slice(from, until)
270+
val collsl = coll.slice(from, until)
271+
if (!tsl.iterator.sameElements(collsl)) {
272+
println("---------------------- " + from + ", " + until)
273+
println("from: " + t)
274+
println("and: " + coll)
275+
println(tsl)
276+
println(collsl)
277+
println("as list: " + collsl.toList)
278+
println(collsl.iterator.hasNext)
279+
println(collsl.iterator.next)
280+
println(collsl.iterator.hasNext)
281+
println(collsl.iterator.next)
282+
println(collsl.iterator.hasNext)
283+
println(collsl.iterator.next)
284+
println(collsl.iterator.hasNext)
285+
}
286+
("slice from " + from + " until " + until) |: tsl.iterator.sameElements(collsl)
287+
}
288288

289289
if (hasStrictOrder) property("splits must be equal") = forAllNoShrink(collectionPairsWithLengths) { case (t, coll, n) =>
290290
val tspl @ (tspl1, tspl2) = t.splitAt(n)
@@ -299,20 +299,20 @@ abstract class ParallelIterableCheck[T](collName: String) extends Properties(col
299299
("splitAt " + n) |: (tspl1.iterator.sameElements(cspl1) && tspl2.iterator.sameElements(cspl2))
300300
}
301301

302-
// if (hasStrictOrder) property("takeWhiles must be equal") = forAllNoShrink(collectionPairs) { case (t, coll) =>
303-
// (for ((pred, ind) <- takeWhilePredicates.zipWithIndex) yield {
304-
// val tt = t.takeWhile(pred)
305-
// val ct = coll.takeWhile(pred)
306-
// if (tt != ct) {
307-
// println("from: " + t)
308-
// println("and: " + coll)
309-
// println("taking while...")
310-
// println(tt)
311-
// println(ct)
312-
// }
313-
// ("operator " + ind) |: tt == ct
314-
// }).reduceLeft(_ && _)
315-
// }
302+
if (hasStrictOrder) property("takeWhiles must be equal") = forAllNoShrink(collectionPairs) { case (t, coll) =>
303+
(for ((pred, ind) <- takeWhilePredicates.zipWithIndex) yield {
304+
val tt = t.takeWhile(pred)
305+
val ct = coll.takeWhile(pred)
306+
if (!tt.iterator.sameElements(ct)) {
307+
println("from: " + t)
308+
println("and: " + coll)
309+
println("taking while...")
310+
println(tt)
311+
println(ct)
312+
}
313+
("operator " + ind) |: tt.iterator.sameElements(ct)
314+
}).reduceLeft(_ && _)
315+
}
316316

317317
if (hasStrictOrder) property("spans must be equal") = forAllNoShrink(collectionPairs) { case (t, coll) =>
318318
(for ((pred, ind) <- spanPredicates.zipWithIndex) yield {
@@ -332,11 +332,11 @@ abstract class ParallelIterableCheck[T](collName: String) extends Properties(col
332332
}).reduceLeft(_ && _)
333333
}
334334

335-
// if (hasStrictOrder) property("dropWhiles must be equal") = forAllNoShrink(collectionPairs) { case (t, coll) =>
336-
// (for ((pred, ind) <- dropWhilePredicates.zipWithIndex) yield {
337-
// ("operator " + ind) |: t.dropWhile(pred) == coll.dropWhile(pred)
338-
// }).reduceLeft(_ && _)
339-
// }
335+
if (hasStrictOrder) property("dropWhiles must be equal") = forAllNoShrink(collectionPairs) { case (t, coll) =>
336+
(for ((pred, ind) <- dropWhilePredicates.zipWithIndex) yield {
337+
("operator " + ind) |: t.dropWhile(pred).iterator.sameElements(coll.dropWhile(pred))
338+
}).reduceLeft(_ && _)
339+
}
340340

341341
property("folds must be equal for assoc. operators") = forAllNoShrink(collectionPairs) { case (t, coll) =>
342342
(for (((first, op), ind) <- foldArguments.zipWithIndex) yield {
@@ -399,21 +399,21 @@ abstract class ParallelIterableCheck[T](collName: String) extends Properties(col
399399
tarr.toSeq == collarr.toSeq
400400
}
401401

402-
// if (hasStrictOrder) property("scans must be equal") = forAllNoShrink(collectionPairs) {
403-
// case (t, coll) =>
404-
// (for (((first, op), ind) <- foldArguments.zipWithIndex) yield {
405-
// val tscan = t.scanLeft(first)(op)
406-
// val cscan = coll.scan(first)(op)
407-
// if (tscan != cscan || cscan != tscan) {
408-
// println("from: " + t)
409-
// println("and: " + coll)
410-
// println("scans are: ")
411-
// println(tscan)
412-
// println(cscan)
413-
// }
414-
// ("operator " + ind) |: tscan == cscan && cscan == tscan
415-
// }).reduceLeft(_ && _)
416-
// }
402+
if (hasStrictOrder) property("scans must be equal") = forAllNoShrink(collectionPairs) {
403+
case (t, coll) =>
404+
(for (((first, op), ind) <- foldArguments.zipWithIndex) yield {
405+
val tscan = t.scanLeft(first)(op)
406+
val cscan = coll.scan(first)(op)
407+
if (!tscan.iterator.sameElements(cscan) || !cscan.sameElements(tscan)) {
408+
println("from: " + t)
409+
println("and: " + coll)
410+
println("scans are: ")
411+
println(tscan)
412+
println(cscan)
413+
}
414+
("operator " + ind) |: tscan.iterator.sameElements(cscan) && cscan.sameElements(tscan)
415+
}).reduceLeft(_ && _)
416+
}
417417

418418
// property("groupBy must be equal") = forAllNoShrink(collectionPairs) {
419419
// case (t, coll) =>

0 commit comments

Comments
 (0)