Skip to content

Commit ee4b9e4

Browse files
committed
Enable more ParSeq tests
1 parent 6c299f7 commit ee4b9e4

File tree

3 files changed

+98
-86
lines changed

3 files changed

+98
-86
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -698,11 +698,11 @@ self =>
698698
})
699699
}) else setTaskSupport((companion.newCombiner[U] += z).result(), tasksupport)
700700
}
701-
/*
702-
def scanLeft[S, That](z: S)(op: (S, T) => S)(implicit bf: CanBuildFrom[Repr, S, That]) = setTaskSupport(seq.scanLeft(z)(op)(bf2seq(bf)), tasksupport)
703701

704-
def scanRight[S, That](z: S)(op: (T, S) => S)(implicit bf: CanBuildFrom[Repr, S, That]) = setTaskSupport(seq.scanRight(z)(op)(bf2seq(bf)), tasksupport)
705-
*/
702+
def scanLeft[S](z: S)(op: (S, T) => S): Iterable[S] = seq.scanLeft(z)(op)
703+
704+
def scanRight[S](z: S)(op: (T, S) => S): Iterable[S] = seq.scanRight(z)(op)
705+
706706
/** Takes the longest prefix of elements that satisfy the predicate.
707707
*
708708
* $indexsignalling

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

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -177,16 +177,18 @@ self =>
177177
* @param offset the starting offset for the search
178178
* @return `true` if there is a sequence `that` starting at `offset` in this sequence, `false` otherwise
179179
*/
180-
def startsWith[S >: T](that: ParSeq[S], offset: Int): Boolean = {
181-
if (offset < 0 || offset >= length) offset == length && that.length == 0
182-
else if (that.length == 0) true
183-
else if (that.length > length - offset) false
184-
else {
185-
val ctx = new DefaultSignalling with VolatileAbort
186-
tasksupport.executeAndWaitResult(
187-
new SameElements[S](splitter.psplitWithSignalling(offset, that.length)(1) assign ctx, that.splitter)
188-
)
189-
}
180+
def startsWith[S >: T](that: IterableOnce[S], offset: Int = 0): Boolean = that match {
181+
case pt: ParSeq[S] =>
182+
if (offset < 0 || offset >= length) offset == length && pt.isEmpty
183+
else if (pt.isEmpty) true
184+
else if (pt.length > length - offset) false
185+
else {
186+
val ctx = new DefaultSignalling with VolatileAbort
187+
tasksupport.executeAndWaitResult(
188+
new SameElements[S](splitter.psplitWithSignalling(offset, pt.length)(1) assign ctx, pt.splitter)
189+
)
190+
}
191+
case _ => seq.startsWith(that, offset)
190192
}
191193

192194
override def sameElements[U >: T](that: IterableOnce[U]): Boolean = {
@@ -216,6 +218,16 @@ self =>
216218
}
217219
}
218220

221+
/** Tests whether this $coll ends with the given collection.
222+
*
223+
* $abortsignalling
224+
*
225+
* @tparam S the type of the elements of `that` sequence
226+
* @param that the sequence to test
227+
* @return `true` if this $coll has `that` as a suffix, `false` otherwise
228+
*/
229+
def endsWith[S >: T](that: Iterable[S]): Boolean = seq.endsWith(that)
230+
219231
def patch[U >: T](from: Int, patch: ParSeq[U], replaced: Int): CC[U] = {
220232
val realreplaced = replaced min (length - from)
221233
if ((size - realreplaced + patch.size) > MIN_FOR_COPY) {

scalacheck/src/test/scala/ParallelSeqCheck.scala

Lines changed: 72 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -131,80 +131,80 @@ abstract class ParallelSeqCheck[T](collName: String) extends ParallelIterableChe
131131
}).reduceLeft(_ && _)
132132
}
133133

