Every value
A random pass has checked the inputs it drew. When the draws have only a few values, a side, a count from 1 to 10, a flag, it can check every one of them instead, and then a pass is a proof over that domain.
Every value with .exhaustively()
Section titled “Every value with .exhaustively()”Where the draws have few values, run each once in place of random tries, and a pass has checked them all:
@Testvoid aFeeIsNeverMoreThanALotEach() { forAll(any(Side.class), integers().atLeast(1).atMost(10), booleans()) .exhaustively() .check((side, lots, rush) -> assertTrue(fee(side, lots, rush) <= lots));}aFeeIsNeverMoreThanALotEach passed every value, all 40That’s every side, every lot count from 1 to 10 and both flags: 40 values, the simplest first. A
counterexample is the first value that fails, shrunk as any other. Here the fee should be waived for an
urgent buy of up to 2 lots, but the code says lots < 2:
@Testvoid anUrgentBuyOfUpToTwoLotsIsFree() { forAll(integers().atLeast(1).atMost(10)) .exhaustively() .check(lots -> assertTrue(lots > 2 || fee(Side.BUY, lots, true) == 0));}expected: <true> but was: <false>
anUrgentBuyOfUpToTwoLotsIsFree failed after 2 tries (seed 0x5eed) shrunk counterexample: lots = 2 pin it: .example(2) rerun: PROPTASTIC_SEED=0x5eed ./gradlew test --tests 'ExhaustivelyTest.anUrgentBuyOfUpToTwoLotsIsFree'Draws with more than 100,000 values, such as a list, a string or an unbounded number, are refused: bound them, or draw them at random. A filter counts the values it rejects too, so a strict one makes a domain too large.
When a random pass could check them all
Section titled “When a random pass could check them all”A random pass whose draws have no more values than it tried says so, as a hint:
@Testvoid aFeeIsNeverMoreThanALot() { forAll(integers().atLeast(1).atMost(10), booleans()) .check((lots, rush) -> assertTrue(fee(Side.SELL, lots, rush) <= lots));}aFeeIsNeverMoreThanALot passed 100 tries · this draws 20 values: .exhaustively() checks them allThe hint never changes what runs: .exhaustively() is yours to add.
Too many to run
Section titled “Too many to run”A draw with no bound, or a list or a string, has far too many values. .exhaustively() counts
them first, and refuses past 100,000, before running any:
@Testvoid aFeeIsNeverMoreThanALotForAnyCount() { forAll(integers().atLeast(1), booleans()) .exhaustively() .check((lots, rush) -> assertTrue(fee(Side.SELL, lots, rush) <= lots));}aFeeIsNeverMoreThanALotForAnyCount: .exhaustively() runs every value, but its draws have more than 100,000: bound them, or draw them at random