Skip to content
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
8 changes: 4 additions & 4 deletions doc/UserGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -873,15 +873,15 @@ object CounterSpecification extends Commands {
* (a singleton [[Sut]]), implement this method the following way:
*
* {{{
* def canCreateNewSut(newState: State, initSuts: Traversable[State]
* runningSuts: Traversable[Sut]
* def canCreateNewSut(newState: State, initSuts: Iterable[State]
* runningSuts: Iterable[Sut]
* ) = {
* initSuts.isEmpty && runningSuts.isEmpty
* }
* }}}
*/
def canCreateNewSut(newState: State, initSuts: Traversable[State],
runningSuts: Traversable[Sut]): Boolean = true
def canCreateNewSut(newState: State, initSuts: Iterable[State],
runningSuts: Iterable[Sut]): Boolean = true

/** The precondition for the initial state, when no commands yet have
* run. This is used by ScalaCheck when command sequences are shrinked
Expand Down
1 change: 1 addition & 0 deletions jvm/src/test/scala/org/scalacheck/GenSpecification.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import Arbitrary._
import Shrink._
import java.util.Date
import scala.util.{Try, Success, Failure}
import scala.collection.immutable.Seq

object GenSpecification extends Properties("Gen") {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ object CommandsSpecification extends Properties("Commands") {

override def shrinkState: Shrink[Int] = implicitly

def canCreateNewSut(newState: State, initSuts: Traversable[State],
runningSuts: Traversable[Sut]) = true
def canCreateNewSut(newState: State, initSuts: Iterable[State],
runningSuts: Iterable[Sut]) = true

def newSut(state: State): Sut = Counter(state)

Expand Down
17 changes: 17 additions & 0 deletions project/MimaSettings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,36 @@ object MimaSettings {
removedPrivateMethods.map(exclude[DirectMissingMethodProblem](_)) ++
newMethods.map(exclude[ReversedMissingMethodProblem](_)) ++
removedPrivateClasses.map(exclude[MissingClassProblem](_)) ++
methodTypeChanges.map(exclude[IncompatibleMethTypeProblem](_)) ++
returnTypeChanges.map(exclude[IncompatibleResultTypeProblem](_)) ++
otherProblems
)

private def newMethods = Seq(
"org.scalacheck.util.Buildable.fromIterable",
"org.scalacheck.commands.Commands.canCreateNewSut"
)

private def removedPrivateMethods = Seq(
"org.scalacheck.util.Buildable.fromIterable"
)

private def removedPrivateClasses = Seq(
"org.scalacheck.Platform$EnableReflectiveInstantiation"
)

private def methodTypeChanges = Seq(
"org.scalacheck.Gen.oneOf",
"org.scalacheck.Gen.sequence",
"org.scalacheck.commands.Commands.canCreateNewSut",
"org.scalacheck.util.Buildable.fromIterable"
)

private def returnTypeChanges = Seq(
"org.scalacheck.Properties.properties",
"org.scalacheck.Test.checkProperties"
)

private def otherProblems = Seq(
)

Expand Down
6 changes: 3 additions & 3 deletions src/main/scala/org/scalacheck/Arbitrary.scala
Original file line number Diff line number Diff line change
Expand Up @@ -360,19 +360,19 @@ private[scalacheck] sealed trait ArbitraryLowPriority {
* (such as lists, arrays, streams, etc). The maximum size of the container
* depends on the size generation parameter. */
implicit def arbContainer[C[_],T](implicit
a: Arbitrary[T], b: Buildable[T,C[T]], t: C[T] => Traversable[T]
a: Arbitrary[T], b: Buildable[T,C[T]], t: C[T] => Iterable[T]
): Arbitrary[C[T]] = Arbitrary(buildableOf[C[T],T](arbitrary[T]))

/** Arbitrary instance of any [[org.scalacheck.util.Buildable]] container
* (such as maps). The maximum size of the container depends on the size
* generation parameter. */
implicit def arbContainer2[C[_,_],T,U](implicit
a: Arbitrary[(T,U)], b: Buildable[(T,U),C[T,U]], t: C[T,U] => Traversable[(T,U)]
a: Arbitrary[(T,U)], b: Buildable[(T,U),C[T,U]], t: C[T,U] => Iterable[(T,U)]
): Arbitrary[C[T,U]] = Arbitrary(buildableOf[C[T,U],(T,U)](arbitrary[(T,U)]))

implicit def arbEnum[A <: java.lang.Enum[A]](implicit A: reflect.ClassTag[A]): Arbitrary[A] = {
val values = A.runtimeClass.getEnumConstants.asInstanceOf[Array[A]]
Arbitrary(Gen.oneOf(values))
Arbitrary(Gen.oneOf(values.to[Vector]))
}

implicit def arbPartialFunction[A: Cogen, B: Arbitrary]: Arbitrary[PartialFunction[A, B]] =
Expand Down
27 changes: 14 additions & 13 deletions src/main/scala/org/scalacheck/Gen.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import util.Buildable
import util.SerializableCanBuildFroms._

import scala.annotation.tailrec
import scala.collection.immutable.Seq
import scala.collection.immutable.TreeMap
import scala.collection.mutable.ArrayBuffer
import scala.concurrent.duration.{Duration, FiniteDuration}
Expand Down Expand Up @@ -449,7 +450,7 @@ object Gen extends GenArities{

/** Sequences generators. If any of the given generators fails, the
* resulting generator will also fail. */
def sequence[C,T](gs: Traversable[Gen[T]])(implicit b: Buildable[T,C]): Gen[C] = {
def sequence[C,T](gs: Iterable[Gen[T]])(implicit b: Buildable[T,C]): Gen[C] = {
val g = gen { (p, seed) =>
gs.foldLeft(r(Some(Vector.empty[T]), seed)) {
case (rs,g) =>
Expand Down Expand Up @@ -530,7 +531,7 @@ object Gen extends GenArities{
}

/** Picks a random value from a list */
def oneOf[T](t0: T, t1: T, tn: T*): Gen[T] = oneOf(t0 +: t1 +: tn)
def oneOf[T](t0: T, t1: T, tn: T*): Gen[T] = oneOf((t0 +: t1 +: tn).to[Vector])

/** Picks a random generator from a list */
def oneOf[T](g0: Gen[T], g1: Gen[T], gn: Gen[T]*): Gen[T] = {
Expand Down Expand Up @@ -576,55 +577,55 @@ object Gen extends GenArities{

//// List Generators ////

/** Generates a container of any Traversable type for which there exists an
/** Generates a container of any Iterable type for which there exists an
* implicit [[org.scalacheck.util.Buildable]] instance. The elements in the
* container will be generated by the given generator. The size of the
* generated container is limited by `n`. Depending on what kind of container
* that is generated, the resulting container may contain fewer elements than
* `n`, but not more. If the given generator fails generating a value, the
* complete container generator will also fail. */
def buildableOfN[C,T](n: Int, g: Gen[T])(implicit
evb: Buildable[T,C], evt: C => Traversable[T]
evb: Buildable[T,C], evt: C => Iterable[T]
): Gen[C] =
sequence[C,T](Traversable.fill(n)(g)) suchThat { c =>
sequence[C,T](Iterable.fill(n)(g)) suchThat { c =>
// TODO: Can we guarantee c.size == n (See issue #89)?
c.forall(g.sieveCopy)
}

/** Generates a container of any Traversable type for which there exists an
/** Generates a container of any Iterable type for which there exists an
* implicit [[org.scalacheck.util.Buildable]] instance. The elements in the
* container will be generated by the given generator. The size of the
* container is bounded by the size parameter used when generating values. */
def buildableOf[C,T](g: Gen[T])(implicit
evb: Buildable[T,C], evt: C => Traversable[T]
evb: Buildable[T,C], evt: C => Iterable[T]
): Gen[C] =
sized(s => choose(0, s max 0).flatMap(buildableOfN[C,T](_,g))) suchThat { c =>
if (c == null) g.sieveCopy(null) else c.forall(g.sieveCopy)
}

/** Generates a non-empty container of any Traversable type for which there
/** Generates a non-empty container of any Iterable type for which there
* exists an implicit [[org.scalacheck.util.Buildable]] instance. The
* elements in the container will be generated by the given generator. The
* size of the container is bounded by the size parameter used when
* generating values. */
def nonEmptyBuildableOf[C,T](g: Gen[T])(implicit
evb: Buildable[T,C], evt: C => Traversable[T]
evb: Buildable[T,C], evt: C => Iterable[T]
): Gen[C] =
sized(s => choose(1, s max 1).flatMap(buildableOfN[C,T](_,g))) suchThat(_.size > 0)

/** A convenience method for calling `buildableOfN[C[T],T](n,g)`. */
def containerOfN[C[_],T](n: Int, g: Gen[T])(implicit
evb: Buildable[T,C[T]], evt: C[T] => Traversable[T]
evb: Buildable[T,C[T]], evt: C[T] => Iterable[T]
): Gen[C[T]] = buildableOfN[C[T],T](n,g)

/** A convenience method for calling `buildableOf[C[T],T](g)`. */
def containerOf[C[_],T](g: Gen[T])(implicit
evb: Buildable[T,C[T]], evt: C[T] => Traversable[T]
evb: Buildable[T,C[T]], evt: C[T] => Iterable[T]
): Gen[C[T]] = buildableOf[C[T],T](g)

/** A convenience method for calling `nonEmptyBuildableOf[C[T],T](g)`. */
def nonEmptyContainerOf[C[_],T](g: Gen[T])(implicit
evb: Buildable[T,C[T]], evt: C[T] => Traversable[T]
evb: Buildable[T,C[T]], evt: C[T] => Iterable[T]
): Gen[C[T]] = nonEmptyBuildableOf[C[T],T](g)

/** Generates a list of random length. The maximum length depends on the
Expand Down Expand Up @@ -707,7 +708,7 @@ object Gen extends GenArities{
seed = s
}
}
r(Some(buf), seed)
r(Some(buf.to[Vector]), seed)
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/main/scala/org/scalacheck/Properties.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ package org.scalacheck
import org.scalacheck.rng.Seed

import language.reflectiveCalls
import collection.immutable.Seq

import util.ConsoleReporter

Expand Down Expand Up @@ -41,7 +42,7 @@ class Properties(val name: String) {

/** Returns all properties of this collection in a list of name/property
* pairs. */
def properties: Seq[(String,Prop)] = props
def properties: Seq[(String,Prop)] = props.to[Seq]

/** Convenience method that checks the properties with the given parameters
* (or default parameters, if not specified)
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/org/scalacheck/ScalaCheckFramework.scala
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ private abstract class ScalaCheckRunner extends Runner {
abstract class BaseTask(override val taskDef: TaskDef) extends Task {
val tags: Array[String] = Array()

val props: Seq[(String,Prop)] = {
val props: collection.Seq[(String,Prop)] = {
val fp = taskDef.fingerprint.asInstanceOf[SubclassFingerprint]
val obj = if (fp.isModule) Platform.loadModule(taskDef.fullyQualifiedName,loader)
else Platform.newInstance(taskDef.fullyQualifiedName, loader, Seq())(Seq())
Expand Down
4 changes: 2 additions & 2 deletions src/main/scala/org/scalacheck/Shrink.scala
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ object Shrink extends ShrinkLowPriority {
cons(x, s.shrink(x))

/** Shrink instance of container */
implicit def shrinkContainer[C[_],T](implicit v: C[T] => Traversable[T], s: Shrink[T],
implicit def shrinkContainer[C[_],T](implicit v: C[T] => Iterable[T], s: Shrink[T],
b: Buildable[T,C[T]]
): Shrink[C[T]] = Shrink { xs: C[T] =>
val ys = v(xs)
Expand All @@ -58,7 +58,7 @@ object Shrink extends ShrinkLowPriority {
}

/** Shrink instance of container2 */
implicit def shrinkContainer2[C[_,_],T,U](implicit v: C[T,U] => Traversable[(T,U)], s: Shrink[(T,U)],
implicit def shrinkContainer2[C[_,_],T,U](implicit v: C[T,U] => Iterable[(T,U)], s: Shrink[(T,U)],
b: Buildable[(T,U),C[T,U]]
): Shrink[C[T,U]] = Shrink { xs: C[T,U] =>
val ys = v(xs)
Expand Down
2 changes: 2 additions & 0 deletions src/main/scala/org/scalacheck/Test.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ package org.scalacheck

import Prop.Arg

import scala.collection.immutable.Seq

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is because Test.checkProperties return type is defined as Seq[(String,Result)].

object Test {

import util.{FreqMap, CmdLineParser, ConsoleReporter}
Expand Down
8 changes: 4 additions & 4 deletions src/main/scala/org/scalacheck/commands/Commands.scala
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@ trait Commands {
* (a singleton [[Sut]]), implement this method the following way:
*
* {{{
* def canCreateNewSut(newState: State, initSuts: Traversable[State]
* runningSuts: Traversable[Sut]
* def canCreateNewSut(newState: State, initSuts: Iterable[State]
* runningSuts: Iterable[Sut]
* ) = {
* initSuts.isEmpty && runningSuts.isEmpty
* }
* }}}
*/
def canCreateNewSut(newState: State, initSuts: Traversable[State],
runningSuts: Traversable[Sut]): Boolean
def canCreateNewSut(newState: State, initSuts: Iterable[State],
runningSuts: Iterable[Sut]): Boolean

/** Create a new [[Sut]] instance with an internal state that
* corresponds to the provided abstract state instance. The provided state
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/org/scalacheck/util/Buildable.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import generic.CanBuildFrom

trait Buildable[T,C] extends Serializable {
def builder: mutable.Builder[T,C]
def fromIterable(it: Traversable[T]): C = {
def fromIterable(it: Iterable[T]): C = {
val b = builder
b ++= it
b.result()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import collection._
object BuildableSpecification {
def container[C[_]](implicit
evb: Buildable[String, C[String]],
evt: C[String] => Traversable[String]
evt: C[String] => Iterable[String]
) = Gen.containerOf[C, String](Gen.alphaStr)

implicit val listGen: Gen[List[String]] = container[List]
Expand Down