Skip to content

Conversation

@github-actions
Copy link
Contributor

Summary

This PR adds comprehensive unit tests for the MatrixModule, which provides utility functions for matrix manipulation and transformation. The module previously had 0% test coverage.

  • MatrixModule: 38 new tests covering all core utility functions
  • Tests cover creation, transformation, iteration, and aggregation operations
  • Tests include edge cases, type conversions, and validation of mathematical properties
  • All 170 tests pass (132 original + 38 new tests)

Problems Found

  1. MatrixModule had 0% test coverage - all matrix utility functions were untested
  2. Overall project coverage was low at 4.83% (99/2047 lines)
  3. MatrixModule is a core utility module that many other parts of the codebase depend on

Actions Taken

  1. Created MatrixModuleTests.fs with 38 comprehensive tests covering:

    • copy (3 tests): Deep copying matrices, dimension preservation, single element matrices
    • splitRows (4 tests): Splitting matrices by row indices, handling unsorted indices, edge cases
    • splitCols (2 tests): Splitting matrices by column indices
    • permuteRowsBy (3 tests): Reordering rows using permutations, identity permutation, single row
    • ofRows (2 tests): Creating matrices from row arrays
    • ofRowSeq (3 tests): Creating matrices from sequences, validation of empty/mismatched rows
    • mapiRows (2 tests): Applying indexed functions to rows, type conversion
    • ofCols (2 tests): Creating matrices from column arrays
    • mapiCols (2 tests): Applying indexed functions to columns, type conversion
    • mapi (3 tests): Applying indexed functions to all elements, type conversion, row-major order
    • map (3 tests): Applying functions to all elements, type conversion, dimension preservation
    • foldi (4 tests): Indexed folding over matrices, row-major order, aggregations
    • sum (4 tests): Computing sums with various numeric types, edge cases
  2. Updated FsMath.Tests.fsproj to include the new test file

  3. All 170 tests pass successfully

Test Coverage Results

Metric Before After Change
Overall Line Coverage 4.83% 8.74% +3.91%
Lines Covered 99/2047 179/2047 +80 lines
Branch Coverage 1.56% 3.22% +1.66%
Branches Covered 83/5307 171/5307 +88 branches
Total Tests 132 170 +38 tests

MatrixModule Specific Coverage

  • MatrixModule.fs: Significant improvement from 0% coverage
  • All core utility functions now have test coverage
  • Edge cases and error conditions validated

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/matrix-module-20251011
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.0874
grep -oP 'lines-covered="\K[^"]*' "$NEW_FILE" | head -n 1  # Should show 179

# Verify test count
dotnet test tests/FsMath.Tests/FsMath.Tests.fsproj --no-build | grep "Passed"  # Should show 170 tests

Possible Other Areas for Future Improvement

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

High Priority (Foundation - 0% coverage):

  1. SpanPrimitives.fs - Low-level SIMD operations on spans (already has PR Daily Test Coverage Improver - Add tests for SpanMath operations #17 for SpanMath)
  2. SIMDUtils.fs - SIMD detection and utilities
  3. Vector.fs - Core vector type operations
  4. Matrix.fs - Core matrix type operations (complementary to MatrixModule)

Medium Priority (Advanced algorithms - 0% or partial coverage):

  1. Algebra/LinearAlgebra.fs (partial coverage) - QR, LU decomposition, solving systems
  2. Algebra/Householder.fs (0% coverage) - Householder transformations for QR decomposition
  3. Algebra/SVD.fs (0% coverage) - Singular Value Decomposition
  4. Algebra/EVD.fs (0% coverage) - Eigenvalue Decomposition
  5. SpecialFunctions/Gamma.fs (partial coverage) - Gamma function and related special functions

Recommendation: The next logical areas would be:

  • Matrix.fs - The core Matrix type to complement the MatrixModule utilities
  • Algebra/Householder.fs - Foundational for linear algebra operations

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

Bash Commands Run:

  • git checkout -b test-coverage/matrix-module-20251011
  • dotnet build tests/FsMath.Tests/FsMath.Tests.fsproj (multiple times while fixing compilation errors)
  • dotnet test tests/FsMath.Tests/FsMath.Tests.fsproj --no-build (multiple times to verify tests pass)
  • rm -rf ./coverage-new && dotnet test tests/FsMath.Tests/FsMath.Tests.fsproj --no-build --collect:"XPlat Code Coverage" --results-directory ./coverage-new
  • head -5 ./coverage/coverage.cobertura.xml (to check baseline coverage)
  • find ./coverage-new -name "coverage.cobertura.xml" -exec head -5 {} \; (to check new coverage)
  • git add tests/FsMath.Tests/MatrixModuleTests.fs tests/FsMath.Tests/FsMath.Tests.fsproj
  • git commit -m "Add comprehensive tests for MatrixModule"

Web Searches:

None performed

Web Pages Fetched:

None fetched


AI generated by Daily Test Coverage Improver

AI generated by Daily Test Coverage Improver

- Added 38 new tests covering all MatrixModule functions
- Tests include copy, splitRows, splitCols, permuteRowsBy, ofRows, ofRowSeq,
  mapiRows, ofCols, mapiCols, mapi, map, foldi, and sum
- All 170 tests pass successfully
- Coverage improved from 4.83% to 8.74% (+3.91pp, +80 lines)
@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 caff935 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