How sure is a pass?
A property ran 100 tries and every one passed. How sure are you that the code is right?
The green tick alone can’t say: it’s silent on every input that wasn’t tried. So when a property follows a model or a spec, or runs on threads, proptastic says how sure a pass is, under the line that says what passed:
how sure: 0 of 100 tries failed, so under 3% of inputs drawn this way fail it (95% confidence)This page works out what that line claims, and what it leaves out, on one small rule with a bug in
it. Each step runs the same test again: with more tries, then with other years, then against a
model that names the rule’s cases, and last on every year. Every output below is a run the docs
build makes, with the seed 0x5eed, and each picture shows the years that run drew. The code is
compiled and run by that build too: the calendar, the model and every test on this page are in
src/docs/java/howsure
in proptastic’s repository, so you can run them yourself.
The rule
Section titled “The rule”Every fourth year is a leap year, but a century isn’t, unless it’s a multiple of 400. That’s why 2000 had a 29 February and 1900 didn’t. This calendar forgets the last part:
/** Which years have a 29 February. */final class Calendar { /** Every fourth year is a leap year, but a century isn't. */ static boolean isLeap(int year) { return year % 4 == 0 && year % 100 != 0; }}So it’s wrong about 400, 800, 1200 and every 400th year up to 2800: 7 years in 3,000. The runs below don’t know that, and a green test wouldn’t tell you.
The test follows a model of the rule, as Follow a model does for a trading desk: a small program, written to be obviously right, that proptastic runs beside the code and asks about each year. The model knows the rule’s four cases:
/** The rule's four cases, each with whether it's a leap year. */enum Case { COMMON("not a multiple of 4", false), LEAP("a multiple of 4, not of 100", true), CENTURY("a multiple of 100, not of 400", false), EVERY_400TH("a multiple of 400", true);
final String about; final boolean leap;
Case(String about, boolean leap) { this.about = about; this.leap = leap; }}
/** Which case a year is, written as the rule is said. */static Case decide(int year) { if (year % 400 == 0) { return Case.EVERY_400TH; } if (year % 100 == 0) { return Case.CENTURY; } return year % 4 == 0 ? Case.LEAP : Case.COMMON;}For now it tells proptastic only whether a year is a leap year, as the outcomes leap and
common. The years come from a domain, the years 1 to 3,000:
/** Years from 1 to 3,000. */static Domain<Integer> years() { return integers().atLeast(1).atMost(3_000);}
@Testvoid calendarFollowsTheModel() { forAll(years()).follows(LeapYearModel.process(), Calendar::isLeap);}The next four steps run this one test, with PROPTASTIC_TRIES saying how many tries it makes.
Ten tries
Section titled “Ten tries”PROPTASTIC_TRIES=10 ./gradlew test \ --tests 'LeapYearTest.calendarFollowsTheModel'followed model Calendar.isLeap on 10 tries (Java) · outcomes leap 5 · common 5 how sure: 0 of 10 tries failed, so under 26% of inputs drawn this way fail it (95% confidence) why: https://docs.proptastic.io/concepts/how-sure-is-a-pass/The first line says what passed: the calendar gave the model’s answer for 10 years, 5 of them leap years. The second says how sure that is. None of 10 tries failed, so fewer than 26% of the years proptastic draws can fail.
Here are the years it drew, a hundred to a row, year 1 at the top left. Shaded are the years 1,101 to 3,000, where about 26% of draws land. Were the calendar wrong on every one of them, 10 tries would all miss them only 5 times in 100, so a bug that common would almost surely have shown. That’s the bound: a failure as common as 26% gets past 10 tries only by bad luck.
10 tries: 8 different years. Say the code failed on every shaded year, 1,101 to 3,000, where about 26% of draws land: 10 tries would all miss them at most 5 times in 100. These landed there 3 times.
A hundred tries
Section titled “A hundred tries”PROPTASTIC_TRIES=100 ./gradlew test \ --tests 'LeapYearTest.calendarFollowsTheModel'followed model Calendar.isLeap on 100 tries (Java) · outcomes leap 28 · common 72 how sure: 0 of 100 tries failed, so under 3% of inputs drawn this way fail it (95% confidence) why: https://docs.proptastic.io/concepts/how-sure-is-a-pass/The same test with the same seed draws the same years, so the first 10 of these 100 are the 10 above. With more tries the bound falls to 3%. The shaded years shrink to 2,701 to 2,999, about 3% of draws, which 100 tries would all miss only 5 times in 100.
100 tries: 58 different years. Say the code failed on every shaded year, 2,701 to 2,999, where about 3.1% of draws land: 100 tries would all miss them at most 5 times in 100. These landed there twice.
The dots crowd the first few years and the last. That’s how proptastic draws: small values and each end most often, as that’s where bugs tend to be, and any value the rest of the time. Year 3,000, the far end, is drawn one try in 16.
A thousand tries
Section titled “A thousand tries”PROPTASTIC_TRIES=1000 ./gradlew test \ --tests 'LeapYearTest.calendarFollowsTheModel'followed model Calendar.isLeap on 1,000 tries (Java) · outcomes leap 219 · common 781 how sure: 0 of 1,000 tries failed, so under 0.3% of inputs drawn this way fail it (95% confidence) why: https://docs.proptastic.io/concepts/how-sure-is-a-pass/Under 0.3% now, and the shaded years are down to 29.
1,000 tries: 460 different years. Say the code failed on every shaded year, 2,971 to 2,999, where about 0.31% of draws land: 1,000 tries would all miss them at most 5 times in 100. These landed there 0 times.
Where the numbers come from
Section titled “Where the numbers come from”Say some share p of the inputs drawn would fail. One try passes with chance 1 - p, and n
tries in a row with chance (1 - p)^n. The bound is the share at which that chance falls to 5%,
1 - 0.05^(1/n): any larger share would let every try pass less than 5% of the time, so, at 95%
confidence, the share is smaller. It comes out close to 3/n, which medicine calls the rule of
three, from trials in which nothing went wrong (Hanley and Lippman-Hand,
1983):
| Tries | The bound, exactly | 3/n |
The line says |
|---|---|---|---|
| 10 | 25.9% | 30% | under 26% |
| 100 | 2.95% | 3% | under 3% |
| 1,000 | 0.299% | 0.3% | under 0.3% |
Ten times the tries, a tenth the bound. Under 20 tries 3/n is a poor guess, so the line prints the
exact share, rounded up so that “under” stays true. Only random tries count: an .example(…) or a
corpus entry was chosen, not drawn, so it says nothing of how rare a failure is.
PROPTASTIC_EXPLAIN=1 prints this working under the line, for the run in front of you:
followed model Calendar.isLeap on 1,000 tries (Java) · outcomes leap 219 · common 781 how sure: 0 of 1,000 tries failed, so under 0.3% of inputs drawn this way fail it (95% confidence) the tries: 1,000, drawn at random, and none failed. Examples and corpus entries were chosen, not drawn, so they aren't counted. the bound: if 0.299% of inputs drawn this way failed, all 1,000 tries would pass only 5% of the time, and less often if more failed. So, at 95% confidence, under 0.299% fail, shown rounded up as 0.3%. That's 1 - 0.05^(1/1000), about 3/1000: the rule of three. drawn this way: from this property's domains, which draw small values and each domain's edges most often. The bound says nothing of inputs they never draw, nor of how often real use meets any input. edge cases: a value outside the domains, or one they seldom draw, may never have been tried: widen them, or add it with .edges(…) or .example(…). shrinking: only runs after a failure, so it has no part in a pass. why: https://docs.proptastic.io/concepts/how-sure-is-a-pass/Without it, the first how sure: line in a run is followed by why: and the address of this page.
Still not proof
Section titled “Still not proof”The calendar is wrong, and it passed 1,000 tries. Here are those 1,000 tries again, with the 7 years it gets wrong ringed:
The years it gets wrong: The 7 years the rule gets wrong, ringed. About 0.071% of draws land on one, under the bound of 0.3%, and none of these 1,000 tries did.
The line didn’t lie. About 0.079% of the years proptastic draws are ones the calendar gets wrong, and that’s under 0.3%. A bound says how rare a failure could still be, never that there’s none, and a bug this rare gets past 1,000 tries about half the time. This run was one of those. Run on:
PROPTASTIC_TRIES=10000 ./gradlew test \ --tests 'LeapYearTest.calendarFollowsTheModel'does not follow model Calendar.isLeap (Java)model Calendar.isLeap said true, code said false (outcome leap)
calendarFollowsTheModel failed after 3,298 tries (seed 0x5eed) shrunk counterexample: year = 400 pin it: .example(400) rerun: PROPTASTIC_SEED=0x5eed ./gradlew test --tests 'LeapYearTest.calendarFollowsTheModel'The same years again, carried on, and try 3,298 drew one of the 7, which shrinking took down to 400. More tries make the bound smaller, but never zero: no number of tries says the code is right.
Drawn this way
Section titled “Drawn this way”The bound is about the years proptastic drew, drawn as its domains draw them, which is why the line says drawn this way. Change the domain and the same line is about other years.
Say the app is only used this century, so the test draws this century’s years:
/** The years the app is used in: this century's. */static Domain<Integer> yearsThisCentury() { return integers().atLeast(2001).atMost(2099);}
@Testvoid thisCentury() { var model = LeapYearModel.process(); forAll(yearsThisCentury()).tries(1_000).follows(model, Calendar::isLeap);}thisCentury passed 1,000 tries · this draws 99 values: .exhaustively() checks them allfollowed model Calendar.isLeap on 1,000 tries (Java) · outcomes leap 228 · common 772 how sure: 0 of 1,000 tries failed, so under 0.3% of inputs drawn this way fail it (95% confidence) why: https://docs.proptastic.io/concepts/how-sure-is-a-pass/The same line, just as sure, and just as true: of the years 2001 to 2099, none fail. But they all sit in one row, and none is a century, where every one of the calendar’s mistakes is:
Years this century: 1,000 tries of the years 2001 to 2099: 99 different years, all in one row. The shaded column, the centuries, is never drawn, so neither is a year the rule gets wrong.
No number of tries from this domain finds the bug, and nothing in the line says so. Random testing’s own theory warns of this: a bound like this carries over to real use only as far as the inputs are drawn as real use would draw them (Richard Hamlet, Random Testing, 1994). It’s true of what was drawn, and silent on the rest.
What a model adds
Section titled “What a model adds”The first line has been saying something the bound can’t: which of the model’s outcomes came up,
and how often. A model that names only leap and common is content with this century’s years, as
both came up. So let the model name the rule’s four cases, which it already tells apart, and follow
that:
@Testvoid thisCenturyByRule() { var model = LeapYearModel.byRule(); forAll(yearsThisCentury()).tries(1_000).follows(model, Calendar::isLeap);}model Calendar.isLeap's outcome century (a multiple of 100, not of 400) never came up in 1,000 tries (seed 0x5eed), so following it said nothing of that case: widen the domains, or say why it can't with .unreachable("century", "…") rerun: PROPTASTIC_SEED=0x5eed ./gradlew test --tests 'LeapYearTest.thisCenturyByRule'A run that never reached one of the model’s cases fails, since it said nothing of that case: here, the centuries. Where the bound says how rare a failure could be among what was drawn, the outcomes say whether each case was drawn at all.
To reach them, go back to the years 1 to 3,000 and give the domain edges of its own, a century and a multiple of 400 among them, so each is drawn often:
/** Years from 1 to 3,000, with the rule's edges drawn one try in 8. */static Domain<Integer> yearsAndCenturies() { return years().edges(100, 400, 1900, 2000);}
@Testvoid everyCase() { var model = LeapYearModel.byRule(); forAll(yearsAndCenturies()).tries(1_000).follows(model, Calendar::isLeap);}does not follow model Calendar.isLeap (Java)model Calendar.isLeap said true, code said false (outcome every-400th)
everyCase failed after 4 tries (seed 0x5eed) shrunk counterexample: year = 400 pin it: .example(400) rerun: PROPTASTIC_SEED=0x5eed ./gradlew test --tests 'LeapYearTest.everyCase'Found in 4 tries, where the plain years took 3,298. With the rule written whole:
/** Every fourth year, but not a century, unless it's every 400th. */static boolean isLeap(int year) { return year % 4 == 0 && (year % 100 != 0 || year % 400 == 0);}followed model Calendar.isLeap on 1,000 tries (Java) · outcomes common 624 · leap 200 · century 122 · every-400th 54 how sure: 0 of 1,000 tries failed, so under 0.3% of inputs drawn this way fail it (95% confidence) why: https://docs.proptastic.io/concepts/how-sure-is-a-pass/Now the two lines say two things together: every case of the rule came up, the 400th years 54 times, and of the years drawn this way, fewer than 0.3% can fail.
Every year
Section titled “Every year”There are only 3,000 years, so there’s no need to draw them: try every one, as examples, and
.tries(0) for no random tries after them.
@Testvoid everyYear() { var everyYear = IntStream.rangeClosed(1, 3_000).boxed().toList(); forAll(years()) .examples(everyYear) .tries(0) .follows(LeapYearModel.process(), FixedCalendar::isLeap);}followed model Calendar.isLeap on 3,000 tries (Java) · outcomes leap 727 · common 2,273There’s no how sure: line. Nothing was drawn, so nothing was left to chance and there’s no bound
to state: the line counts every year, and each passed.
Every year: All 3,000 years, each checked once: nothing drawn, so nothing left to chance, and no bound to state.
A proof covers every input too, by argument rather than by running them, and for domains far too big to run. A model written in Lean can carry one, such as a theorem that the rule holds for every year, and a pass names the theorems its model proved. From design to code builds one.
On threads, both at once
Section titled “On threads, both at once”A test of code on threads is both kinds of run. Each run’s steps are drawn, as a try’s year is. Then proptastic runs those steps on every schedule, each order the threads could interleave in, with up to two preemptions, as this page ran every year. So a pass on threads says two things:
passed on 2 threads, 101 runs (every schedule with up to 2 preemptions: 3,906) · no deadlock · each fits an order of its steps, one at a time how sure: 0 of 100 runs failed, so under 3% of runs drawn this way fail it (95% confidence) why: https://docs.proptastic.io/concepts/how-sure-is-a-pass/The first line is exact: every schedule within the bound was run, 3,906 of them, and none was sampled. The second is the rule of three again, over the runs, whose steps were drawn: under 3% of runs drawn this way fail. Schedules with more preemptions, like years outside a domain, are in neither. A spec checked by TLC is exact the same way, over every state its constants allow, as From design to code shows. A spec followed by TLC traces isn’t: TLC judges every step the runs took, and the runs are drawn, so its pass is sure as a pass on runs is.
Reading the line
Section titled “Reading the line”| The line says | Which means | To say more |
|---|---|---|
0 of 1,000 tries |
the random tries that passed; examples and corpus entries aren’t counted | more tries |
under 0.3% |
the exact bound, 1 - 0.05^(1/n), rounded up |
more tries: ten times as many, a tenth the bound |
of inputs drawn this way |
over your domains’ draws, not real use, and not inputs they never draw | wider domains, edges |
(95% confidence) |
a bound worked out this way is too small at most one run in 20 | more tries |
| the outcomes on the line above | each of the model’s cases came up | a model that names its cases |
None of it says the code is right. Trying every input of a small domain does, for that domain, and so does a proof. Short of that, the line says how rare a failure could still be among what was drawn, and the outcomes say what was drawn.
How sure a share is
Section titled “How sure a share is”require asks a different question of the same tries: not how
rare a failure could be, but whether a case came up often enough. It’s held to more than 95%
confidence, as a wrong answer fails a build or passes a gap. It calls a share too rare, or enough,
only when the chance of that call being wrong is under one in a billion, PROPTASTIC_CERTAINTY,
drawing more tries until it can, up to 64 times those asked:
| The tries | Asked for | The line | What a run says |
|---|---|---|---|
| 7.1% of 800 | 20% | 18% | too rare: it fails |
| 8.9% of 6,400 | 10% | 9% | incomplete: it can’t tell, and says so |
| 42% of 100 | 10% | 9% | enough |
The line is nine tenths of the share asked for, so a share drawn at exactly what was asked is told
as enough in a bounded number of tries, never failed by chance. The chance is worked out with
Chernoff’s bound on a count of independent tries, which holds for any number of them, and split
across the run’s looks, at most 7, so a run that looks again after each doubling is no less sure.
Still unsure at the end, the share is incomplete, never a silent pass: the run says so, with how
sure it got, and PROPTASTIC_INCOMPLETE=fail fails it.
After the run
Section titled “After the run”proptastic explain puts a property’s last run on one card: how sure its pass is, in the long form
above, worked from its event’s numbers, and its model’s outcomes, with its counterexample, corpus
and proposals:
proptastic explain followsTheLeapYearRule ✓ PASSED CalendarTest#followsTheLeapYearRule ┌─ src/test/java/calendar/CalendarTest.java:13 │ 13 │ forAll(integers().atLeast(1).atMost(3_000)) │
last run: passed 100 tries · seed 0x3a78b1c526b4abf0 · local profile · 17ms started: 2026-12-03T07:02:19.397Z how sure: 0 of 100 tries failed, so under 3% of inputs drawn this way fail it (95% confidence) the tries: 100, drawn at random, and none failed. Examples and corpus entries were chosen, not drawn, so they aren't counted. the bound: if 2.95% of inputs drawn this way failed, all 100 tries would pass only 5% of the time, and less often if more failed. So, at 95% confidence, under 2.95% fail, shown rounded up as 3%. That's 1 - 0.05^(1/100), about 3/100: the rule of three. drawn this way: from this property's domains, which draw small values and each domain's edges most often. The bound says nothing of inputs they never draw, nor of how often real use meets any input. edge cases: a value outside the domains, or one they seldom draw, may never have been tried: widen them, or add it with .edges(…) or .example(…). shrinking: only runs after a failure, so it has no part in a pass. model: Calendar.isLeap (command) outcomes: leap 21 (21%) · common 79 (79%) counterexample: none saved corpus: 2 inputs kept, 1 stale proposals: none
Next: proptastic explain 'CalendarTest#followsTheLeapYearRule' leap
About this property ─────────────────────────────────────────── id: calendar.CalendarTest#followsTheLeapYearRule(), as the manifest names it domains: integers[1,3000] corpus key: calendar.CalendarTest#followsTheLeapYearRule(), the directory its inputs are kept in runs under: test, in the build's rootproptastic explain has the rest.