134-
// property("sameElements must be equal") = forAllNoShrink(collectionPairsWithModifiedWithLengths) {
135-
// case (s, coll, collmodif, len) =>
136-
// val pos = if (len < 0) 0 else len
137-
// val scm = s.sameElements(collmodif)
138-
// val ccm = coll.sameElements(collmodif)
139-
// if (scm != ccm) {
140-
// println("Comparing: " + s)
141-
// println("and: " + coll)
142-
// println("with: " + collmodif)
143-
// println(scm)
144-
// println(ccm)
145-
// }
146-
// ("Nil" |: s.sameElements(Nil) == coll.sameElements(Nil)) &&
147-
// ("toList" |: s.sameElements(s.toList) == coll.sameElements(coll.toList)) &&
148-
// ("identity" |: s.sameElements(s.map(e => e)) == coll.sameElements(coll.map(e => e))) &&
149-
// ("vice-versa" |: s.sameElements(coll) == coll.sameElements(s)) &&
150-
// ("equal" |: s.sameElements(coll)) &&
151-
// ("modified" |: scm == ccm) &&
152-
// (for ((it, ind) <- sameElementsSeqs.zipWithIndex) yield {
153-
// val sres = s.sameElements(it)
154-
// val pres = coll.sameElements(it)
155-
// if (sres != pres) {
156-
// println("Comparing: " + s)
157-
// println("and: " + coll)
158-
// println("with: " + it)
159-
// println(sres)
160-
// println(pres)
161-
// }
162-
// ("collection " + ind) |: sres == pres
163-
// }).reduceLeft(_ && _)
164-
// }
134+
property("sameElements must be equal") = forAllNoShrink(collectionPairsWithModifiedWithLengths) {
135+
case (s, coll, collmodif, len) =>
136+
val pos = if (len < 0) 0 else len
137+
val scm = s.sameElements(collmodif)
138+
val ccm = coll.sameElements(collmodif)
139+
if (scm != ccm) {
140+
println("Comparing: " + s)
141+
println("and: " + coll)
142+
println("with: " + collmodif)
143+
println(scm)
144+
println(ccm)
145+
}
146+
("Nil" |: s.sameElements(Nil) == coll.sameElements(Nil)) &&
147+
("toList" |: s.sameElements(s.toList) == coll.sameElements(coll.toList)) &&
148+
("identity" |: s.sameElements(s.map(e => e)) == coll.sameElements(coll.map(e => e))) &&
149+
("vice-versa" |: s.sameElements(coll) == coll.sameElements(s)) &&
150+
("equal" |: s.sameElements(coll)) &&
151+
("modified" |: scm == ccm) &&
152+
(for ((it, ind) <- sameElementsSeqs.zipWithIndex) yield {
153+
val sres = s.sameElements(it)
154+
val pres = coll.sameElements(it)
155+
if (sres != pres) {
156+
println("Comparing: " + s)
157+
println("and: " + coll)
158+
println("with: " + it)
159+
println(sres)
160+
println(pres)
161+
}
162+
("collection " + ind) |: sres == pres
163+
}).reduceLeft(_ && _)
164+
}
165165

