Property-based testing
Në shqip: Testimi i bazuar në veti
ShpjegimiSQ
Në vend që të shkruash shembuj me dorë, përshkruan një „veti“ që duhet të vlejë gjithmonë („renditja e një liste të renditur s'e ndryshon“) dhe mjeti (Hypothesis, fast-check) gjeneron qindra hyrje të rastësishme për ta provuar.
EnglishEN
Instead of hand-writing examples, you describe a “property” that should always hold (“sorting a sorted list doesn't change it”) and the tool (Hypothesis, fast-check) generates hundreds of random inputs to test it.
Si ta mendosh
Si të kontrollosh një rregull me mijëra raste të rastësishme në vend të tre shembujve.
Lexoje në anglisht
Like checking a rule against thousands of random cases instead of three examples.
Shembull kodipython
from hypothesis import given, strategies as st
@given(st.lists(st.integers()))
def test_renditja(v):
assert sorted(sorted(v)) == sorted(v)