diff --git a/test.py b/test.py new file mode 100644 index 0000000..433267a --- /dev/null +++ b/test.py @@ -0,0 +1,55 @@ +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() diff --git a/tests/huge.txt b/tests/huge.txt new file mode 100644 index 0000000..085fd06 --- /dev/null +++ b/tests/huge.txt @@ -0,0 +1 @@ +98765432123456789 \ No newline at end of file diff --git a/tests/negative.txt b/tests/negative.txt new file mode 100644 index 0000000..f064015 --- /dev/null +++ b/tests/negative.txt @@ -0,0 +1 @@ +-1200 \ No newline at end of file diff --git a/tests/power.txt b/tests/power.txt new file mode 100644 index 0000000..7813681 --- /dev/null +++ b/tests/power.txt @@ -0,0 +1 @@ +5 \ No newline at end of file diff --git a/tests/tiny.txt b/tests/tiny.txt new file mode 100644 index 0000000..a32182b --- /dev/null +++ b/tests/tiny.txt @@ -0,0 +1 @@ +34567 \ No newline at end of file