Package src/speed_calc with the decorator, fast_function, slow_function, constants.py and runnable lecture steps; pytest tests with a fake clock; four screenshots rendered from real output; README lecture steps; review record RC-007. Task: MIL-002#1 Task: MIL-002#2 Task: MIL-002#3 Task: MIL-002#4 Task: MIL-002#5 Task: MIL-002#6 Task: MIL-002#7
34 lines
988 B
Python
34 lines
988 B
Python
"""Tests for the assignment's functions and the entry point."""
|
|
|
|
import re
|
|
|
|
import pytest
|
|
|
|
from speed_calc import constants, fast_function, slow_function
|
|
from speed_calc.__main__ import main
|
|
|
|
LINE = r"(fast|slow)_function run speed: \d+(\.\d+)?(e-?\d+)?s"
|
|
|
|
|
|
def test_function_names_match_the_assignment() -> None:
|
|
assert fast_function.__name__ == "fast_function"
|
|
assert slow_function.__name__ == "slow_function"
|
|
|
|
|
|
def test_constants_hold_the_loop_sizes() -> None:
|
|
assert constants.FAST_ITERATIONS == 1_000_000
|
|
assert constants.SLOW_ITERATIONS == 10_000_000
|
|
|
|
|
|
def test_main_prints_time_then_fast_then_slow(
|
|
capsys: pytest.CaptureFixture[str],
|
|
) -> None:
|
|
main()
|
|
|
|
lines = capsys.readouterr().out.splitlines()
|
|
|
|
assert len(lines) == 3
|
|
assert float(lines[0]) > 0
|
|
assert re.fullmatch(LINE, lines[1]) and lines[1].startswith("fast_function")
|
|
assert re.fullmatch(LINE, lines[2]) and lines[2].startswith("slow_function")
|