Skip to content

Commit

Permalink
proprification
Browse files Browse the repository at this point in the history
  • Loading branch information
jprudent committed Jan 31, 2024
1 parent 8140efe commit 0e1b368
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 81 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ object collection:
*
* @tparam V the value the input must contain.
*/
final class Contain[V]
final class Contain[V]

/**
* Tests if each element satisfies the given constraint.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,21 @@ import scala.compiletime.constValue

object collection:

inline given empty[A, CC[_]](using arbElem: Arbitrary[A], evb: Buildable[A, CC[A]], evt: CC[A] => Iterable[A]): Arbitrary[CC[A] :| Empty] = exactLength[A, CC, 0].asInstanceOf[ Arbitrary[CC[A] :| Empty]]
inline given empty[A, CC[_]](using arbElem: Arbitrary[A], evb: Buildable[A, CC[A]], evt: CC[A] => Iterable[A]): Arbitrary[CC[A] :| Empty] = exactLength[A, CC, 0].asInstanceOf

inline given exactLength[A, CC[_], V <: Int](using arbElem: Arbitrary[A], evb: Buildable[A, CC[A]], evt: CC[A] => Iterable[A]): Arbitrary[CC[A] :| FixedLength[V]] =
println("🥸 FixedLength")
Arbitrary(Gen.infiniteLazyList(arbElem.arbitrary).flatMap(ll => evb.fromIterable(ll.take(constValue[V])))).asInstanceOf[ Arbitrary[CC[A] :| FixedLength[V]]]
Arbitrary(Gen.infiniteLazyList(arbElem.arbitrary).flatMap(ll => evb.fromIterable(ll.take(constValue[V])))).asInstanceOf

inline given minLength[A, CC[_], V <: Int](using arbElem: Arbitrary[A], evb: Buildable[A,CC[A]], evt: CC[A] => Iterable[A]): Arbitrary[CC[A] :| MinLength[V]] =
println("🥸 minlength")
Arbitrary(
for
prefix <- Gen.infiniteLazyList(arbElem.arbitrary)
postfix <- Gen.listOf(arbElem.arbitrary)
yield
evb.fromIterable(prefix.take(constValue[V]) ++ postfix)
).asInstanceOf[Arbitrary[CC[A] :| MinLength[V]]]
).asInstanceOf

inline given maxLength[A, CC[_], V <: Int](using arbElem: Arbitrary[A], evb: Buildable[A,CC[A]], evt: CC[A] => Iterable[A]): Arbitrary[CC[A] :| MaxLength[V]] =
println("🥸 max length")
Arbitrary(Gen.containerOf(arbElem.arbitrary).flatMap(cc => Gen.const(evt(cc).take(constValue[V])))).asInstanceOf[Arbitrary[CC[A] :| MaxLength[V]]]

inline given length[A, CC[_], C](using arbLength: Arbitrary[Int :| C], arbElem: Arbitrary[A], evb: Buildable[A,CC[A]], evt: CC[A] => Iterable[A]): Arbitrary[CC[A] :| Length[C]] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import utest.*
object AnySuite extends TestSuite:

val tests: Tests = Tests {
test("fallback") - testGen[Boolean, StrictEqual[true]]()
test("fallback") - testGen[Boolean, StrictEqual[true]]

test("union") - testGen[Int, StrictEqual[1] | StrictEqual[2] | StrictEqual[3]]()
test("union") - testGen[Int, StrictEqual[1] | StrictEqual[2] | StrictEqual[3]]
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ object CharSuite extends TestSuite:

val tests: Tests = Tests {

test("whitespace") - testGen[Char, Whitespace]()
test("whitespace") - testGen[Char, Whitespace]

test("lowercase") - testGen[Char, LowerCase]()
test("lowercase") - testGen[Char, LowerCase]

test("uppercase") - testGen[Char, UpperCase]()
test("uppercase") - testGen[Char, UpperCase]

test("digit") - testGen[Char, Digit]()
test("digit") - testGen[Char, Digit]

test("letter") - testGen[Char, Letter]()
test("letter") - testGen[Char, Letter]

test("special") - testGen[Char, Special]()
test("special") - testGen[Char, Special]
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,44 +11,44 @@ object CollectionSuite extends TestSuite:

val tests: Tests = Tests {
test("minLength") {
test("seq") - testGen[Seq[Boolean], MinLength[5]]()
test("string") - testGen[String, MinLength[5]](_.withMaxDiscardRatio(0.00001))
test("seq") - testGen[Seq[Boolean], MinLength[5]]
test("string") - testGen[String, MinLength[5]]
}
test("maxLength") {
test("seq") - testGen[Seq[Boolean], MaxLength[5]]()
test("string") - testGen[String, MaxLength[5]]()
test("seq") - testGen[Seq[Boolean], MaxLength[5]]
test("string") - testGen[String, MaxLength[5]]
}
test("exactLength") {
test("seq") - testGen[Seq[Boolean], FixedLength[5]]()
test("string") - testGen[String, FixedLength[5]]()
test("seq") - testGen[Seq[Boolean], FixedLength[5]]
test("string") - testGen[String, FixedLength[5]]
}
test("empty") {
test("seq") - testGen[Seq[Boolean], Empty]()
test("string") - testGen[String, Empty]()
test("not empty") - testGen[Seq[Boolean], Not[Empty]]()
test("seq") - testGen[Seq[Boolean], Empty]
test("string") - testGen[String, Empty]
test("not empty") - testGen[Seq[Boolean], Not[Empty]]
}
test("contain") {
test("seq") - testGen[Seq[Boolean], Contain[true]]()
test("string") - testGen[String, Contain["a"]]()
test("seq") - testGen[Seq[Boolean], Contain[true]]
test("string") - testGen[String, Contain["a"]]
}
test("forAll") {
test("seq") - testGen[Seq[Boolean], ForAll[StrictEqual[true]]]()
test("string") - testGen[String, ForAll[StrictEqual['a']]]()
test("seq") - testGen[Seq[Boolean], ForAll[StrictEqual[true]]]
test("string") - testGen[String, ForAll[StrictEqual['a']]]
}
test("init") {
test("seq") - testGen[Seq[Boolean], Init[StrictEqual[true]]]()
test("string") - testGen[String, Init[StrictEqual['a']]]()
test("seq") - testGen[Seq[Boolean], Init[StrictEqual[true]]]
test("string") - testGen[String, Init[StrictEqual['a']]]
}
test("tail") {
test("seq") - testGen[Seq[Boolean], Tail[StrictEqual[true]]]()
test("string") - testGen[String, Tail[StrictEqual['a']]]()
test("seq") - testGen[Seq[Boolean], Tail[StrictEqual[true]]]
test("string") - testGen[String, Tail[StrictEqual['a']]]
}
test("head") {
test("seq") - testGen[Seq[Boolean], Head[StrictEqual[true]]]()
test("string") - testGen[String, Head[StrictEqual['a']]]()
test("seq") - testGen[Seq[Boolean], Head[StrictEqual[true]]]
test("string") - testGen[String, Head[StrictEqual['a']]]
}
test("last") {
test("seq") - testGen[Seq[Boolean], Last[StrictEqual[true]]]()
test("string") - testGen[String, Last[StrictEqual['a']]]()
test("seq") - testGen[Seq[Boolean], Last[StrictEqual[true]]]
test("string") - testGen[String, Last[StrictEqual['a']]]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ import utest.*
object ImplicitsOrderingSuite extends TestSuite:

val tests: Tests = Tests {
test("should resolve implicits using all.given import") - testGen[String, Empty]()
test("should resolve implicits using all.given import") - testGen[String, Empty]
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,67 +12,67 @@ object NumericSuite extends TestSuite:
val tests: Tests = Tests {

test("greater") {
test("int") - testGen[Int, Greater[5]]()
test("long") - testGen[Long, Greater[5L]]()
test("float") - testGen[Float, Greater[5f]]()
test("double") - testGen[Double, Greater[5d]]()
test("int") - testGen[Int, Greater[5]]
test("long") - testGen[Long, Greater[5L]]
test("float") - testGen[Float, Greater[5f]]
test("double") - testGen[Double, Greater[5d]]
}

test("greaterEqual") {
test("int") - testGen[Int, GreaterEqual[5]]()
test("long") - testGen[Long, GreaterEqual[5L]]()
test("float") - testGen[Float, GreaterEqual[5f]]()
test("double") - testGen[Double, GreaterEqual[5d]]()
test("int") - testGen[Int, GreaterEqual[5]]
test("long") - testGen[Long, GreaterEqual[5L]]
test("float") - testGen[Float, GreaterEqual[5f]]
test("double") - testGen[Double, GreaterEqual[5d]]
}

test("less") {
test("int") - testGen[Int, Less[5]]()
test("long") - testGen[Long, Less[5L]]()
test("float") - testGen[Float, Less[5f]]()
test("double") - testGen[Double, Less[5d]]()
test("int") - testGen[Int, Less[5]]
test("long") - testGen[Long, Less[5L]]
test("float") - testGen[Float, Less[5f]]
test("double") - testGen[Double, Less[5d]]
}

test("lessEqual") {
test("int") - testGen[Int, LessEqual[5]]()
test("long") - testGen[Long, LessEqual[5L]]()
test("float") - testGen[Float, LessEqual[5f]]()
test("double") - testGen[Double, LessEqual[5d]]()
test("int") - testGen[Int, LessEqual[5]]
test("long") - testGen[Long, LessEqual[5L]]
test("float") - testGen[Float, LessEqual[5f]]
test("double") - testGen[Double, LessEqual[5d]]
}

test("strictEqual") {
test("int") - testGen[Int, StrictEqual[5]]()
test("long") - testGen[Long, StrictEqual[5L]]()
test("float") - testGen[Float, StrictEqual[5f]]()
test("double") - testGen[Double, StrictEqual[5d]]()
test("int") - testGen[Int, StrictEqual[5]]
test("long") - testGen[Long, StrictEqual[5L]]
test("float") - testGen[Float, StrictEqual[5f]]
test("double") - testGen[Double, StrictEqual[5d]]
}

test("interval") {
test("open") {
test("int") - testGen[Int, Interval.Open[0, 5]]()
test("long") - testGen[Long, Interval.Open[0L, 5L]]()
test("float") - testGen[Float, Interval.Open[0f, 5f]]()
test("double") - testGen[Double, Interval.Open[0d, 5d]]()
test("int") - testGen[Int, Interval.Open[0, 5]]
test("long") - testGen[Long, Interval.Open[0L, 5L]]
test("float") - testGen[Float, Interval.Open[0f, 5f]]
test("double") - testGen[Double, Interval.Open[0d, 5d]]
}

test("openClosed") {
test("int") - testGen[Int, Interval.OpenClosed[0, 5]]()
test("long") - testGen[Long, Interval.OpenClosed[0L, 5L]]()
test("float") - testGen[Float, Interval.OpenClosed[0f, 5f]]()
test("double") - testGen[Double, Interval.OpenClosed[0d, 5d]]()
test("int") - testGen[Int, Interval.OpenClosed[0, 5]]
test("long") - testGen[Long, Interval.OpenClosed[0L, 5L]]
test("float") - testGen[Float, Interval.OpenClosed[0f, 5f]]
test("double") - testGen[Double, Interval.OpenClosed[0d, 5d]]
}

test("closedOpen") {
test("int") - testGen[Int, Interval.ClosedOpen[0, 5]]()
test("long") - testGen[Long, Interval.ClosedOpen[0L, 5L]]()
test("float") - testGen[Float, Interval.ClosedOpen[0f, 5f]]()
test("double") - testGen[Double, Interval.ClosedOpen[0d, 5d]]()
test("int") - testGen[Int, Interval.ClosedOpen[0, 5]]
test("long") - testGen[Long, Interval.ClosedOpen[0L, 5L]]
test("float") - testGen[Float, Interval.ClosedOpen[0f, 5f]]
test("double") - testGen[Double, Interval.ClosedOpen[0d, 5d]]
}

test("closed") {
test("int") - testGen[Int, Interval.Closed[0, 5]]()
test("long") - testGen[Long, Interval.Closed[0L, 5L]]()
test("float") - testGen[Float, Interval.Closed[0f, 5f]]()
test("double") - testGen[Double, Interval.Closed[0d, 5d]]()
test("int") - testGen[Int, Interval.Closed[0, 5]]
test("long") - testGen[Long, Interval.Closed[0L, 5L]]
test("float") - testGen[Float, Interval.Closed[0f, 5f]]
test("double") - testGen[Double, Interval.Closed[0d, 5d]]
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import utest.*
object StringSuite extends TestSuite:

val tests: Tests = Tests {
test("startWith") - testGen[String, StartWith["abc"]]()
test("endWith") - testGen[String, EndWith["abc"]]()
test("not empty string") - testGen[String, Not[Empty]]()
test("startWith") - testGen[String, StartWith["abc"]]
test("endWith") - testGen[String, EndWith["abc"]]
test("not empty string") - testGen[String, Not[Empty]]
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,11 @@ import org.scalacheck.Test.Parameters
import org.scalacheck.{Arbitrary, Prop, Test}
import utest.*

// todo remove parameters
inline def testGen[A, C](parameters: Parameters => Parameters = p => p)(using inline arb: Arbitrary[A :| C], inline constraint: Constraint[A, C]): Unit =
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))

val result = Test.check(Prop.forAll(arb.arbitrary) { v =>
constraint.test(v)
})(parameters)
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, _) =>
Expand Down

0 comments on commit 0e1b368

Please sign in to comment.