Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import time
- from typing import Callable, TypeVar
- T = TypeVar("T")
- def is_floats_eq(lhs: float, rhs: float, eps: float = 1e-6) -> bool:
- return abs(lhs - rhs) < eps
- def collect_statistic(
- statistics: dict[str, list[float, int]]
- ) -> Callable[[T], T]:
- # ваш код
- return statistics
- statistics: list[str, list[float, int]] = {}
- @collect_statistic(statistics)
- def func1() -> None:
- time.sleep(2)
- @collect_statistic(statistics)
- def func2() -> None:
- time.sleep(1)
- for i in range(3):
- func1()
- for i in range(6):
- func2()
- eps = 1e-3
- assert statistics[func1.__name__][1] == 3
- assert statistics[func2.__name__][1] == 6
- assert is_floats_eq(statistics[func1.__name__][0], 2, eps)
- assert is_floats_eq(statistics[func2.__name__][0], 1, eps)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement