From 6aca57df3a0bf27e81456092bc688f299d08e743 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabi=C3=A1n=20Heredia=20Montiel?= Date: Sat, 16 Sep 2023 19:16:22 -0600 Subject: [PATCH] [scalacheck] Use `isDefined ==>` in checks --- .../data/BijectionScalacheckExtensions.scala | 37 ++++++++----------- 1 file changed, 16 insertions(+), 21 deletions(-) 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