Skip to content

[R45-T013] Add reference-comparison checks for FairShareScheduling.addWeight - #52

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

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

Conversation

@shyamlibakale1001-alt

Copy link
Copy Markdown

Description

Adds JUnit reference-comparison regression tests for FairShareScheduling.User#addWeight(int) in src/main/java/com/thealgorithms/scheduling/FairShareScheduling.java, documents one representative result in the source Javadoc for addWeight(int), and adds a focused runner (work/R45-T013/check.py) that runs the tests and saves inputs, expected versus actual results, and tool versions. All existing behavior and public interfaces are preserved.

Related Issue

Fixes: #13

Type of Change

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

Changes Made

  • Added Javadoc on FairShareScheduling.User#addWeight(int) explaining one representative result (totalWeight = 0 -> addWeight(2) -> addWeight(3) -> totalWeight = 5; paired with a second user of weight 5 and totalResources = 100, allocateResources(100) assigns 50 to each user). No executable code or public API was altered.
  • Added src/test/java/com/thealgorithms/scheduling/FairShareSchedulingReferenceTest.java with 4 test methods covering 36 logged comparisons:
    • Smallest valid inputs (weight = 0, weight = 1, and single-user totalResources = 1 → {"u1": 1}) with hand-calculated literal expected outputs and source-line citations.
    • Ordinary input (addWeight(2) then addWeight(3) → 5, paired with bob weight 5 and totalResources = 100 → {"alice": 50, "bob": 50}).
    • 24 enumerated small valid addWeight sequences and 6 multi-user FairShareScheduling allocation cases compared against both an explicit hand-calculated literal table and an independent IntStream / BigDecimal reference oracle.
    • Equivalent fresh inputs under controlled state, unregistered-user no-op guard (line 56), and defensive-copy verification of getAllocatedResources() (line 69).
  • Added work/R45-T013/check.py (along with captured evidence in work/R45-T013/), which runs mvn test for FairShareSchedulingReferenceTest, verifies a nonzero test count and at least 20 comparisons, writes comparisons.txt, result.txt, mvn_output.txt, and tool_versions.txt, and exits non-zero on any failure.

Screenshots / Recordings

Not applicable (no UI changes).

Testing

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

Result: tests=4 failures/errors=0 skipped=0 comparisons=36 mvn_exit=0, status=PASS

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

Negative check: temporarily changing this.totalWeight += weight; to this.totalWeight = weight; on line 40 made python3 work/R45-T013/check.py print status=FAIL (tests=4 failures/errors=3 skipped=0 mvn_exit=1) and exit non-zero; the temporary 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-T013/tool_versions.txt and work/R45-T013/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

  • There is no earlier review feedback to address.

  • The work/R45-T013/ 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-T013: Cross-check addWeight (FairShareScheduling.java) [src/main/java/com/thealgorithms/scheduling/FairShareScheduling.java]

1 participant