Code, Contracts & Types · Page 2 of 6
Conformance: Code Meets Spec
What happens when you give an action both an Action(predicate)
and a Python body?
That declares a conformance obligation. In every reachable state, for every
argument where Requires holds, the checker verifies that the step produced by
running the Python body:
- satisfies the
Actionpredicate, - satisfies every
Ensuresclause (whereresultbinds the return value), - changes only the variables permitted by
Modifies, and - satisfies every
assertit reaches.
If someone edits the implementation later and forgets the spec (or vice versa), the check fails immediately with the exact state and action where the two part ways.
Try it: Change
self.available -= 1 to self.available -= 2
(or change return True to return False) and click Check
to see a FAIL conformance report!