Skip to content

Commit

Permalink
Added types from #7
Browse files Browse the repository at this point in the history
More careful look at the generated type classes needed
  • Loading branch information
alexarchambault committed May 26, 2015
1 parent 240c6e7 commit 891440d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/test/scala/org/scalacheck/Definitions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,18 @@ object Definitions {
/*final class Bar extends Foo
final class Baz(i1: Int)(s1: String) extends Foo*/

object ImageSize extends Enumeration {
type ImageSize = Value
val small, medium, large, extralarge = Value

// This one seems to be required:
implicit def imageSizeArbitrary: Arbitrary[ImageSize] =
Arbitrary(Gen.oneOf(values.toSeq))
// but not this one:
// implicit def imageSizeShrink: Shrink[ImageSize] = ???
}

case class Image(size: ImageSize.ImageSize)
}

// Proxied type classes
Expand All @@ -78,6 +90,8 @@ object Instances {
implicit def aArbitrary: Arbitrary[A] = cachedImplicit
implicit def dArbitrary: Arbitrary[D] = cachedImplicit

implicit def imageArbitrary: Arbitrary[Image] = cachedImplicit

implicit def t1Shrink: Shrink[T1.Tree] = cachedImplicit
implicit def t2Shrink: Shrink[T2.Tree] = cachedImplicit

Expand All @@ -91,4 +105,7 @@ object Instances {
implicit def baseShrink: Shrink[Base] = cachedImplicit
implicit def aShrink: Shrink[A] = cachedImplicit
implicit def dShrink: Shrink[D] = cachedImplicit

implicit def imageShrink: Shrink[Image] = cachedImplicit

}
4 changes: 4 additions & 0 deletions src/test/scala/org/scalacheck/Tests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ object Tests extends Properties("Tests") {
illTyped(" implicitly[Arbitrary[NoArbitraryType]] ")
illTyped(" implicitly[Arbitrary[ShouldHaveNoArb]] ")

property("type with enumeration") = {
Prop.forAll(Arbitrary.arbitrary[Image])(ok)
}


// These two make scalac almost diverge, especially the first one.
// The few times I saw one of them converge, the result was the one I expected though.
Expand Down

0 comments on commit 891440d

Please sign in to comment.