Skip to content

Commit

Permalink
[scalatest] Allow passing PropertyCheckConfigParams*
Browse files Browse the repository at this point in the history
  • Loading branch information
fabianhjr committed Sep 27, 2023
1 parent 3fc01ee commit 27d91d5
Showing 1 changed file with 21 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,61 +9,61 @@ import org.scalatest.matchers.should.Matchers.*
import org.scalatestplus.scalacheck.ScalaCheckPropertyChecks.*

extension [A, B](mapBijection: MapBijection[A, B])
def checkForward(using Arbitrary[A]): Assertion =
forAll[A, Assertion] { case a: A =>
def checkForward(configs: PropertyCheckConfigParam*)(using Arbitrary[A]): Assertion =
forAll[A, Assertion](summon[Arbitrary[A]].arbitrary, configs*) { case a: A =>
whenever(mapBijection.isDefined(a)) {
// Self Inverse
mapBijection(a).flatMap(mapBijection.reverse(_)) should contain(a)
}
}

def checkReverse(using Arbitrary[B]): Assertion =
mapBijection.flip.checkForward
def checkReverse(configs: PropertyCheckConfigParam*)(using Arbitrary[B]): Assertion =
mapBijection.flip.checkForward(configs*)

@SuppressWarnings(Array("org.wartremover.warts.TryPartial"))
def check(using Arbitrary[A], Arbitrary[B]): Assertion =
def check(configs: PropertyCheckConfigParam*)(using Arbitrary[A], Arbitrary[B]): Assertion =
(for
Succeeded <- Try(checkForward)
Succeeded <- Try(checkReverse)
Succeeded <- Try(checkForward(configs*))
Succeeded <- Try(checkReverse(configs*))
yield Succeeded).get
end extension

extension [A, B](pfnBijection: PFnBijection[A, B])
def checkForward(using Arbitrary[A]): Assertion =
forAll[A, Assertion] { case a: A =>
def checkForward(configs: PropertyCheckConfigParam*)(using Arbitrary[A]): Assertion =
forAll[A, Assertion](summon[Arbitrary[A]].arbitrary, configs*) { case a: A =>
whenever(pfnBijection.isDefined(a)) {
// Self Inverse
pfnBijection(a).flatMap(pfnBijection.reverse(_)) should contain(a)
}
}

def checkReverse(using Arbitrary[B]): Assertion =
pfnBijection.flip.checkForward
def checkReverse(configs: PropertyCheckConfigParam*)(using Arbitrary[B]): Assertion =
pfnBijection.flip.checkForward(configs*)

@SuppressWarnings(Array("org.wartremover.warts.TryPartial"))
def check(using Arbitrary[A], Arbitrary[B]): Assertion =
def check(configs: PropertyCheckConfigParam*)(using Arbitrary[A], Arbitrary[B]): Assertion =
(for
Succeeded <- Try(checkForward)
Succeeded <- Try(checkReverse)
Succeeded <- Try(checkForward(configs*))
Succeeded <- Try(checkReverse(configs*))
yield Succeeded).get
end extension

extension [A, B](fnBijection: FnBijection[A, B])
def checkForward(using Arbitrary[A]): Assertion =
forAll[A, Assertion] { case a: A =>
def checkForward(configs: PropertyCheckConfigParam*)(using Arbitrary[A]): Assertion =
forAll[A, Assertion](summon[Arbitrary[A]].arbitrary, configs*) { case a: A =>
whenever(fnBijection.isDefined(a)) {
// Self Inverse
fnBijection.reverse(fnBijection(a)) shouldBe a
}
}

def checkReverse(using Arbitrary[B]): Assertion =
fnBijection.flip.checkForward
def checkReverse(configs: PropertyCheckConfigParam*)(using Arbitrary[B]): Assertion =
fnBijection.flip.checkForward(configs*)

@SuppressWarnings(Array("org.wartremover.warts.TryPartial"))
def check(using Arbitrary[A], Arbitrary[B]): Assertion =
def check(configs: PropertyCheckConfigParam*)(using Arbitrary[A], Arbitrary[B]): Assertion =
(for
Succeeded <- Try(checkForward)
Succeeded <- Try(checkReverse)
Succeeded <- Try(checkForward(configs*))
Succeeded <- Try(checkReverse(configs*))
yield Succeeded).get
end extension

0 comments on commit 27d91d5

Please sign in to comment.