Skip to content

[R45-T011] Add contract regression checks for ComplexNumberMultiply - #53

Open
shyamlibakale1001-alt wants to merge 1 commit into
S-AI-Projects:masterfrom
shyamlibakale1001-alt:student/e26b07f0813/R45-T011
Open

shyamlibakale1001-alt wants to merge 1 commit into
S-AI-Projects:masterfrom
shyamlibakale1001-alt:student/e26b07f0813/R45-T011

Conversation

@shyamlibakale1001-alt

Copy link
Copy Markdown

Description

Adds JUnit contract regression tests for ComplexNumberMultiply.multiply(String, String) in src/main/java/com/thealgorithms/maths/ComplexNumberMultiply.java, documents a concise input/output contract beside multiply(String, String), and adds a focused runner (work/R45-T011/check.py) that executes the checks and saves inputs, expected versus actual results, and tool versions. All existing behavior and public interfaces are preserved.

Related Issue

Fixes: #11

Type of Change

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

Changes Made

  • Added concise Javadoc input/output contract beside ComplexNumberMultiply.multiply(String, String) (lines 23–38 of src/main/java/com/thealgorithms/maths/ComplexNumberMultiply.java). No executable code or public interface was changed.
  • Added src/test/java/com/thealgorithms/maths/ComplexNumberMultiplyContractTest.java with 5 test methods (22 logged cases):
    • Smallest valid inputs ("0+0i", "1+0i", "0+1i") with literal expected outputs and precondition line citations.
    • Ordinary inputs (("2+3i", "4+5i") → "-7+22i", ("1+-2i", "-3+4i") → "5+10i").
    • Repeated-value and domain boundary cases ("1+1i", "-1+-1i", "0+-1i", multiplicative identity "1+0i", zero absorption, pure imaginary, conjugate pair, and multi-digit negative/positive components).
    • Invalid format and null input rejection (IllegalArgumentException message contract).
    • Separate verification of absence of observable state mutation across repeated calls.
  • Added work/R45-T011/check.py (with evidence files in work/R45-T011/), which runs mvn test for ComplexNumberMultiplyContractTest, enforces a nonzero test count, saves comparisons.txt, result.txt, mvn_output.txt, and tool_versions.txt, and exits non-zero on failure.

Screenshots / Recordings

Not applicable (no UI changes).

Testing

Command: python3 work/R45-T011/check.py
(runs mvn -B test -Dtest=ComplexNumberMultiplyContractTest -Dsurefire.failIfNoSpecifiedTests=false)

Result: tests=5 failures/errors=0 skipped=0 comparisons=22 mvn_exit=0, status=PASS

Existing suite: mvn -B test -Dtest=ComplexNumberMultiplyTest -Dsurefire.failIfNoSpecifiedTests=false → Tests run: 5, Failures: 0, Errors: 0, Skipped: 0 (BUILD SUCCESS).

Negative check: temporarily changing int real = a[0] * b[0] - a[1] * b[1]; to + on line 43 made python3 work/R45-T011/check.py print status=FAIL (tests=5 failures/errors=4 skipped=0 mvn_exit=1) and exit non-zero; the change was reverted and re-verified.

Style: mvn -B checkstyle:check reports 0 Checkstyle violations (BUILD SUCCESS).

Tool versions and comparison outputs are saved in work/R45-T011/tool_versions.txt and work/R45-T011/comparisons.txt.

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.

Additional Notes

  • The task text points at "line 9", which is the private constructor; the public method under test is multiply(String, String) (originally line 23, now line 39 after adding Javadoc) backed by parse(String) (lines 12–21).

  • The work/R45-T011/ evidence folder is for coursework review only and should not go into any later upstream PR.

  • 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 algorithms have a URL in their comments that points to Wikipedia or other similar explanations.

  • All new algorithms include a corresponding test class that validates their functionality.

  • All new code is formatted with clang-format -i --style=file path/to/your/file.java

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant