示例工程 29-testing-pytest
29-testing-pytest/02-parametrize-matrix/parametrize_matrix.py
"""演示参数化测试的目标函数 clamp。"""
from __future__ import annotations
def clamp(value: int, low: int, high: int) -> int:
if low > high:
raise ValueError("low must be <= high")
return max(low, min(value, high))
def main() -> None:
for value in (-5, 0, 5, 15):
print(f"clamp({value}, 0, 10) = {clamp(value, 0, 10)}")
if __name__ == "__main__":
main()