Skip to content

Commit

Permalink
fix the test case generation via Arbitrary[PositionName]
Browse files Browse the repository at this point in the history
  • Loading branch information
vreuter committed Oct 14, 2024
1 parent ba9ca3a commit fdb7c66
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
12 changes: 7 additions & 5 deletions modules/imaging/src/test/scala/TestImagingInstances.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ class TestImagingInstances
PropertyCheckConfiguration(minSuccessful = 10000)

given Arbitrary[PositionName] =
import io.github.iltotore.iron.autoRefine
type GoodChar = Char :| PositionNameCharacterConstraint
val goodPunctuation: Set[GoodChar] = Set('-', '.', '_')
val goodPunctuation: Set[GoodChar] = {
import io.github.iltotore.iron.autoRefine
Set('-', '.', '_')
}
def genPunct: Gen[GoodChar] = Gen.oneOf(goodPunctuation)
def genPosNameChar: Gen[GoodChar] = Gen.oneOf(
Arbitrary.arbitrary[Char :| Letter].map(_.asInstanceOf[GoodChar]),
Expand All @@ -44,13 +46,13 @@ class TestImagingInstances
case Nil =>
!(
// Check that the string doesn't encode an integer or decimal.
!raw"-?[0-9]+".r.matches(s) ||
!raw"-?[0-9]+\\.?[0-9]*".r.matches(s)
raw"-?[0-9]+".r.matches(s) ||
raw"-?[0-9]+\.[0-9]+".r.matches(s)
)
case 'E' :: Nil =>
!(
// Check that the string isn't a scientific notation.
raw"-?[0-9]\\.[0-9]+E-?[0-9]{1,3}".r.matches(s) ||
raw"-?[0-9]\.[0-9]+E-?[0-9]{1,3}".r.matches(s) ||
raw"-?[0-9]E-?[0-9]{1,3}".r.matches(s)
)
case _ => true
Expand Down
12 changes: 7 additions & 5 deletions modules/testing/src/main/scala/instances/ImagingInstances.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ trait ImagingInstances extends CatsScalacheckInstances:
Arbitrary[Char :| Letter],
Arbitrary[Char :| Digit]
): Arbitrary[PositionName] =
import io.github.iltotore.iron.autoRefine
type GoodChar = Char :| PositionNameCharacterConstraint
val goodPunctuation: Set[GoodChar] = Set('-', '.', '_')
val goodPunctuation: Set[GoodChar] = {
import io.github.iltotore.iron.autoRefine
Set('-', '.', '_')
}
def genPunct: Gen[GoodChar] = Gen.oneOf(goodPunctuation)
def genPosNameChar: Gen[GoodChar] = Gen.oneOf(
Arbitrary.arbitrary[Char :| Letter].map(_.asInstanceOf[GoodChar]),
Expand All @@ -43,13 +45,13 @@ trait ImagingInstances extends CatsScalacheckInstances:
case Nil =>
!(
// Check that the string doesn't encode an integer or decimal.
!raw"-?[0-9]+".r.matches(s) ||
!raw"-?[0-9]+\\.?[0-9]*".r.matches(s)
raw"-?[0-9]+".r.matches(s) ||
raw"-?[0-9]+\.[0-9]+".r.matches(s)
)
case 'E' :: Nil =>
!(
// Check that the string isn't a scientific notation.
raw"-?[0-9]\\.[0-9]+E-?[0-9]{1,3}".r.matches(s) ||
raw"-?[0-9]\.[0-9]+E-?[0-9]{1,3}".r.matches(s) ||
raw"-?[0-9]E-?[0-9]{1,3}".r.matches(s)
)
case _ => true
Expand Down

0 comments on commit fdb7c66

Please sign in to comment.