Skip to content

Commit

Permalink
[scalacheck] Use isDefined ==> in checks
Browse files Browse the repository at this point in the history
  • Loading branch information
fabianhjr committed Sep 17, 2023
1 parent d8d8a18 commit 6aca57d
Showing 1 changed file with 16 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -1,53 +1,48 @@
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
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
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
Expand Down

0 comments on commit 6aca57d

Please sign in to comment.