Skip to content

[R45-T015] Add determinism checks for HowManyTimesRotated - #51

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

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

Conversation

@shyamlibakale1001-alt

Copy link
Copy Markdown

Description

Adds JUnit determinism checks for HowManyTimesRotated.rotated(int[]) and a small runner (work/R45-T015/check.py) that executes them and propagates failures. The method is already pure (no I/O, time, randomness or input mutation), so this PR adds regression tests only and does not change the implementation.

Related Issue

Fixes: #15

Type of Change

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

Changes Made

  • Added src/test/java/com/thealgorithms/searches/HowManyTimesRotatedDeterminismTest.java with 6 tests:
    • smallest valid input {7} → 0, called twice
    • ordinary input {15, 17, 2, 3, 5} → 2, called twice
    • the ordinary result is unchanged after other valid inputs ({11, 12, 15, 18, 2, 5, 6, 8} → 4 and {7} → 0) run in between
    • the input array is not mutated
    • the same array instance can be reused
    • the result does not depend on System.in (only main() reads stdin)
  • Expected values are hand-calculated (index of the minimum element) and written as literals. Comments name the source lines that establish each precondition (no duplicates at line 13, rotated at line 45, loop skipped for length 1 at line 49, result at line 58).
  • Added work/R45-T015/check.py, which runs mvn test for the new class, requires a nonzero test count, and saves the command, test count, tool versions and Maven output in work/R45-T015/.
  • No change to `HowManyTimesRotated.jav## Screenshots / Recordings
    Not applicable (no UI changes).

Testing

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

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

Negative check: temporarily changing a[mid] > a[high] to a[mid] < a[high] on line 51 made the check print FAIL (4 of 6 tests failed) and exit non-zero; the change was reverted and git diff src/main is empty.

Style: mvn -B checkstyle:check reports 0 violations.

Tool versions are saved in work/R45-T015/tool_versions.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 documentation change was needed, and there is no earlier review feedback to address.

  • The task text points at "line 30", which is the private constructor; the method under test is at line 45.

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