Skip to content

Commit

Permalink
establish Scalacheck 1.11 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
larsrh committed Nov 24, 2013
1 parent b328ea8 commit 11a11d0
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 32 deletions.
Expand Up @@ -13,18 +13,12 @@ object ScalaCheckBinding {
def bind[A, B](fa: Arbitrary[A])(f: A => Arbitrary[B]) = Arbitrary(fa.arbitrary.flatMap(f(_).arbitrary))
def point[A](a: => A) = Arbitrary(sized(_ => value(a)))
override def map[A, B](fa: Arbitrary[A])(f: A => B) = Arbitrary(fa.arbitrary.map(f))
override def ap[A, B](fa: => Arbitrary[A])(f: => Arbitrary[A => B]) = Arbitrary(fa.arbitrary.ap(f.arbitrary))
}

implicit val GenMonad: Monad[Gen] = new Monad[Gen] {
def point[A](a: => A) = sized(_ => value(a))
override def ap[A, B](fa: => Gen[A])(f: => Gen[A => B]) = fa ap f
def bind[A, B](fa: Gen[A])(f: A => Gen[B]) = fa flatMap f
override def map[A, B](fa: Gen[A])(f: A => B) = fa map f
override def apply2[A, B, C](fa: => Gen[A], fb: => Gen[B])(f: (A, B) => C) = fa.map2(fb)(f)
override def apply3[A, B, C, D](fa: => Gen[A], fb: => Gen[B], fc: => Gen[C])(f: (A, B, C) => D) = fa.map3(fb, fc)(f)
override def apply4[A, B, C, D, E](fa: => Gen[A], fb: => Gen[B], fc: => Gen[C], fd: => Gen[D])(f: (A, B, C, D) => E) = fa.map4(fb, fc, fd)(f)
override def apply5[A, B, C, D, E, R](fa: => Gen[A], fb: => Gen[B], fc: => Gen[C], fd: => Gen[D], fe: => Gen[E])(f: (A, B, C, D, E) => R) = fa.map5(fb, fc, fd, fe)(f)
}
}

Expand Down
Expand Up @@ -2,7 +2,7 @@ package scalaz
package scalacheck

import java.math.BigInteger
import org.scalacheck.{Pretty, Gen, Arbitrary}
import org.scalacheck.{Gen, Arbitrary}
import java.io._
import collection.mutable.ArraySeq

