#!/usr/bin/env python3 """Детерминированный набор для P5: 20 copy и граничные размеры.""" from __future__ import annotations import pathlib import sys SIZES = [ 0, 1, 4095, 4096, 65535, 65536, 37, 511, 512, 513, 1023, 1024, 2047, 2048, 8191, 8192, 16383, 16384, 32769, 1024 * 1024 + 37, ] def content(index: int, size: int) -> bytes: seed = (0x31 + index * 13) & 0xFF return bytes(((position * 37 + (position >> 8) * 11 + seed) & 0xFF) for position in range(size)) def create(root: pathlib.Path) -> None: source = root / "SOURCE" target = root / "TARGET" source.mkdir(parents=True) target.mkdir(parents=True) for index, size in enumerate(SIZES): (source / f"F{index:02d}.BIN").write_bytes(content(index, size)) def verify_initial(root: pathlib.Path) -> None: source = root / "SOURCE" target = root / "TARGET" failures = [] for index, size in enumerate(SIZES): path = source / f"F{index:02d}.BIN" if not path.is_file() or path.read_bytes() != content(index, size): failures.append(f"повреждён SOURCE/{path.name}") if not target.is_dir() or list(target.iterdir()): failures.append("TARGET не пуст до теста") if failures: for failure in failures: print(f"FAIL: {failure}") raise SystemExit(1) print("PASS: P5 fixture содержит 20 источников, TARGET пуст.") def verify(root: pathlib.Path) -> None: source = root / "SOURCE" target = root / "TARGET" failures = [] for index, size in enumerate(SIZES): name = f"F{index:02d}.BIN" source_path = source / name target_path = target / name if not target_path.is_file(): failures.append(f"нет TARGET/{name}") elif target_path.read_bytes() != source_path.read_bytes(): failures.append(f"TARGET/{name} не совпадает с источником") elif target_path.stat().st_size != size: failures.append(f"неверный размер TARGET/{name}") temporaries = sorted(target.glob("~SC*.TMP")) if temporaries: failures.append("остались временные файлы: " + ", ".join(path.name for path in temporaries)) if failures: for failure in failures: print(f"FAIL: {failure}") raise SystemExit(1) print("PASS: 20/20 файлов совпали; все граничные размеры и >1 МБ пройдены.") def main() -> None: commands = {"create", "verify-initial", "verify"} if len(sys.argv) != 3 or sys.argv[1] not in commands: raise SystemExit( f"usage: {sys.argv[0]} create|verify-initial|verify DIR") root = pathlib.Path(sys.argv[2]) if sys.argv[1] == "create": create(root) elif sys.argv[1] == "verify-initial": verify_initial(root) else: verify(root) if __name__ == "__main__": main()