liveBook · Manning

Sgen

As explained in Functional Programming in Scala, Second Edition

SGen is a book-defined type representing a size-aware generator of arbitrary test values.

SGen represents a size-aware generator as a function from an integer size to a Gen of arbitrary test values. The generator knows how to produce a value at a requested size, while the property runner chooses which sizes to try. section 8.2

SGen separates value generation from test scheduling:

  • Convert an ordinary Gen into an SGen by ignoring the supplied size. section 8.2
  • Reuse Gen operations through SGen convenience functions. section 8.2
  • Generate structures such as lists from the requested size rather than from an explicit combinator argument. section 8.2

Sized property testing

A sized forAll supplies Prop with a maximum size. Prop distributes test cases across sizes from zero through that maximum, runs the resulting properties, and can search for the smallest failing test case. section 8.2

opaque type SGen[+A] = Int => Gen[A]

The compact type definition makes the size dependency explicit: SGen[A] maps an Int size to Gen[A]. section 8.2

How Functional Programming in Scala, Second Edition covers it

How deep it goes
Defines the size-to-generator representation and exercises conversions, delegated combinators, sized lists, and maximum-size execution.
Examples
Uses size-independent generators, sized list generation, and properties distributed across sizes up to a maximum.
What it assumes
Assumes Gen, Prop, arbitrary value generation, and property-based testing; teaches how size becomes an explicit dependency.
What you can do after
Build sized generators and apply them through maximum-size property testing.
How it connects
Connects Gen with Prop, property-based testing, and test case minimization.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Functional Programming in Scala, Second Edition. The section links point to the parts of the book it draws on.