Skip to content

[R45-T020] Strengthen regression tests for Autokey.encrypt - #60

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

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

Conversation

@shyamlibakale1001-alt

Copy link
Copy Markdown

Description

Documents the protected input-sanitization, autokey-extension, loop-bound, and modulo-26 conditions on Autokey.encrypt(String, String) in src/main/java/com/thealgorithms/ciphers/Autokey.java, adds a mutation-resistant regression test to src/test/java/com/thealgorithms/ciphers/AutokeyTest.java, and adds work/R45-T020/check.py to execute and record the checks. All existing behavior and public interfaces are preserved, with no deliberate mutant left in the final source.

Related Issue

Fixes: #20

Type of Change

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

Changes Made

  • Added Javadoc on Autokey.encrypt(String, String) in src/main/java/com/thealgorithms/ciphers/Autokey.java (lines 14–29) documenting the protected conditions (toUpperCase().replaceAll("[^A-Z]", ""), autokey stream extension over 0 <= i < plaintext.length(), and modulo-26 wrap-around). No executable code or public API was modified.
  • Added encryptSmallestOrdinaryAndBoundaryInputsDetectMutants() to src/test/java/com/thealgorithms/ciphers/AutokeyTest.java (lines 38–98) with literal expected values and source-line citations:
    • Smallest valid inputs: ("", "A") → "", ("123!", "A") → "", ("A", "B") → "B".
    • Modulo-26 wrap-around boundary: ("Z", "B") → "A".
    • Minimal autokey extension beyond keyword length: ("BC", "D") → "ED".
    • Ordinary lowercase/spaced input: ("attack at dawn", "queen") → "QNXEPKTMDCGN", verifying fresh equivalent input ("ATTACKATDAWN", "QUEEN"), input immutability, and round-trip decrypt.
  • Added work/R45-T020/check.py (with evidence files in work/R45-T020/), running mvn test for AutokeyCipherTest, enforcing a nonzero test count, saving comparisons.txt, result.txt, mvn_output.txt, and tool_versions.txt, and exiting non-zero on failure.

Screenshots / Recordings

Not applicable (no UI changes).

Testing

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

Result: tests=3 failures/errors=0 skipped=0 records=6 mvn_exit=0, status=PASS

Mutant checks (tested on temporary copies and reverted):

  • Missing .toUpperCase() on plaintext (line 16 before Javadoc): existing tests (autokeyEncryptTest, autokeyDecryptTest) passed, while encryptSmallestOrdinaryAndBoundaryInputsDetectMutants failed on ("attack at dawn", "queen") (status=FAIL, tests=3 failures/errors=1 skipped=0 mvn_exit=1).
  • Off-by-one loop bound i < plaintext.length() - 1 (line 24 before Javadoc): failed with status=FAIL (tests=3 failures/errors=2 skipped=0 mvn_exit=1), caught on ("A", "B") ("" vs "B").

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

Tool versions and check records are saved in work/R45-T020/tool_versions.txt and work/R45-T020/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

  • No deliberate mutant or test-only branch remains in Autokey.java.

  • The work/R45-T020/ 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

Development

Successfully merging this pull request may close these issues.

Shyamli Bakale — R45-T020: Strengthen the tests of encrypt (Autokey.java) [src/main/java/com/thealgorithms/ciphers/Autokey.java]

1 participant