-
Notifications
You must be signed in to change notification settings - Fork 155
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #170 from fthomas/topic/EqualArbitrary
Add Arbitrary instance for Equal
- Loading branch information
Showing
4 changed files
with
36 additions
and
0 deletions.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
contrib/scalacheck/shared/src/main/scala/eu/timepit/refined/scalacheck/generic.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package eu.timepit.refined | ||
package scalacheck | ||
|
||
import eu.timepit.refined.api.RefType | ||
import eu.timepit.refined.generic.Equal | ||
import org.scalacheck.{ Arbitrary, Gen } | ||
import shapeless.Witness | ||
|
||
/** Module that provides `Arbitrary` instances for generic predicates. */ | ||
object generic { | ||
|
||
implicit def equalArbitrary[F[_, _]: RefType, T, U <: T]( | ||
implicit | ||
wu: Witness.Aux[U] | ||
): Arbitrary[F[T, Equal[U]]] = | ||
arbitraryRefType(Gen.const(wu.value)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
...scalacheck/shared/src/test/scala/eu/timepit/refined/scalacheck/GenericArbitrarySpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package eu.timepit.refined | ||
package scalacheck | ||
|
||
import eu.timepit.refined.api.Refined | ||
import eu.timepit.refined.generic.Equal | ||
import eu.timepit.refined.scalacheck.generic._ | ||
import org.scalacheck.Properties | ||
|
||
class GenericArbitrarySpec extends Properties("GenericArbitrary") { | ||
|
||
property("Equal") = | ||
checkArbitraryRefType[Refined, Int, Equal[W.`100`.T]] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters