Advertisement
Korotkodul

B2

Sep 21st, 2024
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.79 KB | None | 0 0
  1. import time
  2.  
  3. from typing import Callable, TypeVar
  4.  
  5. T = TypeVar("T")
  6.  
  7. def is_floats_eq(lhs: float, rhs: float, eps: float = 1e-6) -> bool:
  8.     return abs(lhs - rhs) < eps
  9.  
  10.  
  11. def collect_statistic(
  12.     statistics: dict[str, list[float, int]]
  13. ) -> Callable[[T], T]:
  14.     # ваш код
  15.     return statistics
  16.  
  17. statistics: list[str, list[float, int]] = {}
  18.  
  19. @collect_statistic(statistics)
  20. def func1() -> None:
  21.     time.sleep(2)
  22.  
  23.  
  24. @collect_statistic(statistics)
  25. def func2() -> None:
  26.     time.sleep(1)
  27.  
  28. for i in range(3):
  29.     func1()
  30.  
  31. for i in range(6):
  32.     func2()
  33.  
  34. eps = 1e-3
  35.  
  36. assert statistics[func1.__name__][1] == 3
  37. assert statistics[func2.__name__][1] == 6
  38. assert is_floats_eq(statistics[func1.__name__][0], 2, eps)
  39. assert is_floats_eq(statistics[func2.__name__][0], 1, eps)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement