from __future__ import annotations from pathlib import Path from mathstream import StreamNumber, add, sub, mul, div, pow, clear_logs NUMBERS_DIR = Path(__file__).parent / "tests" def write_number(name: str, digits: str) -> StreamNumber: """Persist digits to disk and return a streamable handle.""" NUMBERS_DIR.mkdir(parents=True, exist_ok=True) target = NUMBERS_DIR / f"{name}.txt" target.write_text(digits, encoding="utf-8") return StreamNumber(target) def read_number(num: StreamNumber) -> str: """Collapse streamed chunks back into a concrete string.""" return "".join(num.stream()) def check(label: str, result: StreamNumber, expected: str) -> None: actual = read_number(result) assert ( actual == expected ), f"{label} expected {expected}, got {actual}" print(f"{label} = {actual}") def main() -> None: clear_logs() # Build a handful of example operands on disk. big = write_number("huge", "98765432123456789") small = write_number("tiny", "34567") negative = write_number("negative", "-1200") exponent = write_number("power", "5") # Showcase the core operations. total = add(big, small) difference = sub(big, small) product = mul(small, negative) quotient = div(big, small) powered = pow(small, exponent) print("Operands stored under:", NUMBERS_DIR) check("huge + tiny", total, "98765432123491356") check("huge - tiny", difference, "98765432123422222") check("tiny * negative", product, "-41480400") check("huge // tiny", quotient, "2857217349595") check("tiny ** power", powered, "49352419431622775997607") if __name__ == "__main__": main()