Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Deprecate internal forAllShrink #457

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions src/main/scala/org/scalacheck/Prop.scala
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ object Prop {

import Gen.{fail, Parameters}
import Arbitrary.{arbitrary}
import Shrink.{shrink}

// Types

Expand Down Expand Up @@ -748,9 +747,17 @@ object Prop {

/** Universal quantifier for an explicit generator. Shrinks failed arguments
* with the given shrink function */
@deprecated("Use forAllShrink with implicit Shrink[T]", "1.15.0")
def forAllShrink[T, P](g: Gen[T],
shrink: T => Stream[T])(f: T => P
)(implicit pv: P => Prop, pp: T => Pretty
): Prop = forAllShrink(g, Shrink(shrink))(f)

/** Universal quantifier for an explicit generator. Shrinks failed arguments
* with the explicit `Shrink`. */
private def forAllShrink[T, P](g: Gen[T],
s: Shrink[T])(f: T => P
)(implicit pv: P => Prop, pp: T => Pretty
): Prop = Prop { prms0 =>

val (prms, seed) = startSeed(prms0)
Expand All @@ -775,7 +782,7 @@ object Prop {
}

def shrinker(x: T, r: Result, shrinks: Int, orig: T): Result = {
val xs = shrink(x).filter(gr.sieve)
val xs = s.shrink(x).filter(gr.sieve)
val res = r.addArg(Arg(labels,x,shrinks,orig,pp(x),pp(orig)))
if(xs.isEmpty) res else getFirstFailure(xs) match {
case Right((x2,r2)) => res
Expand Down Expand Up @@ -812,7 +819,7 @@ object Prop {
p: P => Prop,
s1: Shrink[T1],
pp1: T1 => Pretty
): Prop = forAllShrink[T1,P](g1, shrink[T1])(f)
): Prop = forAllShrink[T1,P](g1, s1)(f)

/** Universal quantifier for two explicit generators. Shrinks failed arguments
* with the default shrink function for the type */
Expand Down Expand Up @@ -910,7 +917,7 @@ object Prop {
f: A1 => P)(implicit
p: P => Prop,
a1: Arbitrary[A1], s1: Shrink[A1], pp1: A1 => Pretty
): Prop = forAllShrink(arbitrary[A1],shrink[A1])(f andThen p)
): Prop = forAllShrink(arbitrary[A1],s1)(f andThen p)

/** Converts a function into a universally quantified property */
def forAll[A1,A2,P] (
Expand Down
104 changes: 103 additions & 1 deletion src/test/scala/org/scalacheck/PropSpecification.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ package org.scalacheck
import Prop.{
forAll, falsified, undecided, exception, passed, proved, all,
atLeastOne, sizedProp, someFailing, noneFailing, Undecided, False, True,
Exception, Proof, throws, BooleanOperators, secure, delay, lzy
Exception, Proof, throws, BooleanOperators, secure, delay, lzy,
forAllShrink, forAllNoShrink
}
import Gen.{ const, fail, oneOf, listOf, Parameters }

Expand Down Expand Up @@ -129,6 +130,107 @@ object PropSpecification extends Properties("Prop") {
falsified(prms).status == False
}

// FIXME: This method was deprecated in 1.15.0, and will be removed.
property("forAllShrink(Gen, T=>Shrink[T])") = {
val anyVal: Gen[AnyVal] = Arbitrary.arbitrary[AnyVal]
val shrinkAnyVal: Shrink[AnyVal] = Shrink {
case v: Unit => Shrink.shrink[Unit](v)
case v: Boolean => Shrink.shrink[Boolean](v)
case v: Char => Shrink.shrink[Char](v)
case v: Byte => Shrink.shrink[Byte](v)
case v: Short => Shrink.shrink[Short](v)
case v: Int => Shrink.shrink[Int](v)
case v: Long => Shrink.shrink[Long](v)
case v: Float => Shrink.shrink[Float](v)
case v: Double => Shrink.shrink[Double](v)
}
forAllShrink(anyVal, shrinkAnyVal.shrink(_: AnyVal)) { _ =>
passed
}
}

property("forAll(Arbitrary)") = {
forAll { (_: AnyVal, _: AnyVal, _: AnyVal, _: AnyVal, _: AnyVal, _: AnyVal, _: AnyVal, _: AnyVal) =>
forAll { (_: AnyVal, _: AnyVal, _: AnyVal, _: AnyVal, _: AnyVal, _: AnyVal, _: AnyVal) =>
forAll { (_: AnyVal, _: AnyVal, _: AnyVal, _: AnyVal, _: AnyVal, _: AnyVal) =>
forAll { (_: AnyVal, _: AnyVal, _: AnyVal, _: AnyVal, _: AnyVal) =>
forAll { (_: AnyVal, _: AnyVal, _: AnyVal, _: AnyVal) =>
forAll { (_: AnyVal, _: AnyVal, _: AnyVal) =>
forAll { (_: AnyVal, _: AnyVal) =>
forAll { (_: AnyVal) =>
passed
}
}
}
}
}
}
}
}
}

property("forAllNoShrink(Arbitrary)") = {
forAllNoShrink { (_: AnyVal, _: AnyVal, _: AnyVal, _: AnyVal, _: AnyVal, _: AnyVal, _: AnyVal, _: AnyVal) =>
forAllNoShrink { (_: AnyVal, _: AnyVal, _: AnyVal, _: AnyVal, _: AnyVal, _: AnyVal, _: AnyVal) =>
forAllNoShrink { (_: AnyVal, _: AnyVal, _: AnyVal, _: AnyVal, _: AnyVal, _: AnyVal) =>
forAllNoShrink { (_: AnyVal, _: AnyVal, _: AnyVal, _: AnyVal, _: AnyVal) =>
forAllNoShrink { (_: AnyVal, _: AnyVal, _: AnyVal, _: AnyVal) =>
forAllNoShrink { (_: AnyVal, _: AnyVal, _: AnyVal) =>
forAllNoShrink { (_: AnyVal, _: AnyVal) =>
forAllNoShrink { (_: AnyVal) =>
passed
}
}
}
}
}
}
}
}
}

property("forAll(Gen)") = {
val anyVal: Gen[AnyVal] = Arbitrary.arbitrary[AnyVal]
forAll(anyVal, anyVal, anyVal, anyVal, anyVal, anyVal, anyVal, anyVal) { (_, _, _, _, _, _, _, _) =>
forAll(anyVal, anyVal, anyVal, anyVal, anyVal, anyVal, anyVal) { (_, _, _, _, _, _, _) =>
forAll(anyVal, anyVal, anyVal, anyVal, anyVal, anyVal) { (_, _, _, _, _, _) =>
forAll(anyVal, anyVal, anyVal, anyVal, anyVal) { (_, _, _, _, _) =>
forAll(anyVal, anyVal, anyVal, anyVal) { (_, _, _, _) =>
forAll(anyVal, anyVal, anyVal) { (_, _, _) =>
forAll(anyVal, anyVal) { (_, _) =>
forAll(anyVal) { (_) =>
passed
}
}
}
}
}
}
}
}
}

property("forAllNoShrink(Gen)") = {
val anyVal: Gen[AnyVal] = Arbitrary.arbitrary[AnyVal]
forAllNoShrink(anyVal, anyVal, anyVal, anyVal, anyVal, anyVal, anyVal, anyVal) { (_, _, _, _, _, _, _, _) =>
forAllNoShrink(anyVal, anyVal, anyVal, anyVal, anyVal, anyVal, anyVal) { (_, _, _, _, _, _, _) =>
forAllNoShrink(anyVal, anyVal, anyVal, anyVal, anyVal, anyVal) { (_, _, _, _, _, _) =>
forAllNoShrink(anyVal, anyVal, anyVal, anyVal, anyVal) { (_, _, _, _, _) =>
forAllNoShrink(anyVal, anyVal, anyVal, anyVal) { (_, _, _, _) =>
forAllNoShrink(anyVal, anyVal, anyVal) { (_, _, _) =>
forAllNoShrink(anyVal, anyVal) { (_, _) =>
forAllNoShrink(anyVal) { (_) =>
passed
}
}
}
}
}
}
}
}
}

property("proved") = forAll((prms: Parameters) => proved(prms).status == Proof)

property("passed") = forAll((prms: Parameters) => passed(prms).status == True)
Expand Down