Expand All @@ -24,15 +24,15 @@ object ScalazArbitrary {
/** @since 7.0.3 */
implicit def theseArb[A: Arbitrary, B: Arbitrary]: Arbitrary[A \&/ B] =
Arbitrary(Gen.oneOf(
arbitrary[A].map2(arbitrary[B])(\&/.Both(_, _)),
arbitrary[A].map(\&/.This(_)),
arbitrary[B].map(\&/.That(_))
^(arbitrary[A], arbitrary[B])(\&/.Both(_, _)),
arbitrary[A].map(a => \&/.This[A, B](a)),
arbitrary[B].map(b => \&/.That[A, B](b))
))

implicit def arbList[T](implicit a: Arbitrary[T]): Arbitrary[List[T]] = Arbitrary(containerOf[List,T](arbitrary[T]))

implicit def ImmutableArrayArbitrary[A : Arbitrary : ClassManifest] =
Functor[Arbitrary].map(arbArray[A])(ImmutableArray.fromArray[A](_))
Functor[Arbitrary].map(arb[Array[A]])(ImmutableArray.fromArray[A](_))

implicit def ValueArbitrary[A](implicit fa: Arbitrary[A]): Arbitrary[Value[A]] = Functor[Arbitrary].map(fa)(a => Value(a))
implicit def NameArbitrary[A](implicit fa: Arbitrary[A]): Arbitrary[Name[A]] = Functor[Arbitrary].map(fa)(a => Name(a))
Expand Down Expand Up @@ -157,14 +157,14 @@ object ScalazArbitrary {

implicit def FingerArbitrary[V, A](implicit a: Arbitrary[A], measure: Reducer[A, V]): Arbitrary[Finger[V, A]] = Arbitrary(oneOf(
arbitrary[A].map(one(_): Finger[V, A]),
arbitrary[A].map2(arbitrary[A])(two(_, _): Finger[V, A]),
arbitrary[A].map3(arbitrary[A], arbitrary[A])(three(_, _, _): Finger[V, A]),
arbitrary[A].map4(arbitrary[A], arbitrary[A], arbitrary[A])(four(_, _, _, _): Finger[V, A])
^(arbitrary[A], arbitrary[A])(two(_, _): Finger[V, A]),
^^(arbitrary[A], arbitrary[A], arbitrary[A])(three(_, _, _): Finger[V, A]),
^^^(arbitrary[A], arbitrary[A], arbitrary[A], arbitrary[A])(four(_, _, _, _): Finger[V, A])
))

implicit def NodeArbitrary[V, A](implicit a: Arbitrary[A], measure: Reducer[A, V]): Arbitrary[Node[V, A]] = Arbitrary(oneOf(
arbitrary[A].map2(arbitrary[A])((a, b) => node2[V, A](a, b)),
arbitrary[A].map3(arbitrary[A], arbitrary[A])((a, b, c) => node3[V, A](a, b, c))
^(arbitrary[A], arbitrary[A])(node2[V, A](_, _)),
^^(arbitrary[A], arbitrary[A], arbitrary[A])(node3[V, A](_, _, _))
))

implicit def FingerTreeArbitrary[V, A](implicit a: Arbitrary[A], measure: Reducer[A, V]): Arbitrary[FingerTree[V, A]] = Arbitrary {
Expand All @@ -173,7 +173,10 @@ object ScalazArbitrary {
case 1 => arbitrary[A].map(single[V, A](_))
case n => {
val nextSize = n.abs / 2
arbitrary[Finger[V, A]].map3(fingerTree[Node[V, A]](nextSize), arbitrary[Finger[V, A]])(deep[V, A](_, _, _))
^^(FingerArbitrary[V, A].arbitrary,
fingerTree[Node[V, A]](nextSize)(NodeArbitrary[V, A], implicitly),
FingerArbitrary[V, A].arbitrary
)(deep[V, A](_, _, _))
}
}
Gen.sized(fingerTree[A] _)
Expand Down Expand Up @@ -356,7 +359,7 @@ object ScalazArbitrary {
arbitrary[Int].map(n => nthChildOp(n)),
^(arbitrary[Cursor => Cursor], arbitrary[OpDescription])(succeedingOp),
^(arbitrary[Cursor => Option[Cursor]], arbitrary[OpDescription])(genericOp),
failedComposeOp, leftOp, rightOp, firstChildOp, lastChildOp, remove, removeLeftOp, removeRightOp, parentOp, rootOp, nextDepthFirstOp
oneOf(failedComposeOp, leftOp, rightOp, firstChildOp, lastChildOp, remove, removeLeftOp, removeRightOp, parentOp, rootOp, nextDepthFirstOp)
))
}

Expand All @@ -369,8 +372,8 @@ object ScalazArbitrary {
implicit def iterateeInputArbitrary[A: Arbitrary]: Arbitrary[scalaz.iteratee.Input[A]] = {
import scalaz.iteratee.Input._
Arbitrary(Gen.oneOf(
emptyInput[A],
eofInput[A],
Gen.value(emptyInput[A]),
Gen.value(eofInput[A]),
arbitrary[A].map(e => elInput(e))
))
}
Expand Down
4 changes: 2 additions & 2 deletions tests/src/test/scala/scalaz/FingerTreeTest.scala
@@ -1,7 +1,7 @@
package scalaz

import org.scalacheck.Prop.{extendedAny => _, _}
import FingerTree._
import org.scalacheck.Prop.forAll
import scalacheck.ScalazArbitrary._
import std.anyVal._
import std.stream._
Expand Down Expand Up @@ -95,7 +95,7 @@ object FingerTreeTest extends SpecLite {
}

"OrdSeq is ordered" ! forAll { xs: List[Int] => OrdSeq(xs:_*).toList == xs.sorted }

"IndSeq" should {
import org.scalacheck._
import Gen._
Expand Down
7 changes: 3 additions & 4 deletions tests/src/test/scala/scalaz/SpecLite.scala
@@ -1,7 +1,7 @@
package scalaz

import org.scalacheck._
import org.scalacheck.Prop.{Result, Params}
import org.scalacheck.Prop.Result

abstract class SpecLite extends Properties("") {
def updateName: Unit = {
Expand Down Expand Up @@ -39,9 +39,8 @@ abstract class SpecLite extends Properties("") {
context = s; try a finally context = saved
}
def ![A](a: => A)(implicit ev: (A) => Prop): Unit = in(a)
def in[A](a: => A)(implicit ev: (A) => Prop): Unit = property(context + ":" + s) = new Prop {
def apply(prms: Params): Result = ev(a).apply(prms) // TODO sort out the laziness / implicit conversions properly
}
def in[A](a: => A)(implicit ev: (A) => Prop): Unit =
property(context + ":" + s) = Prop(prms => ev(a).apply(prms)) // TODO sort out the laziness / implicit conversions properly
}

implicit def enrichString(s: String) = new StringOps(s)
Expand Down
8 changes: 4 additions & 4 deletions tests/src/test/scala/scalaz/concurrent/PromiseTest.scala
Expand Up @@ -15,8 +15,8 @@ object PromiseTest extends SpecLite {
checkAll(traverse.laws[Promise])
checkAll(comonad.laws[Promise])

"throw" ! (throws(Promise({throw new Error("x"); 1}).flatMap(_ => Promise(2)).get, classOf[Error]))
"filter broken" ! (throws(Promise(0).filter(_ != 0).get, classOf[Promise.BrokenException]))
"throw" ! (throws(classOf[Error])(Promise({throw new Error("x"); 1}).flatMap(_ => Promise(2)).get))
"filter broken" ! (throws(classOf[Promise.BrokenException])(Promise(0).filter(_ != 0).get))
"filter" ! (forAll((x: Int) => Promise(x).filter(_ => true).get must_=== x))

class OhNo extends RuntimeException("OhNo!")
Expand All @@ -25,12 +25,12 @@ object PromiseTest extends SpecLite {
import Scalaz._
"not hang when an error occurs in sequence" in {
withTimeout(2000) {
throws(List(Promise({ throw new OhNo(); 1 })).sequence.get, classOf[OhNo])
throws(classOf[OhNo])(List(Promise({ throw new OhNo(); 1 })).sequence.get)
}
}
"not hang when an error occurs on filter" in {
withTimeout(2000) {
throws(Promise({ throw new OhNo(); 2 }).filter(_ > 2).get, classOf[OhNo])
throws(classOf[OhNo])(Promise({ throw new OhNo(); 2 }).filter(_ > 2).get)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/src/test/scala/scalaz/iteratee/EnumeratorPTest.scala
Expand Up @@ -6,7 +6,7 @@ import Either3._
import Iteratee._
import effect._

import org.scalacheck.{Pretty, Gen, Arbitrary}
import org.scalacheck.{Gen, Arbitrary}
import Arbitrary._
import Gen._
import syntax.functor._
Expand Down
2 changes: 1 addition & 1 deletion tests/src/test/scala/scalaz/iteratee/EnumeratorTTest.scala
Expand Up @@ -5,7 +5,7 @@ import std.AllInstances._
import Iteratee._
import effect._

import org.scalacheck.{Pretty, Gen, Arbitrary}
import org.scalacheck.{Gen, Arbitrary}
import Arbitrary._
import Gen._
import syntax.functor._
Expand Down

0 comments on commit 11a11d0

Please sign in to comment.