diff --git a/scalacheck/src/main/scala/dev/librecybernetics/data/BijectionScalacheckExtensions.scala b/scalacheck/src/main/scala/dev/librecybernetics/data/BijectionScalacheckExtensions.scala index 09c3cd9..06a972d 100644 --- a/scalacheck/src/main/scala/dev/librecybernetics/data/BijectionScalacheckExtensions.scala +++ b/scalacheck/src/main/scala/dev/librecybernetics/data/BijectionScalacheckExtensions.scala @@ -1,19 +1,18 @@ package dev.librecybernetics.data import org.scalacheck.{Arbitrary, Prop} +import org.scalacheck.Prop.{forAll, propBoolean} extension [A, B](mapBijection: MapBijection[A, B]) def checkForward(using Arbitrary[A]): Prop = - Prop.forAll[A, Boolean] { case a: A => - // Self Inverse - mapBijection(a).flatMap(mapBijection.reverse(_)).contains(a) + forAll[A, Prop] { case a: A => + mapBijection.isDefined(a) ==> + // Self Inverse + mapBijection(a).flatMap(mapBijection.reverse(_)).contains(a) } def checkReverse(using Arbitrary[B]): Prop = - Prop.forAll[B, Boolean] { case b: B => - // Self Inverse - mapBijection.reverse(b).flatMap(mapBijection(_)).contains(b) - } + mapBijection.flip.checkForward def check(using Arbitrary[A], Arbitrary[B]): Prop = checkReverse && checkForward @@ -21,16 +20,14 @@ end extension extension [A, B](pfnBijection: PFnBijection[A, B]) def checkForward(using Arbitrary[A]): Prop = - Prop.forAll[A, Boolean] { case a: A => - // Self Inverse - pfnBijection(a).flatMap(pfnBijection.reverse(_)).contains(a) + forAll[A, Prop] { case a: A => + pfnBijection.isDefined(a) ==> + // Self Inverse + pfnBijection(a).flatMap(pfnBijection.reverse(_)).contains(a) } def checkReverse(using Arbitrary[B]): Prop = - Prop.forAll[B, Boolean] { case b: B => - // Self Inverse - pfnBijection.reverse(b).flatMap(pfnBijection(_)).contains(b) - } + pfnBijection.flip.checkForward def check(using Arbitrary[A], Arbitrary[B]): Prop = checkReverse && checkForward @@ -38,16 +35,14 @@ end extension extension [A, B](fnBijection: FnBijection[A, B]) def checkForward(using Arbitrary[A]): Prop = - Prop.forAll[A, Boolean] { case a: A => - // Self Inverse - fnBijection.reverse(fnBijection(a)) == a + forAll[A, Prop] { case a: A => + fnBijection.isDefined(a) ==> + // Self Inverse + (fnBijection.reverse(fnBijection(a)) == a) } def checkReverse(using Arbitrary[B]): Prop = - Prop.forAll[B, Boolean] { case b: B => - // Self Inverse - fnBijection(fnBijection.reverse(b)) == b - } + fnBijection.flip.checkForward def check(using Arbitrary[A], Arbitrary[B]): Prop = checkReverse && checkForward