Hypothesis 示例
Hypothesis 示例
from hypothesis import given, strategies as st
@given(st.lists(st.integers()))
def test_reverse_twice_is_same(xs):
assert list(reversed(list(reversed(xs)))) == xs- 常见性质:幂等、可逆、顺序无关、范围保持、与参考实现一致
- 反例自动缩减(shrinking)是核心价值:把大输入缩到最小失败样本
属性测试适合解析器、算法、序列化与状态机;不适合替代具体示例的验收测试。