166-
// property("startsWiths must be equal") = forAllNoShrink(collectionPairsWithModifiedWithLengths) {
167-
// case (s, coll, collmodif, len) =>
168-
// val pos = if (len < 0) 0 else len
169-
// ("start with self" |: s.startsWith(s) == coll.startsWith(coll)) &&
170-
// ("tails correspond" |: (s.length == 0 || s.startsWith(s.tail, 1) == coll.startsWith(coll.tail, 1))) &&
171-
// ("with each other" |: coll.startsWith(s)) &&
172-
// ("modified" |: s.startsWith(collmodif) == coll.startsWith(collmodif)) &&
173-
// ("modified2" |: s.startsWith(collmodif, pos) == coll.startsWith(collmodif, pos)) &&
174-
// (for (sq <- startEndSeqs) yield {
175-
// val ss = s.startsWith(sq, pos)
176-
// val cs = coll.startsWith(fromSeq(sq), pos)
177-
// if (ss != cs) {
178-
// println("from: " + s)
179-
// println("and: " + coll)
180-
// println("test seq: " + sq)
181-
// println("from pos: " + pos)
182-
// println(ss)
183-
// println(cs)
184-
// println(coll.iterator.psplit(pos, coll.length - pos)(1).toList)
185-
// }
186-
// ("seq " + sq) |: ss == cs
187-
// }).reduceLeft(_ && _)
188-
// }
166+
property("startsWiths must be equal") = forAllNoShrink(collectionPairsWithModifiedWithLengths) {
167+
case (s, coll, collmodif, len) =>
168+
val pos = if (len < 0) 0 else len
169+
("start with self" |: s.startsWith(s) == coll.startsWith(coll)) &&
170+
("tails correspond" |: (s.length == 0 || s.startsWith(s.tail, 1) == coll.startsWith(coll.tail, 1))) &&
171+
("with each other" |: coll.startsWith(s)) &&
172+
("modified" |: s.startsWith(collmodif) == coll.startsWith(collmodif)) &&
173+
("modified2" |: s.startsWith(collmodif, pos) == coll.startsWith(collmodif, pos)) &&
174+
(for (sq <- startEndSeqs) yield {
175+
val ss = s.startsWith(sq, pos)
176+
val cs = coll.startsWith(fromSeq(sq), pos)
177+
if (ss != cs) {
178+
println("from: " + s)
179+
println("and: " + coll)
180+
println("test seq: " + sq)
181+
println("from pos: " + pos)
182+
println(ss)
183+
println(cs)
184+
println(coll.iterator.psplit(pos, coll.length - pos)(1).toList)
185+
}
186+
("seq " + sq) |: ss == cs
187+
}).reduceLeft(_ && _)
188+
}
189189

190-
// property("endsWiths must be equal") = forAllNoShrink(collectionPairsWithModified) {
191-
// case (s, coll, collmodif) =>
192-
// ("ends with self" |: s.endsWith(s) == coll.endsWith(s)) &&
193-
// ("ends with tail" |: (s.length == 0 || s.endsWith(s.tail) == coll.endsWith(coll.tail))) &&
194-
// ("with each other" |: coll.endsWith(s)) &&
195-
// ("modified" |: s.startsWith(collmodif) == coll.endsWith(collmodif)) &&
196-
// (for (sq <- startEndSeqs) yield {
197-
// val sew = s.endsWith(sq)
198-
// val cew = coll.endsWith(fromSeq(sq))
199-
// if (sew != cew) {
200-
// println("from: " + s)
201-
// println("and: " + coll)
202-
// println(sew)
203-
// println(cew)
204-
// }
205-
// ("seq " + sq) |: sew == cew
206-
// }).reduceLeft(_ && _)
207-
// }
190+
property("endsWiths must be equal") = forAllNoShrink(collectionPairsWithModified) {
191+
case (s, coll, collmodif) =>
192+
("ends with self" |: s.endsWith(s) == coll.endsWith(s)) &&
193+
("ends with tail" |: (s.length == 0 || s.endsWith(s.tail) == coll.endsWith(coll.tail))) &&
194+
("with each other" |: coll.endsWith(s)) &&
195+
("modified" |: s.startsWith(collmodif) == coll.endsWith(collmodif)) &&
196+
(for (sq <- startEndSeqs if s.nonEmpty /* guard because of https://github.com/scala/bug/issues/11328 */) yield {
197+
val sew = s.endsWith(sq)
198+
val cew = coll.endsWith(fromSeq(sq))
199+
if (sew != cew) {
200+
println("from: " + s)
201+
println("and: " + coll)
202+
println(sew)
203+
println(cew)
204+
}
205+
("seq " + sq) |: sew == cew
206+
}).foldLeft(Prop.passed)(_ && _)
207+
}
208208

209209
// property("unions must be equal") = forAllNoShrink(collectionPairsWithModified) { case (s, coll, collmodif) =>
210210
// ("modified" |: s.union(collmodif.seq) == coll.union(collmodif)) &&

0 commit comments

Comments
 (0)