liveBook · Manning

State space

As explained in Data-Oriented Programming in Java

A state space is the set of all possible combinations of values representing the states of a domain.

A state space is the set of all possible combinations of values representing a domain or program. Making that space explicit reveals which states remain untested and which invariants the system must preserve. section 11.5

Counting a small domain

Suppose a record contains an optional Policy with five values, an optional AuditFinding with four, and an optional Boolean. Including each Optional.empty state produces 6 × 5 × 3 = 90 possible states. Generating those states can be practical when the modeled space is small. section 7.5.1

Example-based tests exercise selected points in the space. Randomized tests explore broader regions and can express that an invariant should hold for every generated state. The useful target is not unrestricted randomness: generators should cover business-relevant subsets without becoming so prescriptive that they lose exploratory value. section 11.5 section 11.5.2

From examples to generated states

A discount test can generate accounts above, at, and below a threshold, combine those subsets, and then assert the rule over the resulting set. A larger generator can create many accounts first, derive the expected subset from the business predicate, and compare the service result against it.

How Data-Oriented Programming in Java covers it

How deep it goes
Counts finite combinations and develops generator strategies, but defers difficult random-data tooling to property-based testing libraries.
Examples
Uses optional enum combinations, account thresholds, generated subsets, power sets, and large randomized account collections.
What it assumes
Builds from data types and concrete values, then assumes familiarity with tests, generators, predicates, and domain invariants.
What you can do after
Diagnose testing gaps by visualizing reachable states and apply generators that check invariants across relevant data combinations.
How it connects
Connects data types, program states, invariants, randomized testing, and property-based testing.

Also explained in

Compare how 4 books explain state space →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Data-Oriented Programming in Java. The section links point to the parts of the book it draws on.