Skip to content

Conversation

@github-actions
Copy link
Contributor

Summary

This PR adds comprehensive unit tests for advanced LinearAlgebra functions that previously had 0% or very low test coverage, significantly improving overall project coverage.

  • LinearAlgebra functions: 42 new tests covering LU decomposition, matrix solvers, inverse, determinant, pseudo-inverse, and leverage calculations
  • Tests cover matrix operations, edge cases, mathematical properties, and error conditions
  • All 174 tests pass (132 original + 42 new tests)

Problems Found

  1. Advanced LinearAlgebra functions had 0% or minimal test coverage:

    • solveTriangularLinearSystems (matrix version) - untested
    • luDecompose - untested
    • solveLinearSystem and solveLinearSystems (LU-based) - untested
    • inverse - untested
    • determinant - untested
    • pseudoInvers - untested
    • hatMatrix, leverage, leverageBy - untested
  2. Overall project coverage was low at 4.83% (99/2047 lines)

  3. Many advanced matrix operations had no test coverage despite being critical for numerical linear algebra

Actions Taken

  1. Created LinearAlgebraAdvancedTests.fs with 42 comprehensive tests covering:

    SolveTriangularLinearSystems (5 tests): Matrix version of triangular system solver

    • Multiple RHS columns
    • Lower and upper triangular systems
    • Identity matrix verification
    • Error handling (non-square, dimension mismatch)

    LU Decomposition (6 tests):

    • 2x2 and 3x3 matrix decomposition
    • Verification of PA = LU property
    • L diagonal verification (all ones)
    • U upper triangular verification
    • Identity matrix edge case
    • Error handling (non-square)

    Solve Linear Systems with LU (10 tests):

    • Vector version: 2x2 and 3x3 systems, identity matrix, error handling
    • Matrix version: Multiple RHS, reconstruction verification, error handling

    Matrix Inverse (5 tests):

    • 2x2 and 3x3 matrix inversion
    • A * A^-1 = I verification
    • Identity inverse
    • Involution property: (A^-1)^-1 = A
    • Error handling (non-square)

    Determinant (5 tests):

    • Identity determinant
    • 2x2 and 3x3 matrices
    • Singular matrix (det = 0)
    • Error handling (non-square)

    Pseudo-Inverse (4 tests):

    • Overdetermined systems (tall matrices)
    • Underdetermined systems (wide matrices)
    • Square invertible matrices
    • Identity matrix edge case

    Hat Matrix and Leverage (7 tests):

    • Idempotency: H*H = H
    • Symmetry: H = H^T
    • Dimension verification
    • Leverage calculation from hat matrix
    • Direct leverage computation
    • Consistency between methods
    • Non-negativity of leverages
  2. Updated FsMath.Tests.fsproj to include the new test file

  3. All 174 tests pass successfully

Test Coverage Results

Metric Before After Change
Overall Line Coverage 4.83% 6.49% +1.66%
Lines Covered 99/2047 133/2047 +34 lines
Branch Coverage 1.56% 2.09% +0.53%
Branches Covered 83/5307 111/5307 +28 branches
Total Tests 132 174 +42 tests

Coverage Improvement: +34.4% relative increase in line coverage

LinearAlgebra Module Specific Coverage

The new tests significantly improved coverage for:

  • luDecompose - now tested
  • solveLinearSystem / solveLinearSystems - now tested
  • inverse - now tested
  • determinant - now tested
  • pseudoInvers - now tested
  • hatMatrix, leverage, leverageBy - now tested
  • solveTriangularLinearSystems (matrix version) - now tested

Replicating the Test Coverage Measurements

To replicate these measurements:

# Clean previous coverage
rm -rf ./coverage ./coverage-new

# Build the project
dotnet build

# Run tests with coverage (baseline on main)
git checkout main
dotnet test tests/FsMath.Tests/FsMath.Tests.fsproj \
  --no-build \
  --collect:"XPlat Code Coverage" \
  --results-directory ./coverage \
  -- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=cobertura

