-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Improve performance of arbitraries (#207)
- Loading branch information
Showing
6 changed files
with
53 additions
and
9 deletions.
There are no files selected for viewing
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
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
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
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
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
9 changes: 5 additions & 4 deletions
9
scalacheck/test/src/io/github/iltotore/iron/scalacheck/package.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 |
---|---|---|
@@ -1,18 +1,19 @@ | ||
package io.github.iltotore.iron.scalacheck | ||
|
||
import io.github.iltotore.iron.{:|, Constraint} | ||
import org.scalacheck.Test.Parameters | ||
import org.scalacheck.{Arbitrary, Prop, Test} | ||
import utest.* | ||
|
||
inline def testGen[A, C](using inline arb: Arbitrary[A :| C], inline constraint: Constraint[A, C]): Unit = | ||
|
||
def getTestValues(args: List[Prop.Arg[Any]]): List[TestValue] = | ||
args.zipWithIndex.map((arg, i) => TestValue(if arg.label.isBlank then s"value$i" else arg.label, "T", arg.arg)) | ||
|
||
Test.check(Prop.forAll(arb.arbitrary)(constraint.test(_)))(p => p).status match | ||
case Test.Passed | Test.Proved(_) => | ||
val result = Test.check(Prop.forAll(arb.arbitrary)(constraint.test(_)))(p => p) | ||
result.status match | ||
case Test.Passed | Test.Proved(_) => assert(result.discarded == 0) | ||
case Test.Failed(args, _) => | ||
throw AssertionError(s"Some constrained values failed for ${constraint.message}", getTestValues(args)) | ||
case Test.Exhausted => new java.lang.AssertionError("Exhausted") | ||
case Test.Exhausted => throw new java.lang.AssertionError("Exhausted") | ||
case Test.PropException(args, e, _) => | ||
throw AssertionError(s"An error occurred for ${constraint.message}", getTestValues(args), e) |