Skip to content

Domain

class in io.proptastic

abstract non-sealed class Domain<T> implements Argument<Object, T>

Where a property’s inputs come from: “for all x in the domain”. A domain draws a value from a choice sequence and from nothing else, so a saved sequence replays a try exactly and a smaller sequence draws a simpler value.

Make your own by combining domains, domain(symbols(), quantities(), sides(), Trade::new); by naming each draw, domain(source -> new Trade(source.draw(symbols()), …)); or from one with map, filter and flatMap.

Methods

edges

Domain<T> edges(T... values)

This domain, with values drawn often as well, one try in 8: edge values of your own, such as integers().atLeast(1).atMost(3000).edges(1900, 2000, 2100) for a leap-year rule. The rest of the tries draw from this domain as before. A counterexample found at an edge value shrinks among the edges, toward the first given, then, where this domain draws that value too, to the smallest value that fails, edge or not (decision 80).

edges

Domain<T> edges(Collection<? extends T> values)

This domain, with values drawn often as well: see edges.

map

<R> Domain<R> map(Function<? super T, ? extends R> f)

Each value passed through f.

writtenAs

Domain<T> writtenAs(Function<? super T, String> form)

This domain, its values written as Java source as form says, for a type proptastic can’t write itself: money().writtenAs(amount -> "Money.parse(\"" + amount + "\")"), so a failure’s pin line reads .example(Money.parse("USD 0.01")) rather than pinning the seed. The text goes into the pin line as it is, so make it compile where the test is. A value keeps its form wherever it ends up, in a list, a record or a value map returns unchanged; a value map makes anew has none, unless that domain says how to write it too. It draws as this domain does, so no seed or corpus entry changes, and form is called only when a pin line is written. A form that throws leaves the value with no source form (decision 95).

filter

Domain<T> filter(Predicate<? super T> keep)

Only the values that pass keep. A try that can’t find one within 100 draws is discarded, as an assumption would discard it.

excluding

Domain<T> excluding(T... values)

This domain without values, each told apart by equals: integers().excluding(0), elements("buy", "sell", "hold").excluding("hold"). A value the domain can’t draw is no matter. Whole numbers, elements(…) and dates step over the values by their index, so none is ever drawn and a shrink never lands on one; any other domain rejects one as filter does, and the discard health check counts it (decision 92). Say a domain’s bounds first: what this returns is a plain domain.

flatMap

<R> Domain<R> flatMap(Function<? super T, ? extends Domain<? extends R>> f)

A value from the domain that this one’s value picks, for when one value decides another’s domain: integers().atLeast(0).atMost(9).flatMap(n -> lists(strings()).ofSize(n)).

Privacy