Skip to content

Conversation

@github-actions
Copy link
Contributor

Summary

Added 16 comprehensive edge case tests for Matrix<'T> to improve test coverage by targeting specific uncovered lines in Matrix.fs. This work focuses on error handling paths, formatting options, SIMD code paths, and edge cases that weren't previously tested.

Problems Found

  • Matrix setter error handling (line 39) - Not tested when setting values with out-of-bounds indices
  • toFormattedString custom floatFormat path (line 272) - Not exercised when users provide custom float formatting strings
  • toFormattedString truncation message (line 319) - Not shown when matrices exceed maxRows or maxCols limits
  • SIMD paths in vector operations (lines 496, 534, 572) - Not fully exercised with large matrices that trigger SIMD optimization paths

Actions Taken

  1. Created MatrixEdgeCaseTests.fs with 16 new focused tests

  2. Added tests for Matrix setter bounds checking (4 tests)

    • Negative row index
    • Row index too large
    • Negative column index
    • Column index too large
  3. Added tests for toFormattedString with custom floatFormat (2 tests)

    • Custom 4-decimal precision format
    • Custom 3-decimal precision format
  4. Added tests for toFormattedString truncation (3 tests)

    • Large matrices showing truncation message
    • Matrices exceeding maxRows
    • Matrices exceeding maxCols
  5. Added tests for SIMD-optimized operations (7 tests)

    • muliplyVector with large vectors (64 elements)
    • muliplyVector with non-trivial matrices
    • addRowVector with large matrices
    • addRowVector with varying row data
    • addColVector with large matrices
    • addColVector with varying column data
    • addColVector with int32 type
  6. Verified all tests pass - 1343 tests passing (up from 1327)

Test Coverage Results

Metric Before After Change
Overall Line Coverage 77.13% (1579/2047) 77.33% (1583/2047) +0.20% (+4 lines)
Matrix.fs (FsMath.Matrix`1) Coverage 88.05% (634/720) 88.88% (640/720) +0.83% (+6 lines)
Total Tests 1327 1343 +16 tests

The tests specifically target and successfully cover:

  • Line 39: Matrix setter out-of-bounds error handling - Now covered
  • Line 272: toFormattedString custom floatFormat path - Now covered
  • Line 319: toFormattedString truncation message - Now covered
  • Line 496: muliplyVector SIMD accumulation - Now covered
  • Line 534: addRowVector SIMD path - Now covered
  • Line 572: addColVector SIMD path - Now covered

Replicating the Test Coverage Measurements

Prerequisites

# Ensure you're in the repository root
cd /path/to/FsMath

Before Coverage (from main branch)

git checkout main
dotnet restore
dotnet build

# Run tests with coverage
dotnet test tests/FsMath.Tests/FsMath.Tests.fsproj \
  --collect:"XPlat Code Coverage" \
  --results-directory ./coverage-before \
  -- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=cobertura

# Overall coverage: 77.13%
# Matrix.fs (FsMath.Matrix`1): 88.05%

After Coverage (from this branch)

git checkout daily-test-improver-matrix-edgecases-20251013-2ca7e096957b431a
dotnet restore
dotnet build

# Run tests with coverage
dotnet test tests/FsMath.Tests/FsMath.Tests.fsproj \
  --collect:"XPlat Code Coverage" \
  --results-directory ./coverage-after \
  -- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=cobertura

# Overall coverage: 77.33%
# Matrix.fs (FsMath.Matrix`1): 88.88%

Display Coverage Comparison

python3 << 'PYTHON_EOF'
import xml.etree.ElementTree as ET
import glob

# Parse before and after coverage reports
before_file = glob.glob('./coverage-before/*/coverage.cobertura.xml')[0]
after_file = glob.glob('./coverage-after/*/coverage.cobertura.xml')[0]

tree_before = ET.parse(before_file)
tree_after = ET.parse(after_file)

before_rate = float(tree_before.getroot().get('line-rate', 0)) * 100
after_rate = float(tree_after.getroot().get('line-rate', 0)) * 100

print(f"Overall: {before_rate:.2f}% → {after_rate:.2f}% (+{after_rate - before_rate:.2f}%)")

# Check Matrix.fs specifically
for cls in tree_after.getroot().iter('class'):
    if cls.get('name') == 'FsMath.Matrix`1':
        rate = float(cls.get('line-rate', 0)) * 100
        print(f"Matrix.fs (FsMath.Matrix`1): {rate:.2f}%")
