4 ms·
here's an example I had a few month ago: Password Requirements, merging of requirements and generating passwords that fulfill the requirements: - merging/combi
by vbrandl 6y ago
here's an example I had a few month ago:
Password Requirements, merging of requirements and generating passwords that fulfill the requirements:
- merging/combining of requirements is a monoid operation with an "empty requirement" (e.g. one that accepts every password) as the neutral element. Finding this requirement, I could write properties for the monoid properties (a + b = b+ a, a + 0 = a, and so on)
- when generating a password from a requirement, the same requirement must accept the generated password (`requirement.accept(requirement.generate()`)
In general: if you find mathematical rules to your code (commutativity, associativity,. ..), these make a great starting point for property tests.