Skip to content

feat(physics): test invariant and add property-based tests for ThinLe… - #44

Open
Sapna2007-sst wants to merge 1 commit into
S-AI-Projects:masterfrom
Sapna2007-sst:e26b07f0703/R04-T004
Open

Sapna2007-sst wants to merge 1 commit into
S-AI-Projects:masterfrom
Sapna2007-sst:e26b07f0703/R04-T004

Conversation

@Sapna2007-sst

Copy link
Copy Markdown

Description

This pull request introduces property-based and invariant regression tests for ThinLens, documents the fundamental reciprocal and conjugate foci lens invariants in Javadoc, and verifies invariant consistency across 100 bounded valid random cases alongside edge-case and boundary conditions.

Related Issue

Fixes: #4

Type of Change

  • Tests
  • Documentation
  • Bug Fix
  • New Feature
  • UI/UX Improvement
  • Performance Improvement
  • Refactoring / Maintenance
  • CI/CD

Changes Made

  • Documented the thin lens invariant (1.0 / v) + (1.0 / u) == 1.0 / f and conjugate foci reciprocity next to the implementation in src/main/java/com/thealgorithms/physics/ThinLens.java.
  • Expanded src/test/java/com/thealgorithms/physics/ThinLensTest.java with:
    • Smallest valid input fixture (f = 1.0, u = 2.0 yielding v = 2.0, m = 1.0).
    • Ordinary input workflow fixture (f = 10.0, u = 15.0 yielding v = 30.0, m = 2.0).
    • Property-based testing generating 100 deterministic bounded cases (seed 42L) checking reciprocal relations, conjugate foci involution, and magnification consistency.
    • Zero focal length and zero object distance boundary precondition checks asserting IllegalArgumentException.
    • Diverging lens virtual image verification (f = -10.0, u = 20.0 with isRealImage == false).
    • Private constructor reflection contract.
  • Added automated verification check runner work/R45-T004/check.py with invariant mutation sensitivity testing, and saved execution evidence in work/R45-T004/results.json and work/R45-T004/evidence.md.

Screenshots / Recordings

N/A (physics ray optics utility and unit tests; non-UI)

Testing

All changes have been validated locally using JDK 21 and Maven:

  • mvn test -Dtest=ThinLensTest (Tests run: 9, Failures: 0, Errors: 0, Skipped: 0)
  • mvn checkstyle:check (0 Checkstyle violations)
  • python3 work/R45-T004/check.py (All checks, 100 property iterations, and mutation checks passed successfully)

Checklist

  • I have tested my changes locally.
  • I have added or updated tests, if needed.
  • I have updated documentation, if needed.
  • I have followed the project's coding guidelines.
  • I have run the relevant tests and checks.
  • I have addressed previous review feedback, if applicable.
  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized it.
  • All filenames are in PascalCase.
  • All functions and variable names follow Java naming conventions.
  • All new code adheres to repository style conventions and passes mvn checkstyle:check.

Additional Notes

  • Precondition lines establishing input requirements are explicitly cited in both the test methods and work/R45-T004/evidence.md.
  • Automated check runner can be verified anytime with python3 work/R45-T004/check.py.

…ns (R45-T004)

- Document thin lens reciprocal and conjugate foci invariants in ThinLens Javadoc
- Add property-based regression tests generating 100 deterministic bounded cases (seed 42L) asserting reciprocal, involution, and magnification invariants
- Add smallest valid fixture (f=1.0, u=2.0), ordinary fixture (f=10.0, u=15.0), zero focal/object distance exception checks, virtual image checks, and reflection contract
- Add automated verification check runner work/R45-T004/check.py with mutation rejection and verification evidence
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.

Sapna Shankar Talke — R45-T004: Test an invariant of ThinLens (ThinLens.java) [src/main/java/com/thealgorithms/physics/ThinLens.java]

1 participant