liveBook · Manning

Property check

As explained in Functional Programming in Scala, Second Edition

A property check is an operation that executes a Prop and returns an outcome describing whether its tests succeeded or failed.

A property check executes a Prop and returns an outcome describing whether its generated tests succeeded or failed. Returning information, rather than merely printing a report, preserves the data needed for composition. section 8.1.3

A useful check distinguishes several concerns:

  • A Boolean can express success or failure, but loses failure details and test counts. section 8.1.3
  • An Either-based result can preserve a failed case, the number of successful tests, or the number of tests completed. section 8.1.3
  • A helper can supply maximum size, test count, and a random generator, returning a Result for further handling. section 8.2.2

Checking a maximum property

A generated-list property checks that every element is less than or equal to the list maximum. Running it can reveal that empty lists violate the unstated assumption, prompting a nonempty-list generator. section 8.2.2

Listing 8.5 A check helper function for Prop
extension (self: Prop)
  def check(
    maxSize: MaxSize = 100,      #1
    testCases: TestCases = 100,
    rng: RNG = RNG.Simple(System.currentTimeMillis)
  ): Result =
    self(maxSize, testCases, rng)

Use the check helper to inspect how execution parameters become an explicit Result-producing operation. section 8.2.2

How Functional Programming in Scala, Second Edition covers it

How deep it goes
Explores side effects, Boolean insufficiency, structured outcomes, and configurable execution, without fully specifying the result representation.
Examples
Uses maximum and sorting properties, including a failing empty-list maximum case and a nonempty-list generator exercise.
What it assumes
Assumes Prop, forAll, generators, and Boolean predicates while developing their relationship through concrete property examples.
What you can do after
Diagnose/debug with property checks by detecting failures, counting passed tests, and exposing counterexample information.
How it connects
Connects Prop with property composition, generators, Either, Result, and property-based testing.

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.