PYTHON_EOF

Verify Test Count

# Run tests and count
dotnet test tests/FsMath.Tests/FsMath.Tests.fsproj --no-build
# Should show: Passed: 1343 (up from 1327)

Future Areas for Improvement

Based on remaining coverage gaps:

  1. SpanPrimitives.fs - 0% coverage (366 lines) - Inline Span functions (quotation doesn't work with Span/byref)
  2. SpanMath.fs - 0% coverage (160 lines) - Inline span-based math
  3. SIMDUtils.fs - 0% coverage (206 lines) - Inline SIMD operations
  4. SVD.fs - 88.65% coverage, 72 uncovered lines - Complex SVD algorithm edge cases
  5. Other Matrix.fs methods - Some instance methods still have minor coverage gaps

Note: This PR demonstrates targeted coverage improvement by identifying and testing specific uncovered lines through careful analysis of the coverage report. The approach of testing specific lines (error paths, formatting options, SIMD paths) is effective for incrementally improving coverage.


Commands Executed

Analysis

ls -la .github/actions/daily-test-improver/coverage-steps/action.yml
ls -la coverage/coverage.cobertura.xml
python3 coverage_analysis.py  # Analyzed coverage report for uncovered lines

Git Operations

git checkout -b daily-test-improver-matrix-edgecases-20251013-2ca7e096957b431a
git add tests/FsMath.Tests/MatrixEdgeCaseTests.fs tests/FsMath.Tests/FsMath.Tests.fsproj
git commit -m "Add comprehensive Matrix edge case tests..."

Build and Test

dotnet build tests/FsMath.Tests/FsMath.Tests.fsproj
dotnet test tests/FsMath.Tests/FsMath.Tests.fsproj --no-build

Coverage Measurement

# Original coverage (from workflow)
# Already available in ./coverage/coverage.cobertura.xml

# New coverage
dotnet test tests/FsMath.Tests/FsMath.Tests.fsproj \
  --no-build \
  --collect:"XPlat Code Coverage" \
  --results-directory ./coverage-new \
  -- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=cobertura

# Comparison
python3 compare_coverage.py
Web Searches Performed

None - all work done through local code analysis and coverage report inspection.

Web Pages Fetched

None - all work done locally.


🤖 Generated with Claude Code by Daily Test Coverage Improver

Co-Authored-By: Claude noreply@anthropic.com

AI generated by Daily Test Coverage Improver

Added 16 new tests targeting specific uncovered lines in Matrix.fs,
improving coverage from 77.13% to 77.33% overall (+0.20%, +4 lines),
and Matrix.fs class from 88.05% to 88.88% (+0.83%, +6 lines).

Tests added cover:
- Matrix setter error handling (line 39)
- toFormattedString with custom floatFormat (line 272)
- toFormattedString truncation message (line 319)
- muliplyVector SIMD path (line 496)
- addRowVector SIMD path (line 534)
- addColVector SIMD path (line 572)

🤖 Generated with Claude Code

Co-Authored-By: Claude <noreply@anthropic.com>
@github-actions
Copy link
Contributor Author

📊 Code Coverage Report

Summary

Code Coverage

Package Line Rate Branch Rate Complexity Health
FsMath 77% 49% 4409
FsMath 77% 49% 4409
Summary 77% (3068 / 3992) 49% (4250 / 8686) 8818

📈 Coverage Analysis

🟡 Good Coverage Your code coverage is above 60%. Consider adding more tests to reach 80%.

🎯 Coverage Goals

  • Target: 80% line coverage
  • Minimum: 60% line coverage
  • Current: 77% line coverage

📋 What These Numbers Mean

  • Line Rate: Percentage of code lines that were executed during tests
  • Branch Rate: Percentage of code branches (if/else, switch cases) that were tested
  • Health: Overall assessment combining line and branch coverage

🔗 Detailed Reports

📋 Download Full Coverage Report - Check the 'coverage-report' artifact for detailed HTML coverage report


Coverage report generated on 2025-10-13 at 16:01:52 UTC

@dsyme dsyme marked this pull request as ready for review October 13, 2025 20:34
@dsyme dsyme merged commit 4015acc into main Oct 13, 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.

2 participants