# Extract baseline metrics
BASELINE_FILE=$(find ./coverage -name "coverage.cobertura.xml" | head -n 1)
grep -oP 'line-rate="\K[^"]*' "$BASELINE_FILE" | head -n 1  # Should show 0.0483
grep -oP 'lines-covered="\K[^"]*' "$BASELINE_FILE" | head -n 1  # Should show 99

# Run tests with coverage (on this branch)
git checkout test-coverage/linear-algebra-advanced-20251012
dotnet build
dotnet test tests/FsMath.Tests/FsMath.Tests.fsproj \
  --no-build \
  --collect:"XPlat Code Coverage" \
  --results-directory ./coverage-new \
  -- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=cobertura

# Extract new metrics
NEW_FILE=$(find ./coverage-new -name "coverage.cobertura.xml" | head -n 1)
grep -oP 'line-rate="\K[^"]*' "$NEW_FILE" | head -n 1  # Should show 0.0649
grep -oP 'lines-covered="\K[^"]*' "$NEW_FILE" | head -n 1  # Should show 133

# Verify test count increased
dotnet test tests/FsMath.Tests/FsMath.Tests.fsproj --no-build | grep "Passed"  # Should show 174 tests (+42)

Possible Other Areas for Future Improvement

Based on the coverage report and code analysis, the following areas have 0% or very low coverage and could benefit from additional tests:

High Priority (Foundation - 0% coverage, not inline):

  1. Algebra/SVD.fs (0% coverage) - Singular Value Decomposition
  2. Algebra/EVD.fs (0% coverage) - Eigenvalue Decomposition
  3. Algebra/MatrixExt.fs (0% coverage) - Matrix extension methods
  4. AlgTypesTopLevelOps.fs (0% coverage) - Top-level utility functions
  5. Vector.fs (partial coverage) - Core vector type operations beyond basics

Medium Priority (Inline but valuable to test):

  1. SpanPrimitives.fs (0% coverage, inline) - Low-level SIMD operations (PRs Daily Test Coverage Improver - Add tests for VectorOps operators #15, Daily Test Coverage Improver - Add tests for SpanMath operations #17 tested related modules)
  2. SIMDUtils.fs (0% coverage, partial inline) - SIMD detection and utilities

Also Possible:

  1. More functions in Algebra/LinearAlgebra.fs - There are still untested functions like symmetricEigenspectrum
  2. Matrix.fs - Additional matrix operations beyond what's currently tested

Recommendation: The next logical areas would be Algebra/SVD.fs and Algebra/EVD.fs as they provide advanced matrix factorizations that build upon the LU/QR decompositions now better covered.


Execution Details (bash commands, web searches, web pages fetched)

Bash Commands Run:

  • git checkout -b test-coverage/linear-algebra-advanced-20251012
  • find tests/FsMath.Tests -name "*LinearAlgebra*" (to check existing tests)
  • dotnet build tests/FsMath.Tests/FsMath.Tests.fsproj (multiple times during development)
  • dotnet test tests/FsMath.Tests/FsMath.Tests.fsproj --no-build (multiple times to verify tests pass)
  • dotnet test tests/FsMath.Tests/FsMath.Tests.fsproj --no-build --collect:"XPlat Code Coverage" --results-directory ./coverage-new
  • Coverage extraction and comparison commands
  • git add tests/FsMath.Tests/LinearAlgebraAdvancedTests.fs tests/FsMath.Tests/FsMath.Tests.fsproj
  • git commit -m "Add comprehensive tests for advanced LinearAlgebra functions"

Web Searches:

None performed

Web Pages Fetched:

None fetched


AI generated by Daily Test Coverage Improver

AI generated by Daily Test Coverage Improver

- Added 42 new tests for LU decomposition, matrix solver functions, inverse, determinant, pseudo-inverse, and leverage calculations
- Coverage improved from 4.83% to 6.49% (+1.66%)
- Lines covered increased from 99 to 133 (+34 lines)
- All 174 tests pass
@dsyme dsyme closed this Oct 12, 2025
@dsyme dsyme reopened this Oct 12, 2025
@dsyme dsyme marked this pull request as ready for review October 12, 2025 12:42
@dsyme dsyme merged commit 738dc70 into main Oct 12, 2025
2 checks passed
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.

1 participant