Skip to content

test(graph): cover failure and boundary behavior in GomoryHuTree (R45… - #48

Open
Sapna2007-sst wants to merge 1 commit into
S-AI-Projects:masterfrom
Sapna2007-sst:student/e26b07f0703/R08-T008
Open

Sapna2007-sst wants to merge 1 commit into
S-AI-Projects:masterfrom
Sapna2007-sst:student/e26b07f0703/R08-T008

Conversation

@Sapna2007-sst

@Sapna2007-sst Sapna2007-sst commented Nov 11, 2026 •

Copy link
Copy Markdown
  • Document validation preconditions, failure branches, and caller-owned state immutability in GomoryHuTree Javadoc
  • Exercise all documented failure branches asserting exact exceptions and messages citing source precondition lines (GomoryHuTree.java:73-86)
  • Cover smallest valid fixture (1x1 matrix [[0]] returning parent=[-1], weight=[0]), ordinary 2x2 and 3x3 fixtures, caller state preservation, and post-failure execution isolation
  • Add private constructor encapsulation test and automated verification runner work/R45-T008/check.py with verification evidence
  • 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

Description

This pull request resolves task R45-T008 / Issue #8 by providing comprehensive failure-path and boundary coverage for GomoryHuTree.java. It exercises every rejection and failure path in validateCapacityMatrix, naming the exact source lines establishing preconditions (cap == null, cap.length == 0, cap[i] == null, cap[i].length != n, cap[i][j] < 0). It validates the smallest valid input fixture ([[0]]), ordinary valid fixtures (2-node and 3-node graphs), confirms that caller-owned state is never mutated across failures, and verifies that subsequent valid calls execute successfully immediately after an exception.

Related Issue

Closes #8
Related to: #8

Type of Change

  • Tests (adds focused failure-path, boundary, and state-preservation regression tests)
  • Documentation update (documents preconditions, failure paths, and state invariants in Javadoc)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Changes Made

  1. Javadoc Documentation (GomoryHuTree.java):

    • Added class and method-level Javadoc detailing preconditions, failure behavior, and caller-owned state immutability.
    • Documented explicit @throws IllegalArgumentException specifications for null, empty, ragged/non-square, and negative capacity matrices.
  2. Unit & Regression Tests (GomoryHuTreeTest.java):

    • testSmallestValidInputFixture: Tests 1x1 matrix ([[0]]), verifying precondition cap != null && cap.length == 1 established at GomoryHuTree.java:73-86 and branched at line 40, expecting parent = [-1], weight = [0].
    • testOrdinaryInputFixture: Tests ordinary 2x2 matrix ([[0, 7], [7, 0]]), expecting parent = [-1, 0], weight = [0, 7].
    • testDocumentedOrdinaryTriangleInputFixture: Tests ordinary 3x3 symmetric matrix, expecting parent = [-1, 0, 0], weight = [0, 5, 6].
    • testFailureNullCapacityMatrixThrowsIllegalArgumentException: Tests cap == null precondition checked at line 73, thrown at line 74 with message "Capacity matrix must not be null or empty".
    • testFailureEmptyCapacityMatrixThrowsIllegalArgumentException: Tests cap.length == 0 precondition checked at line 73, thrown at line 74 with message "Capacity matrix must not be null or empty".
    • testFailureNullRowThrowsIllegalArgumentException: Tests cap[i] == null precondition checked at line 78, thrown at line 79 with message "Capacity matrix must be square".
    • testFailureNonSquareCapacityMatrixThrowsIllegalArgumentException: Tests cap[i].length != n precondition checked at line 78, thrown at line 79 with message "Capacity matrix must be square".
    • testFailureNegativeCapacityThrowsExceptionAndPreservesCallerStateWithSubsequentSuccess: Tests cap[i][j] < 0 precondition checked at line 82, thrown at line 83 with message "Capacities must be non-negative". Asserts caller-owned array is unmutated, followed by a successful call returning parent = [-1, 0], weight = [0, 7].
    • testCallerOwnedOrdinaryStateUnmutatedAcrossExceptionsAndExecutions: Verifies that caller-owned arrays passed into operations are completely unmutated across failure calls and subsequent successful calls.
    • testPrivateConstructorContract: Reflection contract test verifying private constructor encapsulation.
  3. Automated Verification Harness (work/R45-T008/):

    • Implemented check.py runner logging environment metadata (Python 3.15, OpenJDK 21, Maven 3.10) and executing mvn test -Dtest=GomoryHuTreeTest and mvn checkstyle:check.
    • Generated results.json and evidence.md confirming 13/13 tests passing with 0 failures, 0 errors, and 0 checkstyle violations.

Screenshots / Recordings

  • Native test suite execution output:

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