Compare commits
1 commit
65b3a0d0a9
...
86af4d18b8
Author | SHA1 | Date | |
---|---|---|---|
86af4d18b8 |
4 changed files with 70 additions and 2 deletions
|
@ -1,4 +1,4 @@
|
|||
val scala3: String = "3.7.1"
|
||||
val scala3: String = "3.7.2"
|
||||
|
||||
ThisBuild / scalaVersion := scala3
|
||||
ThisBuild / versionScheme := Some("semver-spec")
|
||||
|
|
|
@ -13,6 +13,15 @@ abstract class Datagen[A, -I]:
|
|||
*/
|
||||
def generate(input: I): A
|
||||
|
||||
/** Convert this to a `Gen[A]` using the supplied input.
|
||||
*
|
||||
* @param input
|
||||
* The input that must always be applied.
|
||||
* @return
|
||||
* The new generator that does not require input.
|
||||
*/
|
||||
def toGen(input: I): Gen[A] = (_: Any) => this.generate(input)
|
||||
|
||||
def flatMap[B, I2 <: I](f: A => Datagen[B, I2]): Datagen[B, I2] =
|
||||
new Datagen.Defer[B, I2](input => f(generate(input)).generate(input))
|
||||
|
||||
|
|
|
@ -158,6 +158,35 @@ object Gen:
|
|||
gen: Gen[A]
|
||||
): Gen[List[A]] = new GenList[A](size, gen)
|
||||
|
||||
/** Generator for a list of some fixed size based on a generator for the list
|
||||
* elements.
|
||||
*
|
||||
* @param fixedSize
|
||||
* The [[gs.datagen.v0.generators.Size]] of the list.
|
||||
* @param gen
|
||||
* The generator for the list elements.
|
||||
*/
|
||||
def list[A](
|
||||
fixedSize: Int,
|
||||
gen: Gen[A]
|
||||
): Gen[List[A]] = new GenList[A](Size.Fixed(fixedSize), gen)
|
||||
|
||||
/** Generator for a list of some size based on a generator for the list
|
||||
* elements.
|
||||
*
|
||||
* @param minSize
|
||||
* The minimum size of the list.
|
||||
* @param maxSize
|
||||
* The maximum size of the list.
|
||||
* @param gen
|
||||
* The generator for the list elements.
|
||||
*/
|
||||
def list[A](
|
||||
minSize: Int,
|
||||
maxSize: Int,
|
||||
gen: Gen[A]
|
||||
): Gen[List[A]] = new GenList[A](Size.Between(minSize, maxSize), gen)
|
||||
|
||||
/** Generator for a set of some [[gs.datagen.v0.generators.Size]] based on a
|
||||
* generator for the set elements.
|
||||
*
|
||||
|
@ -172,6 +201,36 @@ object Gen:
|
|||
gen: Gen[A]
|
||||
): Gen[Set[A]] = new GenSet[A](size, gen)
|
||||
|
||||
/** Generator for a set of some fixed size based on a generator for the set
|
||||
* elements.
|
||||
*
|
||||
* @param fixedSize
|
||||
* The goal [[gs.datagen.v0.generators.Size]] of the set. If duplicate
|
||||
* elements are generated, the size will be less then specified.
|
||||
* @param gen
|
||||
* The generator for the list elements.
|
||||
*/
|
||||
def set[A](
|
||||
fixedSize: Int,
|
||||
gen: Gen[A]
|
||||
): Gen[Set[A]] = new GenSet[A](Size.Fixed(fixedSize), gen)
|
||||
|
||||
/** Generator for a set of some size based on a generator for the set
|
||||
* elements.
|
||||
*
|
||||
* @param minSize
|
||||
* Minimum size of the generated set.
|
||||
* @param maxSize
|
||||
* Maximum size of the generated set.
|
||||
* @param gen
|
||||
* The generator for the list elements.
|
||||
*/
|
||||
def set[A](
|
||||
minSize: Int,
|
||||
maxSize: Int,
|
||||
gen: Gen[A]
|
||||
): Gen[Set[A]] = new GenSet[A](Size.Between(minSize, maxSize), gen)
|
||||
|
||||
/** Generators which pick a single random element from a collection.
|
||||
*/
|
||||
object oneOf:
|
||||
|
|
|
@ -1 +1 @@
|
|||
sbt.version=1.11.2
|
||||
sbt.version=1.11.6
|
||||
|
|
Loading…
Add table
Reference in a new issue