Property-based testing (PBT) generates random inputs and verifies that properties hold for all of them. Instead of testing specific examples, you test invariants.
| Roundtrip | decode(encode(x)) == x | Serialization, conversion pairs | | Idempotence | f(f(x)) == f(x) | Normalization, formatting, sorting | | Invariant | Property holds before/after | Any transformation | | Commutativity | f(a, b) == f(b, a) | Binary/set operations | | Associativity | f(f(a,b), c) == f(a, f(b,c)) | Combining operations |
| Identity | f(x, identity) == x | Operations with neutral element | | Inverse | f(g(x)) == x | encrypt/decrypt, compress/decompress | | Oracle | newimpl(x) == reference(x) | Optimization, refactoring | | Easy to Verify | issorted(sort(x)) | Complex algorithms | | No Exception | No crash on valid input | Baseline (weakest) |