diff options
author | Aleksandar Pokopec <aleksandar.prokopec@epfl.ch> | 2011-03-11 23:07:08 +0000 |
---|---|---|
committer | Aleksandar Pokopec <aleksandar.prokopec@epfl.ch> | 2011-03-11 23:07:08 +0000 |
commit | 0254234328ab8a438aac649234bd5e12614f8ff9 (patch) | |
tree | 41ad8758e6697ac64881e3df471030d4921c4bac | |
parent | 8f245d95f683dec681ea98406c438da32409c088 (diff) | |
download | scala-0254234328ab8a438aac649234bd5e12614f8ff9.tar.gz scala-0254234328ab8a438aac649234bd5e12614f8ff9.tar.bz2 scala-0254234328ab8a438aac649234bd5e12614f8ff9.zip |
Fixes the broken test, introduced in the view p...
Fixes the broken test, introduced in the view patch commit.
No review.
-rw-r--r-- | src/library/scala/collection/parallel/ParSeqLike.scala | 5 | ||||
-rw-r--r-- | test/files/scalacheck/parallel-collections/ParallelSeqCheck.scala | 20 |
2 files changed, 15 insertions, 10 deletions
diff --git a/src/library/scala/collection/parallel/ParSeqLike.scala b/src/library/scala/collection/parallel/ParSeqLike.scala index 9ac647cf5a..d40ced0cd8 100644 --- a/src/library/scala/collection/parallel/ParSeqLike.scala +++ b/src/library/scala/collection/parallel/ParSeqLike.scala @@ -262,9 +262,10 @@ self => } else patch_sequential(from, patch, replaced) } - private def patch_sequential[U >: T, That](from: Int, patch: Seq[U], r: Int)(implicit bf: CanBuildFrom[Repr, U, That]): That = { + private def patch_sequential[U >: T, That](fromarg: Int, patch: Seq[U], r: Int)(implicit bf: CanBuildFrom[Repr, U, That]): That = { + val from = 0 max fromarg val b = bf(repr) - val repl = r min (length - from) + val repl = (r min (length - from)) max 0 val pits = parallelIterator.psplit(from, repl, length - from - repl) b ++= pits(0) b ++= patch.iterator diff --git a/test/files/scalacheck/parallel-collections/ParallelSeqCheck.scala b/test/files/scalacheck/parallel-collections/ParallelSeqCheck.scala index a56cc763a6..4373157311 100644 --- a/test/files/scalacheck/parallel-collections/ParallelSeqCheck.scala +++ b/test/files/scalacheck/parallel-collections/ParallelSeqCheck.scala @@ -65,7 +65,7 @@ abstract class ParallelSeqCheck[T](collName: String) extends ParallelIterableChe } def collectionTripletsWith2Indices: Gen[(Seq[T], CollType, Seq[T], Int, Int)] = - for (inst <- instances(values); f <- choose(0, inst.size); s <- choose(0, inst.size); + 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) } @@ -218,16 +218,20 @@ abstract class ParallelSeqCheck[T](collName: String) extends ParallelIterableChe ("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. // - // 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)) && - // ("with par" |: s.patch(from, pat, repl) == coll.patch(from, fromSeq(pat), repl)) && - // ("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))) - // } + // 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)) && + ("with par" |: s.patch(from, pat, repl) == coll.patch(from, fromSeq(pat), repl)) && + ("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 |