added tests

This commit is contained in:
Dominik Krenn 2025-11-05 08:05:03 +01:00
parent f807a3efa5
commit de886e30ea
5 changed files with 59 additions and 0 deletions

55
test.py Normal file
View File

@ -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()

1
tests/huge.txt Normal file
View File

@ -0,0 +1 @@
98765432123456789

1
tests/negative.txt Normal file
View File

@ -0,0 +1 @@
-1200

1
tests/power.txt Normal file
View File

@ -0,0 +1 @@
5

1
tests/tiny.txt Normal file
View File

@ -0,0 +1 @@
34567