Skip to content

Improve calculation correctness, testing, and repository reliability - #5

Merged
zomop merged 1 commit into
mainfrom
arena/12014a9e-piproject
Nov 22, 2026
Merged

zomop merged 1 commit into
mainfrom
arena/12014a9e-piproject

Conversation

@zomop

@zomop zomop commented Nov 22, 2026

Copy link
Copy Markdown
Owner

Summary

Implements 13 repository-quality improvements across correctness, testing,
reliability, reproducibility, and developer experience, without breaking
existing functionality. All work is on the feature branch
targeting .

Original problems

  • No automated tests; a numerical project with zero correctness coverage.
  • used a fixed 50-character prefix, so correct small results
    (e.g. 5 digits) were rejected and longer miscalculations sharing the
    prefix were falsely accepted.
  • Guard-digit trimming left-padded on the wrong side, risking integer-part
    corruption.
  • called / at module top level.
  • mutated the global GMPY2 precision on import.
  • Generated 10 MB and were not gitignored.
  • downloaded a 10 MB reference on every run with no retry,
    backoff, reuse, or integrity check.
  • No CLI, no lint/CI, unpinned dependency, no license file, legacy
    calculators undocumented.

Files changed

Modified:

  • pi_project_v4.py — verify_pi fix, guard-digit handling, argparse CLI
    (--digits/--output, exit codes), removed global GMPY2 mutation
  • verify.py — retry/backoff, local-reference reuse, optional --sha256,
    TTY-aware progress, removed dead code
  • pie.py — main() + main guard, no import-time input/exit
  • .gitignore — exclude pi_*.txt and reference_pi.txt
  • requirements.txt — pin gmpy2==2.3.2 (tested compatible)
  • README.md — CLI docs, legacy-calculator comparison, license status

Added:

  • requirements-dev.txt — pytest
  • tests/conftest.py — independent decimal/Machin pi reference fixture
  • tests/test_pi_project_v4.py — calculate_pi, binary_split, verify_pi,
    save_pi, CLI, edge-case tests
  • tests/test_verify.py — normalize_chunk, count_digits, sha256_file,
    verify_full tests
  • tests/fixtures/pi_1000_reference.txt — committed 1,000-digit reference
  • .github/workflows/ci.yml — pytest + end-to-end 1,000-digit calc/verify

Tests executed and actual results

============================= test session starts ==============================
platform linux -- Python 3.11.2, pytest-9.2.0, pluggy-1.7.0
rootdir: /home/user/PiProject
collected 47 items

tests/test_pi_project_v4.py .................................. [ 72%]
tests/test_verify.py ............. [100%]

============================== 47 passed in 0.07s ============================== → 47 passed, 0 failed.
Coverage includes calculate_pi against trusted pi digits (1–1000), an
independent decimal/Machin cross-check, binary_split base cases/sign/
associativity, verify_pi accept/reject/edge cases, verify_full
match/mismatch/length/formatting, save_pi, CLI (--digits/--output,
invalid input, interactive fallback), and import side effects.

Functional checks also ran: 5,000-digit calculation verified against the
trusted first-1,000-digit reference; pie.py and pi_v3.py still execute;
clean; no generated artifacts tracked.

Remaining limitations

  • authoritatively checks only the first 1,000 digits; beyond
    that it validates structure only. Full reference comparison at scale is
    handled by .
  • SHA-256 check is opt-in (); no expected checksum
    is hard-coded (see owner decision below).
  • Large (10,000,000-digit) end-to-end verification is not run in CI due
    to download size/time; covered by the committed 1,000-digit fixture.

Decisions requiring repository owner authorization

License (no LICENSE file added). The project describes itself as open
source and the README's License section notes a license file should be
included, but none exists. I intentionally did NOT select or add a license
(MIT or otherwise) without explicit authorization. Please add a
file (and confirm the README wording) when ready.

Potential compatibility concerns

  • User-facing messages were standardized to English to match the README
    (previously mixed Indonesian/English).
  • now returns exit codes and
    How many digits of pi would you like to calculate?
    Input stream closed. is invoked
    as ; scripts relying on the previous implicit
    exit behavior should use the returned code.
  • is pinned to (the version tested in this sandbox).
    Relax to if broader version support is desired.

Verification in CI

GitHub Actions runs ============================= test session starts ==============================
platform linux -- Python 3.11.2, pytest-9.2.0, pluggy-1.7.0
rootdir: /home/user/PiProject
collected 0 items / 2 errors

==================================== ERRORS ====================================
_________________ ERROR collecting tests/test_pi_project_v4.py _________________
ImportError while importing test module '/home/user/PiProject/tests/test_pi_project_v4.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/usr/lib/python3.11/importlib/init.py:126: in import_module
return _bootstrap._gcd_import(name[level:], package, level)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
tests/test_pi_project_v4.py:10: in
import pi_project_v4 as m
E ModuleNotFoundError: No module named 'pi_project_v4'
____________________ ERROR collecting tests/test_verify.py _____________________
ImportError while importing test module '/home/user/PiProject/tests/test_verify.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/usr/lib/python3.11/importlib/init.py:126: in import_module
return _bootstrap._gcd_import(name[level:], package, level)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
tests/test_verify.py:7: in
import verify as v
E ModuleNotFoundError: No module named 'verify'
=========================== short test summary info ============================
ERROR tests/test_pi_project_v4.py
ERROR tests/test_verify.py
!!!!!!!!!!!!!!!!!!! Interrupted: 2 errors during collection !!!!!!!!!!!!!!!!!!!!
============================== 2 errors in 0.09s =============================== plus an end-to-end 1,000-digit calculation
and verification against on every
push/pull request to . No large files are downloaded.

- Add pytest test suite (tests/) covering calculate_pi against trusted
  pi digits, binary_split, verify_pi, verify_full, save_pi, CLI, and
  edge cases; 47 tests passing
- Fix verify_pi: authoritative full-range check against known pi digits,
  eliminating false positives/negatives from an insufficient prefix
- Fix guard-digit handling in calculate_pi: discard guard digits from the
  fractional end, never left-pad the integer part
- Add argparse CLI (--digits, --output) with interactive fallback and
  explicit exit codes
- Remove GMPY2 global precision mutation on import
- Fix pie.py: move interactive execution into main() with __main__ guard
- verify.py: retry/backoff, reuse local reference, optional SHA-256
  integrity check, TTY-aware progress, remove dead code
- .gitignore: exclude generated pi_*.txt and reference_pi.txt
- Pin gmpy2; add requirements-dev.txt (pytest)
- README: document CLI, legacy calculators (pi_v3.py/pie.py), license
  status pending owner decision
- GitHub Actions CI: run pytest + end-to-end 1,000-digit calc/verify
  against a committed fixture (no large downloads)

Co-authored-by: arena-agent <297053741+arena-agent@users.noreply.github.com>
@zomop
zomop force-pushed the arena/12014a9e-piproject branch from bac7294 to 7edccc4 Compare November 22, 2026 19:59
@zomop
zomop merged commit 158e78f into main Nov 22, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant