Skip to content

Commit

Permalink
ScalaCheck 1.13.0
Browse files Browse the repository at this point in the history
  • Loading branch information
adelbertc committed Mar 21, 2016
1 parent df56b82 commit d082fea
Show file tree
Hide file tree
Showing 32 changed files with 115 additions and 104 deletions.
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ lazy val commonJvmSettings = Seq(

lazy val catsSettings = buildSettings ++ commonSettings ++ publishSettings ++ scoverageSettings

lazy val scalacheckVersion = "1.12.5"
lazy val scalacheckVersion = "1.13.0"

lazy val disciplineDependencies = Seq(
libraryDependencies += "org.scalacheck" %%% "scalacheck" % scalacheckVersion,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ package laws
package discipline

import cats.laws.discipline.CartesianTests.Isomorphisms
import org.scalacheck.Arbitrary
import org.scalacheck.Prop
import org.scalacheck.{Arbitrary, Cogen, Prop}
import Prop._

trait AlternativeTests[F[_]] extends ApplicativeTests[F] with MonoidKTests[F] {
def laws: AlternativeLaws[F]

def alternative[A: Arbitrary, B: Arbitrary, C: Arbitrary](implicit
def alternative[A: Arbitrary: Cogen, B: Arbitrary: Cogen, C: Arbitrary: Cogen](implicit
ArbFA: Arbitrary[F[A]],
ArbFB: Arbitrary[F[B]],
ArbFC: Arbitrary[F[C]],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,20 @@ package discipline
import cats.data.{ Xor, XorT }
import cats.laws.discipline.CartesianTests.Isomorphisms
import cats.laws.discipline.arbitrary._
import org.scalacheck.{Arbitrary, Prop}
import org.scalacheck.{Arbitrary, Cogen, Prop}
import org.scalacheck.Prop.forAll

trait ApplicativeErrorTests[F[_], E] extends ApplicativeTests[F] {
def laws: ApplicativeErrorLaws[F, E]

def applicativeError[A: Arbitrary: Eq, B: Arbitrary: Eq, C: Arbitrary: Eq](implicit
def applicativeError[A: Arbitrary: Eq: Cogen, B: Arbitrary: Eq: Cogen, C: Arbitrary: Cogen: Eq](implicit
ArbFA: Arbitrary[F[A]],
ArbFB: Arbitrary[F[B]],
ArbFC: Arbitrary[F[C]],
ArbFAtoB: Arbitrary[F[A => B]],
ArbFBtoC: Arbitrary[F[B => C]],
ArbE: Arbitrary[E],
CogenE: Cogen[E],
EqFA: Eq[F[A]],
EqFB: Eq[F[B]],
EqFC: Eq[F[C]],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ package laws
package discipline

import cats.laws.discipline.CartesianTests.Isomorphisms
import org.scalacheck.Arbitrary
import org.scalacheck.Prop
import org.scalacheck.{Arbitrary, Cogen, Prop}
import Prop._

trait ApplicativeTests[F[_]] extends ApplyTests[F] {
def laws: ApplicativeLaws[F]

def applicative[A: Arbitrary, B: Arbitrary, C: Arbitrary](implicit
def applicative[A: Arbitrary: Cogen, B: Arbitrary: Cogen, C: Arbitrary: Cogen](implicit
ArbFA: Arbitrary[F[A]],
ArbFB: Arbitrary[F[B]],
ArbFC: Arbitrary[F[C]],
Expand Down
5 changes: 2 additions & 3 deletions laws/src/main/scala/cats/laws/discipline/ApplyTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ package laws
package discipline

import cats.laws.discipline.CartesianTests.Isomorphisms
import org.scalacheck.Arbitrary
import org.scalacheck.Prop
import org.scalacheck.{Arbitrary, Cogen, Prop}
import Prop._

trait ApplyTests[F[_]] extends FunctorTests[F] with CartesianTests[F] {
def laws: ApplyLaws[F]

def apply[A: Arbitrary, B: Arbitrary, C: Arbitrary](implicit
def apply[A: Arbitrary: Cogen, B: Arbitrary: Cogen, C: Arbitrary: Cogen](implicit
ArbFA: Arbitrary[F[A]],
ArbFB: Arbitrary[F[B]],
ArbFC: Arbitrary[F[C]],
Expand Down
36 changes: 27 additions & 9 deletions laws/src/main/scala/cats/laws/discipline/Arbitrary.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,13 @@ package laws
package discipline

import cats.data._
import org.scalacheck.{Arbitrary, Gen}
import org.scalacheck.{Arbitrary, Cogen, Gen}
import org.scalacheck.Arbitrary.{arbitrary => getArbitrary}

/**
* Arbitrary instances for cats.data
*/
object arbitrary extends ArbitraryInstances0 {

// A special function1Arbitrary for testing operations like dropWhile specifically
// in the context of Int => Boolean. Once scalacheck supports better Function1 arbitrary
// instances this can be removed.
implicit def function1Arbitrary: Arbitrary[(Int) => Boolean] =
Arbitrary(getArbitrary[Int].map(x => (input) => input < x))

object arbitrary extends CogenInstances with ArbitraryInstances0 {
implicit def constArbitrary[A, B](implicit A: Arbitrary[A]): Arbitrary[Const[A, B]] =
Arbitrary(A.arbitrary.map(Const[A, B]))

Expand Down Expand Up @@ -82,3 +75,28 @@ private[discipline] sealed trait ArbitraryInstances0 {
implicit def writerTArbitrary[F[_], L, V](implicit F: Arbitrary[F[(L, V)]]): Arbitrary[WriterT[F, L, V]] =
Arbitrary(F.arbitrary.map(WriterT(_)))
}

private[discipline] sealed trait CogenInstances extends StdLibCogen {
implicit def coproductCogen[F[_], G[_], A](implicit
CogenFA: Cogen[F[A]],
CogenGA: Cogen[G[A]]
): Cogen[Coproduct[F, G, A]] =
Cogen[Xor[F[A], G[A]]].contramap(_.run)

implicit def evalCogen[A: Cogen]: Cogen[Eval[A]] =
Cogen((seed, evalA) => Cogen[A].perturb(seed, evalA.value))

implicit def oneAndCogen[F[_], A](implicit FA: Cogen[(A, F[A])]): Cogen[OneAnd[F, A]] =
FA.contramap(o => (o.head, o.tail))

implicit def xorCogen[A: Cogen, B: Cogen]: Cogen[Xor[A, B]] =
Cogen[Either[A, B]].contramap(_.toEither)
}

private[discipline] sealed trait StdLibCogen {
implicit def function0Cogen[A: Cogen]: Cogen[Function0[A]] =
Cogen[A].contramap(_())

implicit def streamCogen[A: Cogen]: Cogen[Stream[A]] =
Cogen[List[A]].contramap(_.toList)
}
5 changes: 2 additions & 3 deletions laws/src/main/scala/cats/laws/discipline/ArrowTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ package laws
package discipline

import cats.arrow.Arrow
import org.scalacheck.Arbitrary
import org.scalacheck.Prop
import org.scalacheck.{Arbitrary, Cogen, Prop}
import Prop._

trait ArrowTests[F[_, _]] extends CategoryTests[F] with SplitTests[F] with StrongTests[F] {
def laws: ArrowLaws[F]

def arrow[A: Arbitrary, B: Arbitrary, C: Arbitrary, D: Arbitrary, E: Arbitrary, G: Arbitrary](implicit
def arrow[A: Arbitrary: Cogen, B: Arbitrary: Cogen, C: Arbitrary: Cogen, D: Arbitrary: Cogen, E: Arbitrary: Cogen, G: Arbitrary](implicit
ArbFAB: Arbitrary[F[A, B]],
ArbFBC: Arbitrary[F[B, C]],
ArbFCD: Arbitrary[F[C, D]],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ package cats
package laws
package discipline

import org.scalacheck.Arbitrary
import org.scalacheck.{Arbitrary, Cogen}
import org.scalacheck.Prop._
import org.typelevel.discipline.Laws

trait BifoldableTests[F[_, _]] extends Laws {
def laws: BifoldableLaws[F]

def bifoldable[A: Arbitrary, B: Arbitrary, C: Arbitrary: Monoid: Eq](implicit
def bifoldable[A: Arbitrary: Cogen, B: Arbitrary: Cogen, C: Arbitrary: Monoid: Eq](implicit
ArbFAB: Arbitrary[F[A, B]]
): RuleSet =
new DefaultRuleSet(
Expand Down
7 changes: 4 additions & 3 deletions laws/src/main/scala/cats/laws/discipline/BimonadTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@ package laws
package discipline

import cats.laws.discipline.CartesianTests.Isomorphisms
import org.scalacheck.Arbitrary
import org.scalacheck.Prop
import org.scalacheck.{Arbitrary, Cogen, Prop}
import Prop._

trait BimonadTests[F[_]] extends MonadTests[F] with ComonadTests[F] {
def laws: BimonadLaws[F]

def bimonad[A: Arbitrary: Eq, B: Arbitrary: Eq, C: Arbitrary: Eq](implicit
def bimonad[A: Arbitrary: Cogen: Eq, B: Arbitrary: Cogen: Eq, C: Arbitrary: Cogen: Eq](implicit
ArbFA: Arbitrary[F[A]],
CogenFA: Cogen[F[A]],
CogenFB: Cogen[F[B]],
ArbFFA: Arbitrary[F[F[A]]],
ArbFB: Arbitrary[F[B]],
ArbFC: Arbitrary[F[C]],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package cats
package laws
package discipline

import org.scalacheck.Arbitrary
import org.scalacheck.{Arbitrary, Cogen}
import org.scalacheck.Prop.forAll

trait BitraverseTests[F[_, _]] extends BifoldableTests[F] with BifunctorTests[F] {
Expand All @@ -22,6 +22,11 @@ trait BitraverseTests[F[_, _]] extends BifoldableTests[F] with BifunctorTests[F]
ArbC: Arbitrary[C],
ArbE: Arbitrary[E],
ArbH: Arbitrary[H],
CogenA: Cogen[A],
CogenB: Cogen[B],
CogenC: Cogen[C],
CogenD: Cogen[D],
CogenE: Cogen[E],
EqFAB: Eq[F[A, B]],
EqFAD: Eq[F[A, D]],
EqFAH: Eq[F[A, H]],
Expand Down
5 changes: 3 additions & 2 deletions laws/src/main/scala/cats/laws/discipline/CoflatMapTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ package cats
package laws
package discipline

import org.scalacheck.Arbitrary
import org.scalacheck.Prop
import org.scalacheck.{Arbitrary, Cogen, Prop}
import Prop._
import org.typelevel.discipline.Laws

Expand All @@ -12,6 +11,8 @@ trait CoflatMapTests[F[_]] extends Laws {

def coflatMap[A: Arbitrary, B: Arbitrary, C: Arbitrary](implicit
ArbFA: Arbitrary[F[A]],
CogenFA: Cogen[F[A]],
CogenFB: Cogen[F[B]],
EqFA: Eq[F[A]],
EqFC: Eq[F[C]]
): RuleSet = {
Expand Down
7 changes: 4 additions & 3 deletions laws/src/main/scala/cats/laws/discipline/ComonadTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@ package cats
package laws
package discipline

import org.scalacheck.Arbitrary
import org.scalacheck.Prop
import org.scalacheck.{Arbitrary, Cogen, Prop}
import Prop._

trait ComonadTests[F[_]] extends CoflatMapTests[F] {

def laws: ComonadLaws[F]

def comonad[A: Arbitrary: Eq, B: Arbitrary: Eq, C: Arbitrary: Eq](implicit
def comonad[A: Arbitrary: Cogen: Eq, B: Arbitrary: Eq, C: Arbitrary: Eq](implicit
ArbFA: Arbitrary[F[A]],
CogenFA: Cogen[F[A]],
CogenFB: Cogen[F[B]],
EqFA: Eq[F[A]],
EqFFA: Eq[F[F[A]]],
EqFFFA: Eq[F[F[F[A]]]],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ package laws
package discipline

import cats.functor.Contravariant
import org.scalacheck.Arbitrary
import org.scalacheck.{Arbitrary, Cogen}
import org.scalacheck.Prop._

trait ContravariantTests[F[_]] extends InvariantTests[F] {
def laws: ContravariantLaws[F]

def contravariant[A: Arbitrary, B: Arbitrary, C: Arbitrary](implicit
def contravariant[A: Arbitrary: Cogen, B: Arbitrary: Cogen, C: Arbitrary: Cogen](implicit
ArbFA: Arbitrary[F[A]],
EqFA: Eq[F[A]],
EqFC: Eq[F[C]]
Expand Down
5 changes: 2 additions & 3 deletions laws/src/main/scala/cats/laws/discipline/FlatMapTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ package laws
package discipline

import cats.laws.discipline.CartesianTests.Isomorphisms
import org.scalacheck.Arbitrary
import org.scalacheck.Prop
import org.scalacheck.{Arbitrary, Cogen, Prop}
import Prop._

trait FlatMapTests[F[_]] extends ApplyTests[F] {
def laws: FlatMapLaws[F]

def flatMap[A: Arbitrary, B: Arbitrary, C: Arbitrary](implicit
def flatMap[A: Arbitrary: Cogen, B: Arbitrary: Cogen, C: Arbitrary: Cogen](implicit
ArbFA: Arbitrary[F[A]],
ArbFB: Arbitrary[F[B]],
ArbFC: Arbitrary[F[C]],
Expand Down
4 changes: 2 additions & 2 deletions laws/src/main/scala/cats/laws/discipline/FoldableTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ package cats
package laws
package discipline

import org.scalacheck.Arbitrary
import org.scalacheck.{Arbitrary, Cogen}
import org.scalacheck.Prop._
import org.typelevel.discipline.Laws

trait FoldableTests[F[_]] extends Laws {
def laws: FoldableLaws[F]

def foldable[A: Arbitrary, B: Arbitrary](implicit
def foldable[A: Arbitrary: Cogen, B: Arbitrary](implicit
ArbFA: Arbitrary[F[A]],
B: Monoid[B],
EqB: Eq[B]
Expand Down
5 changes: 2 additions & 3 deletions laws/src/main/scala/cats/laws/discipline/FunctorTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@ package cats
package laws
package discipline

import org.scalacheck.Arbitrary
import org.scalacheck.Prop
import org.scalacheck.{Arbitrary, Cogen, Prop}
import Prop._

trait FunctorTests[F[_]] extends InvariantTests[F] {
def laws: FunctorLaws[F]

def functor[A: Arbitrary, B: Arbitrary, C: Arbitrary](implicit
def functor[A: Arbitrary: Cogen, B: Arbitrary: Cogen, C: Arbitrary: Cogen](implicit
ArbFA: Arbitrary[F[A]],
EqFA: Eq[F[A]],
EqFC: Eq[F[C]]
Expand Down
5 changes: 2 additions & 3 deletions laws/src/main/scala/cats/laws/discipline/InvariantTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@ package laws
package discipline

import cats.functor.Invariant
import org.scalacheck.Arbitrary
import org.scalacheck.Prop
import org.scalacheck.{Arbitrary, Cogen, Prop}
import Prop._
import org.typelevel.discipline.Laws

trait InvariantTests[F[_]] extends Laws {
def laws: InvariantLaws[F]

def invariant[A: Arbitrary, B: Arbitrary, C: Arbitrary](implicit
def invariant[A: Arbitrary: Cogen, B: Arbitrary: Cogen, C: Arbitrary: Cogen](implicit
ArbFA: Arbitrary[F[A]],
EqFA: Eq[F[A]],
EqFC: Eq[F[C]]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ package laws
package discipline

import cats.laws.discipline.CartesianTests.Isomorphisms
import org.scalacheck.Arbitrary
import org.scalacheck.Prop
import org.scalacheck.{Arbitrary, Cogen, Prop}
import Prop._

trait MonadCombineTests[F[_]] extends MonadFilterTests[F] with AlternativeTests[F] {
def laws: MonadCombineLaws[F]

def monadCombine[A: Arbitrary: Eq, B: Arbitrary: Eq, C: Arbitrary: Eq](implicit
def monadCombine[A: Arbitrary: Cogen: Eq, B: Arbitrary: Cogen: Eq, C: Arbitrary: Cogen: Eq](implicit
ArbFA: Arbitrary[F[A]],
ArbFB: Arbitrary[F[B]],
ArbFC: Arbitrary[F[C]],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,20 @@ package discipline

import cats.data.{ Xor, XorT }
import cats.laws.discipline.CartesianTests.Isomorphisms
import org.scalacheck.{Arbitrary, Prop}
import org.scalacheck.{Arbitrary, Cogen, Prop}
import org.scalacheck.Prop.forAll

trait MonadErrorTests[F[_], E] extends ApplicativeErrorTests[F, E] with MonadTests[F] {
def laws: MonadErrorLaws[F, E]

def monadError[A: Arbitrary: Eq, B: Arbitrary: Eq, C: Arbitrary: Eq](implicit
def monadError[A: Arbitrary: Cogen: Eq, B: Arbitrary: Cogen: Eq, C: Arbitrary: Cogen: Eq](implicit
ArbFA: Arbitrary[F[A]],
ArbFB: Arbitrary[F[B]],
ArbFC: Arbitrary[F[C]],
ArbFAtoB: Arbitrary[F[A => B]],
ArbFBtoC: Arbitrary[F[B => C]],
ArbE: Arbitrary[E],
CogenE: Cogen[E],
EqFA: Eq[F[A]],
EqFB: Eq[F[B]],
EqFC: Eq[F[C]],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ package laws
package discipline

import cats.laws.discipline.CartesianTests.Isomorphisms
import org.scalacheck.Arbitrary
import org.scalacheck.Prop
import org.scalacheck.{Arbitrary, Cogen, Prop}
import Prop._

trait MonadFilterTests[F[_]] extends MonadTests[F] {
def laws: MonadFilterLaws[F]

def monadFilter[A: Arbitrary: Eq, B: Arbitrary: Eq, C: Arbitrary: Eq](implicit
def monadFilter[A: Arbitrary: Cogen: Eq, B: Arbitrary: Cogen: Eq, C: Arbitrary: Cogen: Eq](implicit
ArbFA: Arbitrary[F[A]],
ArbFB: Arbitrary[F[B]],
ArbFC: Arbitrary[F[C]],
Expand Down
Loading

0 comments on commit d082fea

Please sign in to comment.